• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

ERROR: ORA-02289: sequence does not exist

 
Ranch Hand
Posts: 251
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:
 
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 251
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 251
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
here is my model class

 
Dave Tolls
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 251
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's good..

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