-->
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.  [ 6 posts ] 
Author Message
 Post subject: timestamp
PostPosted: Mon Oct 04, 2004 4:18 am 
Newbie

Joined: Thu Sep 23, 2004 4:11 am
Posts: 12
Location: Gold Coast, Australia
Hibernate version: 2.0


Given the following in a <class> in a mapping file:

Code:
<property
            name="t"
            type="java.sql.Timestamp"
            update="true"
            insert="true"
            access="property"
        >
            <column
                name="t"
            />
</property>


... why is it that schemaexport generates the column of type 'datetime' when using the MS SQL Server 2000 dialect?
If I specify sql-type="timestamp", I get a SQLException back from the driver "Unsupported data conversion".
If I use the MySQL dialect, a timestamp column is created and everything runs smoothly. If I write a small JDBC application that connects to the MS SQL server and I call ResultSet.getTimestamp, it works fine.

How do I use a MS SQL Server 2000 timestamp with Hibernate?
I am completely baffled - advice is most appreciated.


Complete stack trace:
Code:
java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Unsupported data conversion.
   at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)
   at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
   at com.microsoft.jdbc.base.BaseData.unsupportedConversion(Unknown Source)
   at com.microsoft.jdbc.base.BaseData.getTimestamp(Unknown Source)
   at com.microsoft.jdbc.base.BaseResultSet.getTimestamp(Unknown Source)
   at com.microsoft.jdbc.base.BaseResultSet.getTimestamp(Unknown Source)
   at org.apache.commons.dbcp.DelegatingResultSet.getTimestamp(DelegatingResultSet.java:261)
   at net.sf.hibernate.type.TimestampType.get(TimestampType.java:24)
   at net.sf.hibernate.type.NullableType.nullSafeGet(NullableType.java:62)
   at net.sf.hibernate.type.NullableType.nullSafeGet(NullableType.java:53)
   at net.sf.hibernate.type.AbstractType.hydrate(AbstractType.java:66)
   at net.sf.hibernate.loader.Loader.hydrate(Loader.java:686)
   at net.sf.hibernate.loader.Loader.loadFromResultSet(Loader.java:627)
   at net.sf.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:586)
   at net.sf.hibernate.loader.Loader.getRow(Loader.java:501)
   at net.sf.hibernate.loader.Loader.getRowFromResultSet(Loader.java:213)
   at net.sf.hibernate.loader.Loader.doQuery(Loader.java:281)
   at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:133)
   at net.sf.hibernate.loader.Loader.loadEntity(Loader.java:911)
   at net.sf.hibernate.loader.Loader.loadEntity(Loader.java:931)
   at net.sf.hibernate.loader.EntityLoader.load(EntityLoader.java:59)
   at net.sf.hibernate.loader.EntityLoader.load(EntityLoader.java:51)
   at net.sf.hibernate.persister.EntityPersister.load(EntityPersister.java:419)
   at net.sf.hibernate.impl.SessionImpl.doLoad(SessionImpl.java:2117)
   at net.sf.hibernate.impl.SessionImpl.doLoadByClass(SessionImpl.java:1991)
   at net.sf.hibernate.impl.SessionImpl.load(SessionImpl.java:1920)
   at com.tmits.web.re.actions.TempAction.execute(TempAction.java:24)
   at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:168)
   at com.opensymphony.xwork.interceptor.AroundInterceptor.intercept(AroundInterceptor.java:35)
   at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:165)
   at com.opensymphony.xwork.interceptor.AroundInterceptor.intercept(AroundInterceptor.java:35)
   at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:165)
   at com.opensymphony.xwork.interceptor.AroundInterceptor.intercept(AroundInterceptor.java:35)
   at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:165)
   at com.opensymphony.xwork.DefaultActionProxy.execute(DefaultActionProxy.java:115)
   at com.opensymphony.webwork.dispatcher.ServletDispatcher.serviceAction(ServletDispatcher.java:273)
   at com.opensymphony.webwork.dispatcher.ServletDispatcher.service(ServletDispatcher.java:243)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
   at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
   at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198)
   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
   at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
   at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
   at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
   at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
   at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
   at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
   at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
   at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
   at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
   at java.lang.Thread.run(Thread.java:595)
[/code]

_________________
SCJP 1.4, SCJD
Software Engineer, IBM Australia


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 04, 2004 6:08 am 
Beginner
Beginner

Joined: Wed Nov 19, 2003 6:46 pm
Posts: 41
Location: Auckland, New Zealand
My guess would be that a Timestamp has special meaning in SQL Server to be an alias for a RowVersion type of field, that is, a field that is updated each time the row is updated. It probably used to be implemented as an actual timestamp, but now it's just a number, similar to the way Hibernate manages verison fields.

If you're trying to store a date/time then an SQL Server DATETIME is exactly the right type.

This is an interesting article:

http://java.sun.com/j2se/1.3/docs/guide ... pping.html


Top
 Profile  
 
 Post subject: timestamp
PostPosted: Mon Oct 04, 2004 7:58 pm 
Newbie

Joined: Thu Sep 23, 2004 4:11 am
Posts: 12
Location: Gold Coast, Australia
Thanks for the response.
A SQL Server 2000 timestamp field can be retrieved from a ResultSet using java.sql.Timestamp. I don't understand why Hibernate can't do just the same?

Your response does not explain this anomaly unless I have misinterpreted it, in which case, I apologise for my lack of coherence.

_________________
SCJP 1.4, SCJD
Software Engineer, IBM Australia


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 04, 2004 8:04 pm 
Newbie

Joined: Thu Sep 23, 2004 4:11 am
Posts: 12
Location: Gold Coast, Australia
I might just use a Long field and set it to System.currentTimeMillis() before persisting it.

_________________
SCJP 1.4, SCJD
Software Engineer, IBM Australia


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 04, 2004 9:51 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Because Hibernate works on the JDBC type system; it knows (nor should/can it) nothing about conversions allowed by various vendors. In the documentation for your SQLServer driver, what is the JDBC type mapped to the java.sql.Timestamp type? Most definitely it is the JDBC type that maps to SQLServer's DATATIME type.

Now if you can do this in your JDBC code given a ResultSet containing this type of column, then Hibernate will also be able to do it. But you asked about this in regards to Hibernate generating a schema for you. There it is a little bit different; there it strictly (and has to if you think about it) adheres to the JDBC type mappings.


Top
 Profile  
 
 Post subject: timestamp
PostPosted: Mon Oct 04, 2004 11:09 pm 
Newbie

Joined: Thu Sep 23, 2004 4:11 am
Posts: 12
Location: Gold Coast, Australia
I don't completely understand that, given my "newness" to Hibernate, but you are right; the driver defines the DATETIME to the JDBC Type TIMESTAMP ... and the TIMESTAMP type is mapped to the JDBC Type BINARY.

Thanks for the response.

_________________
SCJP 1.4, SCJD
Software Engineer, IBM Australia


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