Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.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 org.postgresql.util.PSQLException:错误:关系;“序列生成”;不存在_Java_Postgresql_Hibernate_Collections - Fatal编程技术网

Java org.postgresql.util.PSQLException:错误:关系;“序列生成”;不存在

Java org.postgresql.util.PSQLException:错误:关系;“序列生成”;不存在,java,postgresql,hibernate,collections,Java,Postgresql,Hibernate,Collections,我不熟悉Hibernate,现在我正试图使用@CollectionId使用'sequence gen'Hibernate sequence generator为我的类Hobbydeals生成一个标识符。下面是我的StudentDetails课程,其中包含hobbydeails的集合 @Entity public class StudentDetails { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) p

我不熟悉Hibernate,现在我正试图使用
@CollectionId
使用'sequence gen'Hibernate sequence generator为我的类Hobbydeals生成一个标识符。下面是我的
StudentDetails
课程,其中包含
hobbydeails
的集合

@Entity
public class StudentDetails {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private int studentId;

    private String studentName;

    @ElementCollection
    @JoinTable(name = "STUDENT_HOBBIES", // customised table name
             joinColumns = @JoinColumn(name = "STUDENT_ID"))
    @GenericGenerator(name = "sequence-gen", strategy = "sequence")
    @CollectionId(columns = { @Column(name="HOBBY_ID") }, generator = "sequence-gen", type = @Type(type="long"))
    private Collection<HobbyDetails> hobbies = new ArrayList<HobbyDetails>();

    public int getStudentId() {
        return studentId;
    }

    public void setStudentId(int studentId) {
        this.studentId = studentId;
    }

    public String getStudentName() {
        return studentName;
    }

    public void setStudentName(String studentName) {
        this.studentName = studentName;
    }

    public Collection<HobbyDetails> getHobbies() {
        return hobbies;
    }

    public void setHobbies(Collection<HobbyDetails> hobbies) {
        this.hobbies = hobbies;
    }

}

我使用的是hibernate版本5.3.1。有人能帮忙吗?

这是因为PostgreSQL数据库中不存在名为“sequence gen”的序列生成器。您需要通过运行以下命令显式创建序列

创建序列发生器

连字符(-)符号将在PostgreSQL数据库中生成语法错误。因此,您需要重命名GenericGenerator

@GenericGenerator(name = "sequence_gen", strategy = "sequence")

@CollectionId(columns = { @Column(name="HOBBY_ID") }, generator = "sequence_gen", type = @Type(type="long"))

private Collection<HobbyDetails> hobbies = new ArrayList<HobbyDetails>();
@GenericGenerator(name=“sequence\u gen”,strategy=“sequence”)
@CollectionId(columns={@Column(name=“HOBBY\u ID”)},generator=“sequence\u gen”,type=@type(type=“long”))
私人收藏爱好=新建ArrayList();
另外,您需要在PostgreSQL数据库中运行以下命令以生成生成器

创建序列


您正在使用hibernate生成数据库表吗?还是您手动创建的?如果是手动的,还需要创建序列:@paranoidAndroid我使用hibernate生成表。我参考了解决错误的链接“Hilo生成器策略不工作”Ok,很高兴知道
@GenericGenerator(name = "sequence_gen", strategy = "sequence")

@CollectionId(columns = { @Column(name="HOBBY_ID") }, generator = "sequence_gen", type = @Type(type="long"))

private Collection<HobbyDetails> hobbies = new ArrayList<HobbyDetails>();