错误:ORA-02289:休眠时序列不存在

时间:2017-07-26 20:15:21

标签: java sql oracle hibernate

我正在开发一个非常基本的hibernate应用程序并且遇到错误:

ERROR: ORA-02289: sequence does not exist.

附件是相关文件。我看到这个问题已经在堆栈溢出中被问到,但没有一个可以解决问题。我已经在Oracle DB中创建了序列school_seq

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="hibEx">
<class name="School" table="school">
<id name="id" column="ID" type="int">
<generator class="sequence">
        <param name="sequence">SCHOOL_SEQ</param>
    </generator>
 </id>
<property name="name" column="NAME"></property>
<property name="subject" column="SUBJECT"></property>
<property name="marks" column="MARKS"></property>
</class>
</hibernate-mapping>

POJO CLASS

package hibEx;

public class School {

    private String name;
    private String subject;
    private int marks;
    private int id;

    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getSubject() {
        return subject;
    }
    public void setSubject(String subject) {
        this.subject = subject;
    }
    public int getMarks() {
        return marks;
    }
    public void setMarks(int marks) {
        this.marks = marks;
    }
    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }
}

首先我创建了如下所示的序列:

CREATE SEQUENCE school_seq
 START WITH     411
 INCREMENT BY   1;

当我面对这个问题时,我已根据小组中的评论尝试了多种做法 后来改变了表格,如下所示:

alter sequence school_seq
MINVALUE 411
MAXVALUE 1000
NOCYCLE
CACHE 20
NOORDER

2 个答案:

答案 0 :(得分:1)

感谢您对此问题的支持。在进一步研究中,我在链接click here中找到了李莹的评论。 它说在Hibernate 5中,序列的参数名称已从<param name="sequence_name">xxxxxx_seq</param>更改为<param name="sequence">xxxxxx_seq</param>

答案 1 :(得分:0)

确保您的序列是在与表相同的架构中创建的。与SCHOOL表的所有者连接并查询这些数据字典视图,以确保同一用户拥有该表和序列。

SELECT
    s.sequence_name,
    s.sequence_owner
FROM
    all_sequences s
WHERE
    s.sequence_name = 'SCHOOL_SEQ';

SELECT
    t.table_name,
    t.owner
FROM
    all_tables t
WHERE
    t.table_name = 'SCHOOL';