2

I am developing a very basic hibernate application and am stuck with the error:

ERROR: ORA-02289: sequence does not exist.

Attached are the related files. I see this question already been asked in stack overflow but none of them could solve the issue. I have created the sequence school_seq already in Oracle DB.

<?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;
    }
}

First i have created sequence like the below:

CREATE SEQUENCE school_seq
 START WITH     411
 INCREMENT BY   1;

As i am facing this issue,i have tried multiple practices based on the comments in the group and later altered the table like the below:

alter sequence school_seq
MINVALUE 411
MAXVALUE 1000
NOCYCLE
CACHE 20
NOORDER
Pavan Ghantasala
  • 209
  • 1
  • 4
  • 13
  • 2
    Show the _exact_ `CREATE SEQUENCE` statement you ran. – mustaccio Jul 26 '17 at 20:19
  • First i have created sequence like the below: CREATE SEQUENCE school_seq START WITH 411 INCREMENT BY 1; As i am facing this issue,i have tried multiple practices based on the comments in the group and later altered the table like the below: alter sequence school_seq MINVALUE 411 MAXVALUE 1000 NOCYCLE CACHE 20 NOORDER – Pavan Ghantasala Jul 27 '17 at 02:46

2 Answers2

4

thanks for your support in clearing this problem..On further research i found a comment from Li Ying in the link click here . It says In Hibernate 5, the param name for the sequence has been changed to <param name="sequence_name">xxxxxx_seq</param> from <param name="sequence">xxxxxx_seq</param>

Pavan Ghantasala
  • 209
  • 1
  • 4
  • 13
0

Make sure your sequence was created in the same schema as the table. Connect with the owner of the SCHOOL table and query these data dictionary views to make sure that the same user owns the table and the sequence.

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

and

SELECT
    t.table_name,
    t.owner
FROM
    all_tables t
WHERE
    t.table_name = 'SCHOOL';
Julius Zaldokas
  • 234
  • 2
  • 7