-->
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: Timestamp corrupting id values
PostPosted: Wed Apr 08, 2009 11:21 am 
Newbie

Joined: Tue May 23, 2006 9:05 am
Posts: 5
Hello,

I have hit upon a really peculiar problem. I have a field where I want to store the last changed time, so I map it as type - timestamp. When I do that, while saving, it corrupts the other property values. If I change the type to - date, then it works fine, but the time of last change is not stored. The other properties are an integer and a string.

This seems a really weird issue, and I am not sure where to start debugging. I have about 10 other screens, and they all seem to work fine. Just this one alone.

Here is an interesting observation I made.
The integer property is corrupted only while creating it. Subsequent saves seems to leave it alone.
The string property(description) gets corrupted everytime, but there seems to be pattern to it. Only the first 3 letters get corrupted.
asd became ^óÀ
123asd became �asd
123asd became nq@asd
asd became ûS@asd

This is the first time I am coming across something like this in Hibernate. I hope no one else got this, but have the patience to help me debug this issue.

Hibernate version: - 3.2.6.ga

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="Branch" table="EXCEPTION_BRANCH_NUMBER">
<id name="branchNumber" type="integer">
<column name="BRANCH_NUMBER" precision="10" scale="0" />
<generator class="assigned" />
</id>
<property name="description" type="string">
<column name="DESCRIPTION" length="256" />
</property>
<property name="userId" type="string">
<column name="CHANGE_USER_ID" length="10" not-null="true" />
</property>
<property name="changeTimestamp" type="date">
<column name="CHANGE_TIMESTAMP" length="7" not-null="true" />
</property>
</class>
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():
hibernateTemplate.saveOrUpdate(branch);

Name and version of the database you are using:
Oracle 10

Debug level Hibernate log excerpt:
2009-04-08 11:09:32,367 470797 [btpool0-1] DEBUG org.springframework.orm.hibernate3.SessionFactoryUtils - Opening Hibernate Session
2009-04-08 11:09:32,367 470797 [btpool0-1] DEBUG org.hibernate.impl.SessionImpl - opened session at timestamp: 12392033723
2009-04-08 11:09:32,367 470797 [btpool0-1] DEBUG org.hibernate.jdbc.AbstractBatcher - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
2009-04-08 11:09:32,367 470797 [btpool0-1] DEBUG org.hibernate.jdbc.ConnectionManager - opening JDBC connection
2009-04-08 11:09:32,367 470797 [btpool0-1] DEBUG org.hibernate.SQL - select branch_.BRANCH_NUMBER, branch_.DESCRIPTION as DESCRIPT2_1_, branch_.CHANGE_USER_ID as CHANGE3_1_, branch_.CHANGE_TIMESTAMP as CHANGE4_1_ from EXCEPTION_BRANCH_NUMBER branch_ where branch_.BRANCH_NUMBER=?
2009-04-08 11:09:32,383 470813 [btpool0-1] DEBUG org.hibernate.jdbc.AbstractBatcher - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
2009-04-08 11:09:32,383 470813 [btpool0-1] DEBUG org.hibernate.event.def.AbstractSaveEventListener - generated identifier: 333, using strategy: org.hibernate.id.Assigned
2009-04-08 11:09:32,492 470922 [btpool0-1] DEBUG com.tdsecurities.branchRevenue.admin.support.HibernateTemplate - Eagerly flushing Hibernate session
2009-04-08 11:09:32,492 470922 [btpool0-1] DEBUG org.hibernate.event.def.AbstractFlushingEventListener - processing flush-time cascades
2009-04-08 11:09:32,492 470922 [btpool0-1] DEBUG org.hibernate.event.def.AbstractFlushingEventListener - dirty checking collections
2009-04-08 11:09:32,492 470922 [btpool0-1] DEBUG org.hibernate.event.def.AbstractFlushingEventListener - Flushed: 1 insertions, 0 updates, 0 deletions to 1 objects
2009-04-08 11:09:32,492 470922 [btpool0-1] DEBUG org.hibernate.event.def.AbstractFlushingEventListener - Flushed: 0 (re)creations, 0 updates, 0 removals to 0 collections
2009-04-08 11:09:32,492 470922 [btpool0-1] DEBUG org.hibernate.pretty.Printer - listing entities:
2009-04-08 11:09:32,508 470938 [btpool0-1] DEBUG org.hibernate.pretty.Printer - com.tdsecurities.branchRevenue.admin.models.Branch{changeTimestamp=2009-04-08 11:09:21, branchNumber=333, userId=PADINS2, description=asd}
2009-04-08 11:09:32,508 470938 [btpool0-1] DEBUG org.hibernate.jdbc.AbstractBatcher - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
2009-04-08 11:09:32,508 470938 [btpool0-1] DEBUG org.hibernate.SQL - insert into EXCEPTION_BRANCH_NUMBER (DESCRIPTION, CHANGE_USER_ID, CHANGE_TIMESTAMP, BRANCH_NUMBER) values (?, ?, ?, ?)
2009-04-08 11:09:32,508 470938 [btpool0-1] DEBUG org.hibernate.jdbc.AbstractBatcher - Executing batch size: 1
2009-04-08 11:09:32,539 470969 [btpool0-1] DEBUG org.hibernate.jdbc.Expectations - success of batch update unknown: 0
2009-04-08 11:09:32,539 470969 [btpool0-1] DEBUG org.hibernate.jdbc.AbstractBatcher - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
2009-04-08 11:09:32,539 470969 [btpool0-1] DEBUG org.springframework.orm.hibernate3.SessionFactoryUtils - Closing Hibernate Session
2009-04-08 11:09:32,539 470969 [btpool0-1] DEBUG org.hibernate.jdbc.ConnectionManager - releasing JDBC connection [ (open PreparedStatements: 0, globally: 0) (open ResultSets: 0, globally: 0)]
2009-04-08 11:09:32,539 470969 [btpool0-1] DEBUG org.hibernate.jdbc.ConnectionManager - transaction completed on session with on_close connection release mode; be sure to close the session to release JDBC resources!
2009-04-08 11:09:49,820 488250 [btpool0-1] DEBUG org.springframework.security.ui.ExceptionTranslationFilter - Chain processed normally
2009-04-08 11:09:49,820 488250 [btpool0-1] DEBUG org.springframework.security.context.HttpSessionContextIntegrationFilter - SecurityContextHolder now cleared, as request processing completed


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 09, 2009 4:47 am 
Expert
Expert

