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.  [ 8 posts ] 
Author Message
 Post subject: How to user TableHiLoGenerator in seperate transaction?
PostPosted: Fri May 14, 2004 12:14 pm 
Beginner
Beginner

Joined: Wed May 12, 2004 2:52 pm
Posts: 36
All,

The TableHiLoGenerator says the following:

Quote:
An IdentifierGenerator that returns a Long, constructed using a hi/lo algorithm. The hi value MUST be fetched in a seperate transaction to the Session transaction so the generator must be able to obtain a new connection and commit it. Hence this implementation may not be used when Hibernate is fetching connections from an application server datasource or when the user is supplying connections. In these cases a SequenceHiLoGenerator would be a better choice (where supported).


Does this mean that I:
1. Open a session
2. Open a transaction, generate and Id, commit the transaction
3. Open another transaction, populate my object with the id, save, the object and close the transaction.
4. Close the session

How do I get a reference to the Generator for this specific object?

Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 14, 2004 12:22 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
You do not at all obtain a reference to the generator, you just save your object and hibernate assigns the id.


Top
 Profile  
 
 Post subject: Not two steps?
PostPosted: Fri May 14, 2004 12:34 pm 
Beginner
Beginner

Joined: Wed May 12, 2004 2:52 pm
Posts: 36
Michael,

Reading the javadoc further, I realize that my application will be obtaining connections from an application server datasource. Because I am using MSSQL Server, a SequenceHiLoGenerator is not supported.

Is there any other ways to pull this off?

Joshua


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 14, 2004 12:40 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
use generator="native"


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 14, 2004 1:02 pm 
Beginner
Beginner

Joined: Wed May 12, 2004 2:52 pm
Posts: 36
Is there another way?


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 14, 2004 1:32 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
You can use all kinds of generators except sequence and seqhilo.


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 14, 2004 1:50 pm 
Beginner
Beginner

Joined: Wed May 12, 2004 2:52 pm
Posts: 36
Michael,

Thanks for your patience. I know how frustrating it is dealing with new users.

Because I am not writing this application from scratch, I need to use the TableHiLoGenerator to generate primary keys (This is how the app works now.)


Given:
Quote:
An IdentifierGenerator that returns a Long, constructed using a hi/lo algorithm. The hi value MUST be fetched in a seperate transaction to the Session transaction so the generator must be able to obtain a new connection and commit it. Hence this implementation may not be used when Hibernate is fetching connections from an application server datasource or when the user is supplying connections. In these cases a SequenceHiLoGenerator would be a better choice (where supported).


How do I ensure that the hi value is fetched in a seperate transaction to the Session transaction using the TableHiLoGenerator? (Note: I do not have access to EJB's)

Joshua


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 14, 2004 2:12 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
TableHiLoGenerator already does that - i'd suggest you just take a look at the code if you are interested in the details.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 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.