-->
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.  [ 14 posts ] 
Author Message
 Post subject: Assigned identifiers
PostPosted: Wed Mar 24, 2004 7:02 pm 
Newbie

Joined: Wed Mar 24, 2004 6:43 pm
Posts: 11
Location: Winnipeg, Manitoba, Canada
Hi. I'm inserting a record into a table. I've defined the primary key as "assigned" in the XML file - since I want my application to provide it. However, it keeps inserting a random number in my PK field - all other column values are inserted OK.

Here's a quick sample of my code:

(in Data Access Object class...)

logger.warn("About to insert transaction record -> Id: " + myBean.getId() + ".");

session.save(myBean);

/**************************/

(in XML file definition...)

<hibernate-mapping>
<class name="myBean" table="myTable">
<id column="myTablePKfield" name="id" type="long">
<generator class="assigned"/>
</id>
... (other columns here)
</class>
</hibernate-mapping>

/**************************/

As you can see, just before I call the save() method, I output the number in the ID field of my bean. It contains the correct number at that point. But when I go to insert, it's inserting a random value. What am I doing wrong here? I just can't get it to work!

PS: I'm using Oracle 8.1.7.0.0 and the PK data column is NUMBER(15).

_________________
- Dylan Milks


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 25, 2004 6:30 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Enable log to see what Hibernate set in the SQL parameters. But I'm certain it does well.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 25, 2004 6:35 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
emmanuel,
ouf, enfin voila l'hibernate team, je pensais que vous aviez laiss


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 25, 2004 6:49 pm 
Newbie

Joined: Wed Mar 24, 2004 6:43 pm
Posts: 11
Location: Winnipeg, Manitoba, Canada
Thanks for the tip. However after doing this, the bound variables don't show up in the queries. Example of what is being output to the console:

Hibernate: insert into INTERNET_TRANSACTION (STORE_ID, TRANSACTION_TIMESTAMP, INTERNET_TRANSACTION_ID) values (?, ?, ?)

As you can see, no values are appearing. Is there a way to fill the substitution variables with the values that are being inserted?

_________________
- Dylan Milks


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 25, 2004 7:12 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
delpouve wrote:
je pensais que vous aviez laiss

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 26, 2004 3:20 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
Emmanuel,

Quote:
On se concentre pas mal sur le code de la prochaine version en ce moment.


ok, j'essaierai de repondre aux questions bateaux et aux aspects que je connait un peu plus pendant cette periode de boulot intense pour vous.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 26, 2004 4:32 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
And in spare spare time, you're free to help again :-D
http://forum.hibernate.org/viewtopic.php?t=929338

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 26, 2004 10:07 am 
Newbie

Joined: Wed Mar 24, 2004 6:43 pm
Posts: 11
Location: Winnipeg, Manitoba, Canada
Could you guys please make your posts in English. My French isn't very good.

_________________
- Dylan Milks


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 26, 2004 3:35 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
The French part wasn't related to your pb sorry. He was just saying he had a dead headache, and was happy that I came back to the forum, etc etc :)

Try
### log just the SQL
log4j.logger.net.sf.hibernate.SQL=debug

### log JDBC bind parameters ###
log4j.logger.net.sf.hibernate.type=debug

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 26, 2004 5:41 pm 
Newbie

Joined: Wed Mar 24, 2004 6:43 pm
Posts: 11
Location: Winnipeg, Manitoba, Canada
Thanks for the advice. However, the logs show the correct values for the parameters - but when I look at the record in the database, the PK field contains the wrong value.

Here's what the log is telling me:

03:26:15:33:56 net.sf.hibernate.SQL [DEBUG] BatcherImpl.getPreparedStatement() - insert into INTERNET_TRANSACTION (STORE_ID, TRANSACTION_TIMESTAMP, INTERNET_TRANSACTION_ID) values (?, ?, ?)
03:26:15:33:56 net.sf.hibernate.type.LongType [DEBUG] NullableType.nullSafeSet() - binding '2140' to parameter: 1
03:26:15:33:56 net.sf.hibernate.type.TimestampType [DEBUG] NullableType.nullSafeSet() - binding '26 March 2004 15:33:56' to parameter: 2
03:26:15:33:56 net.sf.hibernate.type.LongType [DEBUG] NullableType.nullSafeSet() - binding '1047' to parameter: 3

The field in question is INTERNET_TRANSACTION_ID. It shows 1047 being inserted, however that value doesn't show up in the field. It's inserting a Hibernate-generated PK value instead. All other fields do appear correctly.

Any other thoughts?

_________________
- Dylan Milks


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 27, 2004 5:07 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
This value is exactly what Hibernate give to the JDBC driver.
Did you set an identity, a trigger or something generated on that field in your DB ? Hibernate can't handle that you you don't tell it.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 29, 2004 11:33 am 
Newbie

Joined: Wed Mar 24, 2004 6:43 pm
Posts: 11
Location: Winnipeg, Manitoba, Canada
Hello again.

There are no triggers on the table - I've just checked. What is an "identity"? I would check this out, however I don't know what an "identity" is. (Do you mean SYNONYM? There are no synonyms in my schema either.)

I'm wondering if it could be a problem with the datatype. The value in the bean is a LONG - which is a numeric datatype in Java. But Oracle doesn't support LONG as a number. LONG for Oracle is a TEXT format up to 2 GB in size. In the XML file, the id column field is of type LONG (I'm assuming Java LONG, not Oracle LONG). Could this be a problem?

Any other thoughts?

- Dylan

_________________
- Dylan Milks


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 31, 2004 9:20 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
identity means the column is filled by your DB in a incremental manner, it is used to add surrogate keys into DB and let the DB handle it. Oracle prefered way is sequence anyway.
Try to use NUMERIC or something like that for mapping numbers

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 31, 2004 10:31 am 
Newbie

Joined: Wed Mar 24, 2004 6:43 pm
Posts: 11
Location: Winnipeg, Manitoba, Canada
The problem was my Oracle JDBC driver. I down-graded to the previous version. Now everything works fine.

_________________
- Dylan Milks


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