-->
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.  [ 9 posts ] 
Author Message
 Post subject: hibernate jdbc bind value
PostPosted: Tue Jan 16, 2007 3:41 pm 
Beginner
Beginner

Joined: Thu Oct 05, 2006 4:00 pm
Posts: 22
hi, in my log4j file, I have

### log just the SQL
log4j.logger.org.hibernate.SQL=debug

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

however, the bind value is not shown in my log. I got this in my log

14:38:51,343 DEBUG SQL:346 - select attribute_value_seq.nextval from dual
14:38:51,359 DEBUG SQL:346 - insert into ATTRIBUTE_VALUE (ATTR_TYP_ID, ATTR_ID, OBJ_ID, REL_ID, ATTR_VALUE, ATTR_INT_VAL, ATTR_FLOAT_VAL, ATTR_DATE_VAL, CUSER, MUSER, ATTR_VAL_ID) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
14:38:51,421 WARN JDBCExceptionReporter:71 - SQL Error: 1, SQLState: 23000
14:38:51,421 ERROR JDBCExceptionReporter:72 - ORA-00001: unique constraint (BOEMD01.XAK1ATTRIBUTE_VALUE) violated

14:38:51,421 WARN JDBCExceptionReporter:71 - SQL Error: 1, SQLState: 23000
14:38:51,421 ERROR JDBCExceptionReporter:72 - ORA-00001: unique constraint (BOEMD01.XAK1ATTRIBUTE_VALUE) violated

14:38:51,421 ERROR AbstractFlushingEventListener:300 - Could not synchronize database state with session
org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:71)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)

thanks for the help.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 16, 2007 4:14 pm 
Beginner
Beginner

Joined: Thu Aug 31, 2006 2:31 pm
Posts: 25
Location: USA
Hi Wang,
Just check your Constraint BOEMD01.XAK1ATTRIBUTE_VALUE You can find the error easily.
Obviously you might have this on your field additional to the Primary Key.So while running your test , you have to take care to have a unique value every time you insert records.
Regards,
Vinodh

_________________
I am using a shitty e-mail filtering system that caused a lot of bounces for the admin of this forum. I need to turn on my brain next time and update my e-mail address.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 16, 2007 4:15 pm 
Regular
Regular

Joined: Wed Dec 07, 2005 4:19 pm
Posts: 53
It looks like you have a unique index on your ATTR_VALUE, and you are trying to insert the same (already exisiting) value in there... nothing to do with Hibernate.

I do not see any log() showing bound values (in Hibernate source), even though there is a lot of TRACE statements...

As a habbit, my objects implement toString() method as a 'dump' of important object attributes, and then I can easily add:
Code:
log.info("Inserting " + myObject);

anywhere - besides, it helps a lot when you are in debugger, showing toString() values often makes the display much less cluttered.

Do not forget to rate this posting - if it helped.
Martin.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 16, 2007 4:54 pm 
Beginner
Beginner

Joined: Thu Oct 05, 2006 4:00 pm
Posts: 22
the constraint XAK1ATTRIBUTE_VALUE is the combination of ATTR_ID, OBJ_ID, REL_ID has to be unique.

the ATTR_VALUE_ID is got from a sequence. I know REL_ID is NULL. OBJ_ID is preset. ATTR_ID is preset and it's not in the database.

I can do it manually (using assumed value) via SQL.

So, to resolve this, I really need to find out the value of id.

Any help?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 16, 2007 6:48 pm 
Regular
Regular

Joined: Wed Dec 07, 2005 4:19 pm
Posts: 53
Well, then we have insufficient info (Hibernate mapping file would help)

When you say
Quote:
ATTR_ID is preset and it's not in the database
,
Is ATTR_ID a primary key (entity identification), and (if so) are you letting Hibernate generate it OR are you generating it on youir own?
OR is it some foreign key?
OR is the primary key the 'ATTR_VALUE_ID is got from a sequence'?

When you say
Quote:
I really need to find out the value of id
, which of your XXX_ID you refer to?
Normally, you should be able to dump(log) values from your object just before the insert. Hibernate does not invent anything you have not given it, _except_ for the generated keys (which should be null to indicate they need to be generated).


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 17, 2007 10:08 am 
Beginner
Beginner

Joined: Thu Oct 05, 2006 4:00 pm
Posts: 22
ATTR_VALUE_ID is PK and got from a sequence.
there is another constraint on the table for (OBJ_ID, ATTR_ID, REL_ID) to be unique.

Before inserting, in the log, OBJ_ID, ATTR_ID have valid value. REL_ID is null.

I will try to drop the constraint to see what's going on there. thanks.

Any idea how to show the JDBC bind value in the log for hibernate?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 17, 2007 11:32 am 
Beginner
Beginner

Joined: Thu Oct 05, 2006 4:00 pm
Posts: 22
ok, I drop the constraint and found out obj_id is not populated.

I have a class object, which has a set of attributes. obj_id is got from a sequence. attribute.id is got from another sequence.

here is my hibernate.xml for those 2 classes.

