-->
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: insert problem
PostPosted: Fri Sep 19, 2003 10:17 am 
Newbie

Joined: Tue Sep 09, 2003 3:40 pm
Posts: 9
Hi, guys:

Here is my problem: if a database table is empty originally, data can be
inserted without a problem; if I use a database table with existing data,
I get the following exception. I am using "native" generator for ids (primary keys):

COM.ibm.db2.jdbc.DB2Exception: [IBM][CLI Driver][DB2/NT] SQL0803N One or more values in the INSERT statement, UPDATE statement, or foreign key update caused by a DELETE statement are not valid because the primary key, unique constraint or unique index identified by "1" constrains table "RICK.SAMPLE" from having duplicate rows for those columns. SQLSTATE=23505


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 19, 2003 12:04 pm 
Regular
Regular

Joined: Tue Sep 09, 2003 9:37 pm
Posts: 56
Location: Ogden, Utah, USA
Is your database table set up as an identity?
(Something like this in the create table script :
INTEGER GENERATED BY DEFAULT AS IDENTITY NOT NULL)

Also, what DB2 server platform are you using? We had to change the autogenerating key script in the dialect for DB2 on the OS 390.

Jenica


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 19, 2003 1:07 pm 
Newbie

Joined: Tue Sep 09, 2003 3:40 pm
Posts: 9
Yes, in my sample table, I have the following on the first line:

sample_id INTEGER not null generated by default as identity,

I am using DB2 UDB7.2 Personal Edition, is this the cause of my problem?

Thanks.
TealWren wrote:
Is your database table set up as an identity?
(Something like this in the create table script :
INTEGER GENERATED BY DEFAULT AS IDENTITY NOT NULL)

Also, what DB2 server platform are you using? We had to change the autogenerating key script in the dialect for DB2 on the OS 390.

Jenica


Top
 Profile  
 
 Post subject:
PostPosted: Sun Sep 21, 2003 10:13 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
What SQL is being executed?


I suggest you turn up the hibernate logging.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 22, 2003 11:48 am 
Regular
Regular

Joined: Tue Sep 09, 2003 9:37 pm
Posts: 56
Location: Ogden, Utah, USA
The default SQL for the hibernate dialect is:

values IDENTITY_VAL_LOCAL()

If that statement works for you just using straight jdbc it probably isn't a problem. What Hibernate does is it saves your object, then calls the above statement to find out what DB2 assigned to the identity field.

Another potential cause of this problem would be that your database connection has autocommit true. The post and the subsequent sql to retrieve the identity have to be in the same transaction, so you can't be autocommitting. Connections retrieved from Websphere JNDI automatically have autocommit true.

The DB2 error that you're getting suggests that for some reason you're trying to save two different records with the same id. I'd guess that most likely that id is a null. I've seen this happen when Hibernate's retrieval of the identity didn't work correctly so when you update the object it gives you an error. It could be caused by any number of different things, though!

If you add
hibernate.show_sql = true
to your hibernate.properties, and something like
log4j.logger.cirrus.hibernate = DEBUG, console
to your log4j.properties, you'll get a wealth of messages that will tell you what hibernate was trying to do when the error cropped up. That should narrow things down a bit!

Good luck!
Jenica


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 23, 2003 8:54 pm 
Beginner
Beginner

Joined: Wed Aug 27, 2003 8:53 pm
Posts: 34
Hi, guys:

I got the same problem. I am wondering if any other people using DB2
have this problem? Thanks for your pointers anyways.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 24, 2003 12:41 pm 
Regular
Regular

Joined: Tue Sep 09, 2003 9:37 pm
Posts: 56
Location: Ogden, Utah, USA
This problem could have many potential causes.

#1. the "values IDENTITY_VAL_LOCAL()" function doesn't work in your version of SQL. If you run this and it throws an SQL error, you may need to use a custom dialect. I can send you mine - I had to change the identity select string to "select sysibm.identity_val_local() from sysibm.sysdummy1"

#2. Your connection has autocommit true. Put in a logging statement or something to see if your connection has autocommit true. If it does, you need to set it to false after you get it.

#3. Could be none of the above. Add some logging statements, turn on hibernate show_sql and logging, and see what exactly is happening when you save the offending object. That will narrow it down so that someone can help you!

I had the problem with DB2, but it wasn't a showstopper, and not necessarily specific to db2. Also, it worked fine with db2 7.1 on a NT server but didn't work with db2 7.1 on the OS390, so problem #1 is database server platform specific.

Jenica


Top
 Profile  
 
 Post subject: Re: insert problem - solution?
PostPosted: Thu Sep 25, 2003 6:42 pm 
Regular
Regular

Joined: Fri Sep 12, 2003 12:40 pm
Posts: 65
rick_cols wrote:
if a database table is empty originally, data can be
inserted without a problem; if I use a database table with existing data,
I get the following exception.


Rick, check out this post. I too, thought it was a hibernate issue, it turns out that with identity, my scripts had to be changed. Check out this post.

_________________
- Brian


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.