File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes Oracle Sequence Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Oracle Sequence" Watch "Oracle Sequence" New topic
Author

Oracle Sequence

Bob Ciazoratione
Greenhorn

Joined: Mar 30, 2005
Posts: 8
Hello,
Is there a way to tell Hibernate which sequence to use?

My POJO class has following ID:
<id
name="formulierId"
type="java.lang.Long"
column="FORMULIER_ID"
>
<generator class="native" />
</id>

And Hibernate generates the following SQL log when preparing this insert:
"Hibernate: select hibernate_sequence.nextval from dual"

The problem is that I want to use a specific sequence for this table and not the 'hibernate_sequence'. Is there a way to do this?

Thanx in advance,

Stijn
Bob Ciazoratione
Greenhorn

Joined: Mar 30, 2005
Posts: 8
Sorry guys,
Solved it by using:
<id
name="formulierId"
type="java.lang.Long"
column="FORMULIER_ID"
>
<generator class="sequence">
<param name="sequence">SEQ_SJUSTIF_FORMULIER_ID</param>
</generator>
</id>

Thanx anyway...
David Harkness
Ranch Hand

Joined: Aug 07, 2003
Posts: 1646
From [url=]section 5.1.4.4[/url] of the Hibernate documentation, use the sequence generator type and provide a sequence name parameter.[ Beat me to it. ]
[ March 30, 2005: Message edited by: David Harkness ]
Bob Ciazoratione
Greenhorn

Joined: Mar 30, 2005
Posts: 8
When I try to perform the session.save(obj) operation, the Hibernate log only shows: 'Hibernate: select SEQ_SJUSTIF_FORMULIER_ID.nextval from dual' but no insert statement. (and of cources, no insert is executed...).
Any idea why this occurs?

Thanx,
S.
David Harkness
Ranch Hand

Joined: Aug 07, 2003
Posts: 1646
First, it's better to start a new topic for a new question. While this is related in that you use an ID generator when creating new objects, this problem would occur regardless of the generator type.

Saving and updating objects only registers them with the Session's unit of work. You must flush() the Session to make it execute the SQL statements to persist the changes in the database. Then you must commit() the Transaction you began at the start.

If you didn't explicitely begin() a transaction, Hibernate should have begun one for you. I use a framework called Spring that does all the transaction work in my application based on method tags, so I don't know if Hibernate will do this automatically, but I do know that you must tell Hibernate to either commit() or rollback() a Transaction to make your flush()ed changes permanent or undo them.

Once you've done all that, you can close() the Session or continue using a single one (preferably the former).
Benson Fung
Ranch Hand

Joined: Apr 10, 2003
Posts: 207
Hi David,

DO I need to create the sequence person_id_sequence generator in oracle?


Thanks
Benson
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Oracle Sequence