-->
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: db2 error when trying to save aggregated objects
PostPosted: Thu Sep 25, 2003 5:42 pm 
Pro
Pro

Joined: Mon Sep 08, 2003 4:30 pm
Posts: 203
Hi all,

I have the following mappings:

<hibernate-mapping default-cascade="all" auto-import="true">
<class name="com.diatem.db.teste.Address" table="address" mutable="true" polymorphism="implicit" dynamic-update="false" dynamic-insert="false">
<id name="id" type="long" unsaved-value="0">
<generator class="native">
</generator>
</id>

<property name="street" type="string"></property>
<property name="city" type="string"/>
<property name="person" type="com.diatem.db.teste.Person" length="1024"/>

</class>

</hibernate-mapping>

<hibernate-mapping default-cascade="none" auto-import="true">
<class name="com.diatem.db.teste.Person" table="person" mutable="true" polymorphism="implicit" dynamic-update="false" dynamic-insert="false">
<id name="id" type="long" unsaved-value="0">
<generator class="native">
</generator>
</id>

<property name="firstName" type="string"/>
<property name="lastName" type="string"/>
<property name="age" type="string"/>

<property name="address" type="com.diatem.db.teste.Address" length="1024"/>
<property name="office" type="com.diatem.db.teste.Address" length="1024"/>


</class>

</hibernate-mapping>


The problem is that if I DONT specify length(1024) and it takes the default 255 for the VARCHARs that represent the Person or Address references, I get the folowing from DB2 when trying to save one of the above objects:


COM.ibm.db2.jdbc.DB2Exception: [IBM][CLI Driver][DB2/SUN] SQL0302N The value of a host variable in the EXECUTE or OPEN statement is too large for its corresponding use. SQLSTATE=22001
at COM.ibm.db2.jdbc.app.SQLExceptionGenerator.throw_SQLException(SQLExceptionGenerator.java:270)
at COM.ibm.db2.jdbc.app.SQLExceptionGenerator.throw_SQLException(SQLExceptionGenerator.java:207)
at COM.ibm.db2.jdbc.app.SQLExceptionGenerator.check_return_code(SQLExceptionGenerator.java:458)
at COM.ibm.db2.jdbc.app.DB2PreparedStatement.loadParameters(DB2PreparedStatement.java:1398)
at COM.ibm.db2.jdbc.app.DB2PreparedStatement.execute2(DB2PreparedStatement.java:2097)
at COM.ibm.db2.jdbc.app.DB2PreparedStatement.executeUpdate(DB2PreparedStatement.java:1642)
at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:504)
at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:444)
at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:717)
at net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:605)
at com.diatem.db.teste.MainTeste.go(MainTeste.java:68)
at com.diatem.db.teste.MainTeste.main(MainTeste.java:37)
rethrown as net.sf.hibernate.JDBCException: Could not insert: [IBM][CLI Driver][DB2/SUN] SQL0302N The value of a host variable in the EXECUTE or OPEN statement is too large for its corresponding use. SQLSTATE=22001
at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:720)
at net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:605)
at com.diatem.db.teste.MainTeste.go(MainTeste.java:68)
at com.diatem.db.teste.MainTeste.main(MainTeste.java:37)
Caused by: COM.ibm.db2.jdbc.DB2Exception: [IBM][CLI Driver][DB2/SUN] SQL0302N The value of a host variable in the EXECUTE or OPEN statement is too large for its corresponding use. SQLSTATE=22001
at COM.ibm.db2.jdbc.app.SQLExceptionGenerator.throw_SQLException(SQLExceptionGenerator.java:270)
at COM.ibm.db2.jdbc.app.SQLExceptionGenerator.throw_SQLException(SQLExceptionGenerator.java:207)
at COM.ibm.db2.jdbc.app.SQLExceptionGenerator.check_return_code(SQLExceptionGenerator.java:458)
at COM.ibm.db2.jdbc.app.DB2PreparedStatement.loadParameters(DB2PreparedStatement.java:1398)
at COM.ibm.db2.jdbc.app.DB2PreparedStatement.execute2(DB2PreparedStatement.java:2097)
at COM.ibm.db2.jdbc.app.DB2PreparedStatement.executeUpdate(DB2PreparedStatement.java:1642)
at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:504)
at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:444)
at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:717)
... 3 more


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 25, 2003 8:51 pm 
Beginner
Beginner

Joined: Fri Aug 29, 2003 12:38 am
Posts: 22
Location: Phoenix, AZ
First, I do not belive that DB2 defaults varchar fields to 255 - rather 1.

In any case, enable sql logging to see exactly what sql is being attempted by putting

Code:
hibernate.show_sql=true
in hibernate.properties
or
Code:
<property name="show_sql">true</property>
in hibernate.cfg.xml to show the sql
and
Code:
log4j.logger.net.sf.hibernate.type=debug
into your log4j properties file to display the bind params


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 25, 2003 10:10 pm 
Pro
Pro

Joined: Mon Sep 08, 2003 4:30 pm
Posts: 203
Hi,

I am sure that the DB2 tables are created with varchar(255) because I saw the output.

TIA,

steve


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 26, 2003 12:18 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Quote:
<property name="address" type="com.diatem.db.teste.Address" length="1024"/>
<property name="office" type="com.diatem.db.teste.Address" length="1024"/>


Question: do you want these to be foreign key references? Because thats not what the above mapping does. The above is most likely serializing instances of type Address into the "address" and "office" columns. If you wanted FK references, you should be using the <many-to-one> mapping for these:
Code:
<many-to-one name="address" class="com.diatem.db.teste.Address" />
<many-to-one name="office" class="com.diatem.db.teste.Address" />

http://www.hibernate.org/hib_docs/reference/html/or-mapping.html#or-mapping-s1-8

Otherwise, what is the problem? Just that you have to specify the size?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 26, 2003 4:39 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
There is a DB2 config parameter which makes this exception go away. It is a common problem not at all related to Hibernate.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 26, 2003 8:04 am 
Pro
Pro

Joined: Mon Sep 08, 2003 4:30 pm
Posts: 203
Hi,

Steve, Gavin, thanks so much!

Steve must be right saying that Hibernate is trying to serialize the objects into DB2 columns. That explains the need for such a big VARCHAR value for the serialized objects!

Actually, I wanted only to go with FK, not the entire serialized object. So Steve's suggestion makes perfect sense.

Thanks Gavin for pointing out the need for a specific DB setting (in any case).

Best,

Steve.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 26, 2003 5:30 pm 
Beginner
Beginner

Joined: Fri Aug 29, 2003 12:38 am
Posts: 22
Location: Phoenix, AZ
Of course, steve saw the problem immediately which I missed (actually my mind read them as references.. doh!), but I would still like to point out that had you printed out the sql this problem would probably been quite obvious much sooner, when you saw the serialized object being inserted.


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.