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.  [ 7 posts ] 
Author Message
 Post subject: <generator class="increment" />
PostPosted: Sun Jun 05, 2005 6:31 am 
Newbie

Joined: Wed Nov 12, 2003 3:49 pm
Posts: 19
I have set up the generator class for two classes. One works great, the other generates wild, seemingly random, numbers. I am using an ORacle database.

I put a println statement in my setUserId method, and it is in fact "1" the javaclass rst time through. However, the database always ends up conatining some wacky value. THe second tme through generally throws an exception, probably because it can't handle the wacky database value.

Again - I have another case that works perfectly, and I can't see any differences between the way that case is set up and the way that the problem case is set up.

Does anybody have any ideas?

Here are a few snips of relevant code:

from the hbm file:

<id name="userId" column="USER_ID" type="long">
<generator class="increment" />
</id>

the oracle table:

SQL> desc bidder
Name Null? Type
----------------------------------------- -------- ------------
USER_ID NOT NULL NUMBER(19)

From the java bean:

private long userId;


public long getUserId() { return userId;}

private void setUserId(long userId) {
System.out.println("*userID=" + userId);
this.userId = userId;
}


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 05, 2005 9:49 am 
Expert
Expert

Joined: Thu May 26, 2005 9:19 am
Posts: 262
Location: Oak Creek, WI
Why do u use long here?

_________________
RamnathN
Senior Software Engineer
http://www.linkedin.com/in/ramnathn
Don't forget to rate.


Top
 Profile  
 
 Post subject: More detail on the generator problem
PostPosted: Sun Jun 05, 2005 10:11 am 
Newbie

Joined: Wed Nov 12, 2003 3:49 pm
Posts: 19
Folks - One more piece of info on this... I added more println() statements to my code to see what is happening with the id value in the bean:


Transaction tx = session.beginTransaction();
System.out.println(" Before: " + user.getId());
session.save(user);
System.out.println(" After: " + user.getId());
tx.commit();
System.out.println(" After tx.commit(): " + user.getId());

ON the first insert to the table, I get exactly what i would expect:

Before: 0
userID=1 (this is a println that is inside the setID method)
After: 1
After tx.commit(): 1

So, everything looks like it's in order. But, when I select from the database, I get a surprise:

SQL> select id from bidder;

ID
----------
-a.000E+46

Could this be some kind of bug in the JDBC? Is thist even a valid value inside an Oracle number(19) column?


Top
 Profile  
 
 Post subject: using long v. int
PostPosted: Sun Jun 05, 2005 10:44 am 
Newbie

Joined: Wed Nov 12, 2003 3:49 pm
Posts: 19
ramnath wrote:
Why do u use long here?


Ramnath - I have tried both long and int on this example, and both formats fail.

Both should work...

I also have another example that uses long i got working.


Top
 Profile  
 
 Post subject: found a "solution"
PostPosted: Sun Jun 05, 2005 11:59 am 
Newbie

Joined: Wed Nov 12, 2003 3:49 pm
Posts: 19
OK, here is the fix that I found...

I originally used HBM2DDL to generate the table. It created the ID column as number(19). I modified the table and redefined the ID column as number (without any qualifictons.). Now, it works.

But, what is still troubling, is that my other example that is still defined as number(19) also works! So, I have this feeling that I took care of the symptom but have no idea as to what is the actual cause of the problem.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 05, 2005 6:41 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Personally, I would be using a sequence generator for Oracle.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 05, 2005 7:11 pm 
Newbie

Joined: Wed Nov 12, 2003 3:49 pm
Posts: 19
david wrote:
Personally, I would be using a sequence generator for Oracle.


David - Yes, I plan to use sequences eventually. I'm just going through the Hibernate in Action book now and learning the api.

Thanks for the input.


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