1. object.hbm.xml

<class name="MetaData"
table="OBJECT"
lazy="false"
batch-size="10">

<!-- id property. -->
<id name="id"
type="integer"
column="OBJ_ID"
unsaved-value="null"
access="field">
<generator class="sequence">
<param name="sequence">object_seq</param>
</generator>
</id>

<!-- Name is limited to 100 characters.-->
<property name="name"
type="string"
column="OBJ_NME"
length="100"/>

<!-- Description is limited to 256 characters.-->
<property name="description"
type="string"
column="OBJ_DESC"
length="256"/>

<!-- MetaDataType property. -->
<many-to-one name="metaType"
class="MetaDataType"
column="OBJ_TYP_ID"
not-null="true"
cascade="none"/>

<!-- source relations property. -->
<set name="srcRelations"
table="ASSOCIATION"
lazy="true"
inverse="true"
cascade="all-delete-orphan"
batch-size="3">
<key column="SRC_OBJ_ID"/>
<one-to-many class="MetaDataRelation"/>
</set>

<!-- target relations property. -->
<set name="trgRelations"
table="ASSOCIATION"
lazy="true"
inverse="true"
cascade="all-delete-orphan"
batch-size="3">
<key column="DEST_OBJ_ID"/>
<one-to-many class="MetaDataRelation"/>
</set>

<!-- attributes property. -->
<set name="attributes"
table="ATTRIBUTE_VALUE"
lazy="true"
inverse="true"
cascade="all-delete-orphan"
batch-size="10">
<key column="OBJ_ID"/>
<one-to-many class="MetaDataAttribute"/>
</set>

<!-- creationUser is limited to 30 characters.-->
<property name="cUser"
type="string"
column="CUSER"
length="30"/>

<!-- modifyUser is limited to 30 characters.-->
<property name="mUser"
type="string"
column="MUSER"
length="30"/>

</class>



2. attribute.hbm.xml

<class name="MetaDataAttribute"
table="ATTRIBUTE_VALUE"
lazy="false"
batch-size="10">

<!-- id property. -->
<id name="id"
type="integer"
column="ATTR_VAL_ID"
unsaved-value="null"
access="field">
<generator class="sequence">
<param name="sequence">attribute_value_seq</param>
</generator>
</id>

<!-- MetaDataAttributeType relation -->
<many-to-one name="attrType"
class="MetaDataAttributeType"
column="ATTR_TYP_ID"
not-null="true"
cascade="none"/>

<!-- MetaDataAttributeElement relation -->
<many-to-one name="element"
class="MetaDataAttributeElement"
column="ATTR_ID"
not-null="true"
cascade="none"/>

<!-- MetaData relation -->
<many-to-one name="metaData"
class="MetaData"
column="OBJ_ID"
cascade="none"/>

<!-- MetaDataRelation relation -->
<many-to-one name="relation"
class="MetaDataRelation"
column="REL_ID"
cascade="none"/>

<!-- strValue is limited to 255 characters.-->
<property name="strValue"
type="string"
column="ATTR_VALUE"
length="255"/>

<!-- intValue property.-->
<property name="intValue"
type="integer"
column="ATTR_INT_VAL"/>

<!-- numValue property.-->
<property name="numValue"
type="float"
column="ATTR_FLOAT_VAL"/>

<!-- dateValue property.-->
<property name="dateValue"
type="date"
column="ATTR_DATE_VAL"/>

<!-- blobValue property.-->
<!-- property name="blobValue" type="binary" column="ATTR_BLOB_VAL"/ -->

<!-- creationUser is limited to 30 characters.-->
<property name="cUser"
type="string"
column="CUSER"
length="30"/>

<!-- modifyUser is limited to 30 characters.-->
<property name="mUser"
type="string"
column="MUSER"
length="30"/>
</class>

Just wonder, why obj_id is not populated when inserting into child table attribute_value? Thanks much.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 17, 2007 12:12 pm 
Beginner
Beginner

Joined: Thu Aug 31, 2006 2:31 pm
Posts: 25
Location: USA
HI Wang,
From your Log4J settings you are alredy set to display the binding values.

DEBUG IntegerType - binding '1001' to parameter: 1
DEBUG IntegerType - binding '1001' to parameter: 1
DEBUG IntegerType - binding '1001' to parameter: 1

you should see something similar to these on your console.But it wont work in Websphere environment.Im got this only when running with JRE 1.4 with SUN not with IBM.
So if you can switch your JRE version it might work.I ran with IBM JDK and it did not show up.- FYI

Regards,
Vinodh.

_________________
I am using a shitty e-mail filtering system that caused a lot of bounces for the admin of this forum. I need to turn on my brain next time and update my e-mail address.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 17, 2007 12:17 pm 
Beginner
Beginner

Joined: Thu Oct 05, 2006 4:00 pm
Posts: 22
Vinodh,

I could not find any "binding" message in my log4j log.

I am using Sun JDK 1.4.2 in Tomcat 5.5.

figured it out. I need to set child.setParent(parent) in my child class. my bad.


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