-->
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.  [ 4 posts ] 
Author Message
 Post subject: Date on DB (DB2) getting blown with timestamp type
PostPosted: Mon Aug 22, 2005 10:46 am 
Senior
Senior

Joined: Tue Aug 03, 2004 2:11 pm
Posts: 142
Location: Somerset
I have a field defined as a DATE on a database file (DB2 by the way)

The field is defined in my class as a java.util.Date, and initiliased to a new Date()

When hibernate tries to persist away my date it fails on DB2 with a "Datetime field overflow." DB2 error.

This is because (looking at the hibernate trace) hibernate is trying to put a Timestamptype (which contains seconds) into a DB2 DATE field (which doesn't)

org.hibernate.type.TimestampType - binding '2005-08-22 15:29:53' to parameter: 6

YOu don't get this error in DB2 7.2, nor do you get it in the iSeries version of DB2, but I can understand why the error occurs, because hibernate is plainly trying to add more data into the field than it should be (its just that the other versions of DB2 can cope with this).

Is this a bug in hibernate, and if it is not (or even if it is) what is the work around ?


Hibernate version:

3.0.1

Mapping documents:

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
<class name="net.targetgroup.broker.marketing.Campaign" table="campaign" lazy="false">
<id name="identifier" type="int" column="IDENTIFIER" unsaved-value="-1">
<generator class="native" />
</id>

<version name="recordVersion" type="integer" column="RECORD_VERSION" unsaved-value="null" />
<property name="description" column="DESCRIPTION"/>
<property name="code"/>
<property name="validDate"/>
<property name="expiryDate"/>
<property name="creationTimestamp" column="CREATIONDATE"/>
<property name="creationUserName" column="CREATIONUSER"/>
<property name="active" column="ACTIVE" type="net.targetgroup.util.datatypes.CustomBooleanType"/>
<property name="typicalAPR"/>
<set name="schemes" lazy="false"
inverse="true"
cascade="all-delete-orphan">
<key>
<column name="CAMPAIGN_IDENTIFIER" />
</key>
<one-to-many class="net.targetgroup.broker.marketing.Scheme"/>
</set>
</class>

</hibernate-mapping>

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

2005-08-22 15:29:53,769 [Servlet.Engine.Transports : 1] DEBUG org.hibernate.persister.entity.BasicEntityPersister - Version: 0
2005-08-22 15:29:53,769 [Servlet.Engine.Transports : 1] DEBUG org.hibernate.jdbc.AbstractBatcher - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
2005-08-22 15:29:53,769 [Servlet.Engine.Transports : 1] DEBUG org.hibernate.jdbc.AbstractBatcher - opening JDBC connection
2005-08-22 15:29:53,769 [Servlet.Engine.Transports : 1] DEBUG org.hibernate.jdbc.JDBCContext - successfully registered Synchronization
2005-08-22 15:29:53,769 [Servlet.Engine.Transports : 1] DEBUG org.hibernate.SQL - insert into campaign (RECORD_VERSION, DESCRIPTION, code, validDate, expiryDate, CREATIONDATE, CREATIONUSER, ACTIVE, typicalAPR, IDENTIFIER) values (?, ?, ?, ?, ?, ?, ?, ?, ?, default)
2005-08-22 15:29:53,769 [Servlet.Engine.Transports : 1] DEBUG org.hibernate.jdbc.AbstractBatcher - preparing statement
2005-08-22 15:29:53,769 [Servlet.Engine.Transports : 1] DEBUG org.hibernate.persister.entity.BasicEntityPersister - Dehydrating entity: [net.targetgroup.broker.marketing.Campaign#<null>]
2005-08-22 15:29:53,769 [Servlet.Engine.Transports : 1] DEBUG org.hibernate.type.IntegerType - binding '0' to parameter: 1
2005-08-22 15:29:53,769 [Servlet.Engine.Transports : 1] DEBUG org.hibernate.type.StringType - binding 'Adminisitrator' to parameter: 2
2005-08-22 15:29:53,769 [Servlet.Engine.Transports : 1] DEBUG org.hibernate.type.StringType - binding 'BODE' to parameter: 3
2005-08-22 15:29:53,769 [Servlet.Engine.Transports : 1] DEBUG org.hibernate.type.TimestampType - binding '2005-11-11 15:29:53' to parameter: 4
2005-08-22 15:29:53,769 [Servlet.Engine.Transports : 1] DEBUG org.hibernate.type.TimestampType - binding '2006-06-12 15:29:53' to parameter: 5
2005-08-22 15:29:53,769 [Servlet.Engine.Transports : 1] DEBUG org.hibernate.type.TimestampType - binding '2005-08-22 15:29:53' to parameter: 6
2005-08-22 15:29:53,769 [Servlet.Engine.Transports : 1] DEBUG org.hibernate.type.StringType - binding null to parameter: 7
2005-08-22 15:29:53,769 [Servlet.Engine.Transports : 1] DEBUG org.hibernate.type.DoubleType - binding '0.0' to parameter: 9
2005-08-22 15:29:54,019 [Servlet.Engine.Transports : 1] DEBUG org.hibernate.jdbc.AbstractBatcher - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
2005-08-22 15:29:54,019 [Servlet.Engine.Transports : 1] DEBUG org.hibernate.jdbc.AbstractBatcher - closing statement
2005-08-22 15:29:54,019 [Servlet.Engine.Transports : 1] DEBUG org.hibernate.util.JDBCExceptionReporter - could not insert: [net.targetgroup.broker.marketing.Campaign] [insert into campaign (RECORD_VERSION, DESCRIPTION, code, validDate, expiryDate, CREATIONDATE, CREATIONUSER, ACTIVE, typicalAPR, IDENTIFIER) values (?, ?, ?, ?, ?, ?, ?, ?, ?, default)]
COM.ibm.db2.jdbc.DB2Exception: [IBM][CLI Driver] CLI0114E Datetime field overflow. SQLSTATE=22008
at COM.ibm.db2.jdbc.app.SQLExceptionGenerator.throw_SQLException(Unknown Source)
at COM.ibm.db2.jdbc.app.SQLExceptionGenerator.throw_SQLException(Unknown Source)
at COM.ibm.db2.jdbc.app.SQLExceptionGenerator.check_return_code(Unknown Source)
at COM.ibm.db2.jdbc.app.DB2PreparedStatement.execute2(Unknown Source)
at COM.ibm.db2.jdbc.app.DB2PreparedStatement.executeUpdate(Unknown Source)
at com.ibm.ws.rsadapter.jdbc.WSJdbcPreparedStatement.executeUpdate(WSJdbcPreparedStatement.java:469)
at org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntityPersister.java:1776)
at org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntityPersister.java:2187)
at org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:34)

