Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/379.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将java类映射到Postgresql表错误_Java_Spring_Postgresql_Hibernate_Spring Boot - Fatal编程技术网

将java类映射到Postgresql表错误

将java类映射到Postgresql表错误,java,spring,postgresql,hibernate,spring-boot,Java,Spring,Postgresql,Hibernate,Spring Boot,我尝试使用JPA在java中创建一个学生实体,但有些东西不起作用 我在postgresql中有一个名为“Studenti”的表和一个班级学生 我的学生班是: import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.Table; import java.io.Serializable; @Entity(name

我尝试使用JPA在java中创建一个学生实体,但有些东西不起作用

我在postgresql中有一个名为“Studenti”的表和一个班级学生

我的学生班是:


import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import java.io.Serializable;

@Entity(name = "Student")
@Table(name = "Studenti")
public class Student implements Serializable {
    @Id
    @Column(name = "Id")
    private long Id;

    @Column(name = "Nume")
    private String firstName;

    @Column(name = "Prenume")
    private String lastName;

    @Column(name = "An")
    private int year;

    @Column(name = "Id_cont")
    private long accountId;
}
该表具有以下结构:

Application.properties:

server.port=9091

spring.application.name=user-management

spring.datasource.url=jdbc:postgresql://localhost:5432/Licenta
spring.datasource.username=postgres
spring.datasource.password=*****

spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults=false
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQL9Dialect
spring.jpa.hibernate.ddl-auto=update
spring.h2.console.enabled=true

需要为此文件或其他文件配置特殊文件吗?

不,您只能在application.properties文件中配置PostgreSQL连接

可能没有更多的配置参数,尤其是这个

spring.datasource.driver.class=org.postgresql.Driver
如果已经有了DB结构,最好设置
ddl auto=none

PostgreSQL有Oracle引擎(或类似于Oracle引擎),所以对于@Id字段,最好使用序列

@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "genname")
@SequenceGenerator(name = "genname", sequenceName = "seqname", allocationSize = 1)

和@Id字段不能是原语,只能是长、整数、字符串、UUID或其他可能的实现。

a
UUID
不是
Long
。我怀疑这就是问题所在。请将遇到的堆栈跟踪包括在内好吗?请为id列指定@GeneratedValue。