-->
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.  [ 2 posts ] 
Author Message
 Post subject: Set default timestamp string representation
PostPosted: Fri Dec 18, 2015 5:33 pm 
Newbie

Joined: Fri Dec 18, 2015 5:09 pm
Posts: 1
Hi,

I support an application using Hibernate to access a DB2 database. We are migrating the database to Oracle 12c. We are running into issues with the differing string representations for timestamps used by DB2 and Oracle.

Our DB2 timestamp data is stored as strings with a column format of CHAR(26). The string format for our existing data is YYYY-MM-DD HH24:MI:SS.FF3. The Oracle default is DD-MON-RR HH.MI.SSXFF AM, so on reads Oracle can't parse the existing data, and on insert it fails because it needs room for 31 characters.

Our value objects (our pojo's) hold the timestamps in java.util.Date. The string conversions are being handled implicitly by Hibernate. Here's an example of one of our hibernate mapping files:

Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
        "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
    <class name="com.foo.bar.LastModified" table="LastModified" >
       <id name="resourceId" type="string" >
         <generator class="assigned"/>
       </id>
         <property name="timeLastMod" type="string" />
         <property name="timestampLastMod" type="timestamp" />
     </class>
    <query name="LastModified.getByResourceId"><![CDATA[
    FROM com.foo.bar.LastModified where resourceId=:resourceId]]>
    </query>
</hibernate-mapping>


I would like to update our existing hibernate mapping files to enforce a timestamp string representation of YYYY-MM-DD HH24:MI:SS.FF3. I know how to set the NLS_TIMESTAMP_FORMAT using "alter session" or "alter system", but I would like something that handles this at the point the reads and updates are being made, to avoid ambiguity.

Any advice would be greatly appreciated.


Top
 Profile  
 
 Post subject: Re: Set default timestamp string representation
PostPosted: Sat Dec 19, 2015 3:10 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
You need to write a Hibernate UserTime that makes the conversion from the CHAR(26) format to a Java java.util.Date.


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