• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ERROR: ORA-02289: sequence does not exist

 
Thakur Sachin Singh
Ranch Hand
Posts: 248
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am creating a basic hibernate application for employee table in which I am adding, updating, deleting and displaying the record with the help of ManageEmployee class.

Actually, ManageEmployee is my test class and i am using Employee.java and Employee.hbm.xml file to do above things.

Details: Database: Oracle 11 g Hibernate version: hibernate-release-4.3.8.Final Java Version: Java 1.8

Employee Table Details:

USER_ID NUMBER(15,0) No 1 1
FIRST_NAME VARCHAR2(20 BYTE) Yes 2
LAST_NAME VARCHAR2(20 BYTE) Yes 3
SALARY NUMBER(10,0) Yes 4

Error Log: you can see in the log that error is coming 3 times because I am adding Employee object 3 times in ManageEmployee.java class with addEmployee(...) method so I am assuming that problem is with the sequence generator for the column id.

Here I am using naive generator. i.g. Integer empID1 = ME.addEmployee("Zara", "Ali", 1000);



ManageEmployee.java file Code:


Mapping File:
 
Dave Tolls
Ranch Hand
Posts: 2112
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you asked Hibernate to create your db for you, or have you done it by hand?
If the latter then you will (IIRC) need to create the SEQUENCE that Hibernate is to use for your IDs, which will also mean changing your XML to tell Hibernate what SEQUENCE to use.
 
Thakur Sachin Singh
Ranch Hand
Posts: 248
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi,

I have created database and table myself.

If the latter then you will (IIRC) need to create the SEQUENCE that Hibernate is to use for your IDs, which will also mean changing your XML to tell Hibernate what SEQUENCE to use.

How we can implement this?
 
Thakur Sachin Singh
Ranch Hand
Posts: 248
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
here is my model class

 
Dave Tolls
Ranch Hand
Posts: 2112
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thakur Sachin Singh wrote:
Hi,

I have created database and table myself.

If the latter then you will (IIRC) need to create the SEQUENCE that Hibernate is to use for your IDs, which will also mean changing your XML to tell Hibernate what SEQUENCE to use.

How we can implement this?


You'll need to read up on Oracle sequences and how they function, as well as telling Hibernate that you are using a SEQUENCE (section 5.1.2.2.4) rather than a native generator.

(fixed links)
 
Thakur Sachin Singh
Ranch Hand
Posts: 248
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

@Dave: Thanks for the information, now i have fixed my problem.

I have created a sequence in oracle database by the below query and updated my hbm.xml file



 
Dave Tolls
Ranch Hand
Posts: 2112
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's good..

Thanks for coming back and posting your fix.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic