-->
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.  [ 3 posts ] 
Author Message
 Post subject: SQL smalldateti-> hbm sql-type="date" Timestamp
PostPosted: Thu May 12, 2005 6:25 pm 
Newbie

Joined: Tue May 03, 2005 8:02 pm
Posts: 13
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

I've got my mapping file, database, POJO and config file all set up. The simple CAT example from Hibernate guide works.

But when I try to access a smalldatetime column in my SQL Server database, I get the error "Timestamp format must be yyyy-mm-dd hh:mm:ss.fffffffff" I'm not sure why it's expecting a timestamp because the config file, pojo and database all say "date" or "smalldatetime".

Thanks

Hibernate version:
3.0

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

<hibernate-mapping>
   <class name="com.rps.monitor.MonitorVisit"   table="monitor_visits">
      
      <id name="id" type="int" unsaved-value="null">
         <column name="monitor_visit_id" sql-type="int" not-null="true" />
         <generator class="identity" />
      </id>
      
      <property name="visitDateDraftSubmitted">
         <column name="visit_date_draft_submitted" sql-type="date" not-null="false" />
      </property>

   </class>
</hibernate-mapping>

Code between sessionFactory.openSession() and session.close():
Code:
       
        MonitorVisit mv = (MonitorVisit) session.get(MonitorVisit.class, new Integer(555));
        System.out.println(mv.getPiPersonID());

Full stack trace of any exception that occurs:
Code:
log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
java.lang.IllegalArgumentException: Timestamp format must be yyyy-mm-dd hh:mm:ss.fffffffff
   at java.sql.Timestamp.valueOf(Unknown Source)
   at net.sourceforge.jtds.jdbc.Support.convert(Support.java:407)
   at net.sourceforge.jtds.jdbc.JtdsResultSet.getTimestamp(JtdsResultSet.java:1116)
   at net.sourceforge.jtds.jdbc.JtdsResultSet.getTimestamp(JtdsResultSet.java:1268)
   at org.hibernate.type.TimestampType.get(TimestampType.java:28)
   at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:77)
   at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:68)
   at org.hibernate.type.AbstractType.hydrate(AbstractType.java:80)
   at org.hibernate.persister.entity.BasicEntityPersister.hydrate(BasicEntityPersister.java:1663)
   at org.hibernate.loader.Loader.loadFromResultSet(Loader.java:877)
   at org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:833)
   at org.hibernate.loader.Loader.getRow(Loader.java:746)
   at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:290)
   at org.hibernate.loader.Loader.doQuery(Loader.java:384)
   at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:203)
   at org.hibernate.loader.Loader.loadEntity(Loader.java:1255)
   at org.hibernate.loader.entity.EntityLoader.load(EntityLoader.java:139)
   at org.hibernate.loader.entity.EntityLoader.load(EntityLoader.java:124)
   at org.hibernate.persister.entity.BasicEntityPersister.load(BasicEntityPersister.java:2453)
   at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:387)
   at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:368)
   at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:166)
   at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:140)
   at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:249)
   at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:123)
   at org.hibernate.impl.SessionImpl.get(SessionImpl.java:561)
   at org.hibernate.impl.SessionImpl.get(SessionImpl.java:556)
   at com.rps.monitor.TestMonitorVisit.main(TestMonitorVisit.java:24)
Exception in thread "main"

Name and version of the database you are using:
SQL Server 2000 with the JTDS driver...perhaps a different driver would give better results?

The generated SQL (show_sql=true):
None showing in Eclipse Hibernate console. Don't know how to turn show_sql on yet

Debug level Hibernate log excerpt:
Haven't got logging working yet.


Top
 Profile  
 
 Post subject: Hibernate thinks SQL Server Date field is a Timestamp
PostPosted: Fri May 13, 2005 10:16 am 
Newbie

Joined: Tue May 03, 2005 8:02 pm
Posts: 13
This is sort of a repeat of the original post but with a better subject line.

Thanks

I've got my mapping file, database, POJO and config file all set up. The simple CAT example from Hibernate guide works.

But when I try to access a smalldatetime or date column in my SQL Server database, I get the error "Timestamp format must be yyyy-mm-dd hh:mm:ss.fffffffff" I'm not sure why it's expecting a timestamp because the config file, pojo and database all say "date" or "smalldatetime".

Thanks


Top
 Profile  
 
 Post subject: Fixed
PostPosted: Fri May 13, 2005 6:50 pm 
Newbie

Joined: Tue May 03, 2005 8:02 pm
Posts: 13
In case anyone else encounters this problem, I thought I'd post the solution.

Originally the columns were smalldatetime. That created the timestamp problem.

I used Enterprise Manager to rebuild the table with datetime fields. The timestamp problem continued.

I created a complete new copy of the table and everything worked fine.

This solution might be obvious. But the people who set up the system used smalldatetime everywhere. I was hoping to avoid having to rebuild and repopulate every table in the application across 6 servers.

But it looks like that's the solution.

BTW, I also realized something else: if you use Java primitives, like int, for fields that can be nullable, Hibernate stores them in the db as 0. That may not be what you want (null and zero aren't the same after all).

If another app, say Query Analyzer, writes a row with the nulls and you try to get() it with Hibernate, you'll get a null exception.

Switch to Integer and the other wrapper classes and you should be fine.


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