Joined: Fri Jul 13, 2007 8:18 am
Posts: 370
Location: london
I'm guessing its a data type mismatch. A timestamp will require more storage space than a date field. If you specify the hibernate type as timestamp but the actual database type is date there's a chance the data will overflow into adjacent fields.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 09, 2009 10:53 am 
Newbie

Joined: Tue May 23, 2006 9:05 am
Posts: 5
thx for the reply williams.

the database field is of type - date. I will try changing and see what happens. but I do have other tables, where this issue does not crop up. would you know why that occurs?

btw, when I use hibernate tools to generate the mapping, for date fields why does it automatically generate
Code:
length="7"
attribute? whts the significance?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 09, 2009 11:51 am 
Expert
Expert

Joined: Fri Jul 13, 2007 8:18 am
Posts: 370
Location: london
I can't imagine the length field matters. The DDL I just generated for date and timestamp columns doesn't include a length.

Although in my test I can't recreate the corruption you're seeing, I can confirm that squirrel displays column size of date as 7 and timestamp as 11. Not sure why I don't get corruption though - might depend on table layout internally in oracle.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 09, 2009 7:18 pm 
Newbie

Joined: Tue May 23, 2006 9:05 am
Posts: 5
BTW, the oracle version is 8.

I tried without the length and even then it has the problem.

Oracle doesn't support the timestamp field, so I cannot change the type of the field. Is hibernate timestamp property supported in Oracle 8? The thing is, hibernate enters only the date value, if u specify the type as date, and hence thts not an option either. i need with timestamp.

BTW, as a workaround, do you suggest any alternatives?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 14, 2009 12:48 am 
Newbie

Joined: Mon Apr 13, 2009 7:45 am
Posts: 4
Hi Zalym

I've also noticed that generated legth in the mappings I've done... I usually remove it...

You mention date, and time, and that Oracle doesn't support the timestamp datatype... what about the datetime datatype? (I know its supported in MySQL & MS SQL...)

If datetime doesn't help - you could always save your timestamp as a big number datatype in your table... you could also add an additional getter on your hibernate bean, that will translate the timestamp from a number into a Date-object...


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 14, 2009 3:15 pm 
Newbie

Joined: Tue May 23, 2006 9:05 am
Posts: 5
I am migrating an old EJB application, and the mandate is to not touch the DB as much as possible. So changing the data type or using another DB is unfortunately not a solution.


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.