-->
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.  [ 5 posts ] 
Author Message
 Post subject: Error in sequence incrementation (hilo generator)
PostPosted: Tue Nov 25, 2003 1:55 pm 
Newbie

Joined: Mon Sep 01, 2003 1:22 pm
Posts: 16
Location: France
Hi,

I'm basically inserting a value into a table, the id is properly generated using the hilo generator (but first value is 3 instead of 1 which is already strange) but the sequence table is not properly incremented. And the context itself is weird.

I have two test cases, when I run them separately, everything's alright, my insert works with a id value of 1 and sequence table index is 1. When I run them together, test 2 fails, the sequence table is still at 0 and my insert has been done with a id value of 3. Between both test cases I reset the database completely.

I analyzed a bit the logs and queries generated and the only differences between the two cases is that when I run both test cases, hibernate initiates its mapping only once when test 1 starts and not before test 2 starts (which makes sense). When I run only test 2 hibernate initiates juste before the test runs. I don't know if this has anything to do with my problem. Generated queries are exactly the same (except the id value of course). I couldn't see when the sequence table is incremented in the SQL logs.

I used both Hibernate 2.0.1 and Hibernate 2.0.3 (what is funny is that the first generated sequence value was 2 instead of 1 when using Hibernate 2.0.1 and 3 when using Hibernate 2.0.3) .

Any help, hint, or suggestion of additional test that could help me would be greatly appreciated.

Matt.

P.S. The id declaration in the mapping file is :

<id name="id" column="ID" type="long">
<generator class="hilo">
<param name="table">CONTEXT_ID</param>
<param name="column">NEXT</param>
</generator>
</id>


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 26, 2003 9:36 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Do you understand hilo concept. The high value is saved in DB, the low value is incremented in memory for the range of high value.

So id value will not be updated in DB for each new object but only when low value > max_lo.


From the doc: Unfortunately, you can't use hilo when supplying your own Connection to Hibernate, or when Hibernate is using an application server datasource to obtain connections enlisted with JTA. Hibernate must be able to fetch the "hi" value in a new transaction.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 26, 2003 9:57 am 
Newbie

Joined: Mon Sep 01, 2003 1:22 pm
Posts: 16
Location: France
I didn't know the hilo algorithm, that explains why the sequence table is not incremented. But I think I found what the problem is then.

When I run the first test case, hibernate initiates and I initialize the DB using :

SchemaExport schemaExport = new SchemaExport(new Configuration().configure());
schemaExport.create(true, true);

When I run the second test case, I initialize the database again but the hilo value in memory doesn't seem to be re-initiated. It seems to mess up hibenate a bit because when I create a new object, it gives me an id of 1 (before commit, in my java code) but actually when it's commited, its id in DB is 3. Does that seem possible ?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 26, 2003 6:35 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
mriou wrote:
Does that seem possible ?

No
Do you share the session object between your testcases ? Show a simple testsuite

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 26, 2003 9:40 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Hang on, are you telling us that you re-export the schema without building a new SessionFactory? Of course that would screw up the hilo algorithm. If you don't understand how the hilo algorithm works, please read scott amblers famous whitepaper.


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