Name and version of the database you are using:

IBM DB2 8.1 (PC)

_________________
On the information super B road


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 22, 2005 1:18 pm 
Regular
Regular

Joined: Wed Jan 07, 2004 5:16 pm
Posts: 65
Location: CA, USA
Specify a mapping type for your Date attributes. Use type="date" if you are mapping to a date column, and type="timestamp" if you are mapping to a timestamp column.


Kevin Hooke


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 22, 2005 3:22 pm 
Senior
Senior

Joined: Tue Aug 03, 2004 2:11 pm
Posts: 142
Location: Somerset
khooke wrote:
Specify a mapping type for your Date attributes. Use type="date" if you are mapping to a date column, and type="timestamp" if you are mapping to a timestamp column.


Kevin Hooke


I'll try that thanks. I kind of assumed that as the column was a date, it would know to map to a date.

If it works one credit coming your way LOL

_________________
On the information super B road


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 23, 2005 3:52 am 
Senior
Senior

Joined: Tue Aug 03, 2004 2:11 pm
Posts: 142
Location: Somerset
khooke wrote:
Specify a mapping type for your Date attributes. Use type="date" if you are mapping to a date column, and type="timestamp" if you are mapping to a timestamp column.


Kevin Hooke


That worked perfectly. Thanks.

_________________
On the information super B road


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.