-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: User Oracle Sequence <generator class="sequence"
PostPosted: Mon Jan 12, 2004 3:37 pm 
Newbie

Joined: Mon Dec 01, 2003 7:32 pm
Posts: 7
I tried to refactor an existing application and start using hibernate. The current application use oracle sequence to generate the pk for a few tables. The way it does is to use the insert trigger to generate the id.

When I use the
<id name="id">
<generator class="sequence"/>
<param>sq_lms_incident</param>
</id>

do I need to remove the trigger from the database? Or do we have a way to work around so that we still can continue using the existing trigger?

How does it work? Is it that hibernate first issue a sql to get an id from oracle sequence, populate the class id property and then issue another sql to insert all persistent the properties to the table including the id field?

Qin


Top
 Profile  
 
 Post subject: Re: User Oracle Sequence <generator class="sequence&
PostPosted: Mon Jan 12, 2004 3:51 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Qin Ding wrote:
How does it work? Is it that hibernate first issue a sql to get an id from oracle sequence, populate the class id property and then issue another sql to insert all persistent the properties to the table including the id field?


Yes, that is the way it works. If you have an autogenerated id, you could probably work around it by using the "identity" generator, and create a subclass of the dialect you use. Then override getIdentitySelectString() to return the SQL query needed to retrieve the last generated id.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 12, 2004 5:29 pm 
Newbie

Joined: Mon Dec 01, 2003 7:32 pm
Posts: 7
Gloeglm:

I don't follow what you said:

"create a subclass of the dialect you use. Then override getIdentitySelectString() to return the SQL query needed to retrieve the last generated id." Would you please explain? Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 12, 2004 5:42 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Hm, well, create a class extending the dialect class you use for hibernate, override getIdentitySelectString() to return an SQL query needed to select your last generated id. Then use this class as dialect.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.