-->
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: java.util.Date property is populated with java.sql.Timestamp
PostPosted: Sat Nov 20, 2004 2:13 pm 
Regular
Regular

Joined: Tue Jan 06, 2004 3:32 pm
Posts: 80
Location: Munich, Germany
Hibernate version:

2.1.6 on JDK 1.5

Mapping documents:
Code:
    <property
         name="createdAt"
         type="java.util.Date" (or "timestamp", tried both)
         update="true"
         insert="true"
         access="property"
         column="created_at"
     />

   import java.util.Date;

   private Date createdAt;

   public Date getCreatedAt()
   {
      return createdAt;
   }

   private void setCreatedAt(Date createdAt)
   {
      this.createdAt = createdAt;
   }


Name and version of the database you are using:

MySQL 4.0.18

Problem:

Hibernate populates the above property with a java.sql.Timestamp instead of a java.util.Date. I know Timestamp extends Date, but if you want to use Date.compareTo(Date), you can only compare Date against Date or Timestamp against Timestamp, not Date against Timestamp or the other way around (raises ClassCastException).

You should be consistant throughout your application about the use of java.util.Date or java.sql.Timestamp. I chose to use java.util.Date - how can I force Hibernate to always instantiate java.util.Date?

The strange thing is that this problem seems to have started with JDK 1.5 - on JDK 1.4 I was using type="timestamp" and think I got an java.util.Date (at least I did not get a ClassCastException when comparing dates).

Regards,

Andreas


Top
 Profile  
 
 Post subject:
PostPosted: Sat Nov 20, 2004 2:19 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
http://forum.hibernate.org/viewtopic.php?t=925275

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


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.