-->
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: Storing time info with millisecond precession. How?
PostPosted: Wed Jan 05, 2005 9:17 am 
Newbie

Joined: Wed Jan 05, 2005 9:08 am
Posts: 3
Hibernate version: 2.1.7c

Mapping documents:N/A

Code between sessionFactory.openSession() and session.close():N/A

Full stack trace of any exception that occurs:N/A

Name and version of the database you are using:Oracle

The generated SQL (show_sql=true):N/A

Debug level Hibernate log excerpt:N/A

Hello forum,

I want to map a java.util.Calendar Property to Database with Millisecond precession. All attemps using "time", "date", "timestamp", "calendar" in the mappings failed. It's just day precessision dates that show up in the DB. Don't want to create another user type...please help!

Thanks,
Peter


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 05, 2005 9:33 am 
Contributor
Contributor

Joined: Thu Nov 06, 2003 9:49 pm
Posts: 104
Location: New York, NY
'timestamp' results in day precision in the database? That doesn't sound right.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 05, 2005 10:03 am 
Newbie

Joined: Wed Jan 05, 2005 9:08 am
Posts: 3
Yes, you're right. Actually I get an exception when using "timestamp". Here's more data on the topic:

This is the XDoclet for the Calendar getter:
Code:
@hibernate.property column = "MODIFICATION_TS" not-null = "true" type = "timestamp"


Which is ANT-transformed to this mapping (excerpt)
Code:
       
<property
            name="modificationTimeStamp"
            type="timestamp"
            update="true"
            insert="true"
            access="property"
            column="MODIFICATION_TS"
            not-null="true"
        />


And here is the ANT-generated schema (excerpt)
Code:
create table ANY (
   ...
   MODIFICATION_TS date not null,
   ...
);


When running this example I get the following exception on write access
Code:
java.lang.ClassCastException
   at net.sf.hibernate.type.TimestampType.deepCopyNotNull(TimestampType.java:63)
   at net.sf.hibernate.type.NullableType.deepCopy(NullableType.java:96)
   at net.sf.hibernate.type.TypeFactory.deepCopy(TypeFactory.java:212)
   at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:935)
   at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:866)
   at net.sf.hibernate.impl.SessionImpl.saveWithGeneratedIdentifier(SessionImpl.java:788)
   at net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:747)


Anyway I'm still looking for a high resolution calendar writing/reading solution. I started without the explicit "type" spec in XDoclet, which gave me a runing example but with low resolution.

Futher help appreciated, Thanks!
Peter


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 05, 2005 12:36 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Right, because java.util.Calendar and is not castable to either java.sql.Timestamp nor java.util.Date. The correct combination should be to use type="calendar" which specifies the Hibernate CalendarType.

Both CalendarType and TimestampType map to the JDBC TIMESTAMP type. JDBC defines the TIMESTAMP datatype as having millisecond precision. So if there is a problem getting correct precision from either of these, the problem is with the JDBC driver.


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:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.