-->
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: Mapping Calendars and Dates
PostPosted: Tue Feb 08, 2005 7:44 am 
Newbie

Joined: Mon Feb 07, 2005 8:36 am
Posts: 2
Location: Cambridge, UK
Our applications make extensive use of date fields that may or may not be set, meaning that whatever the date is for might not yet have happened. That a particular date field is unset, or void, can have important business significance. For this reason we have preferred using Calendar to represent dates as, amongst other things, we can use its clear() method to make it unset. Then in our own DAO's we can test the Calendar date with isTimeSet() and either write a null or a TimeStamp to the database accordingly.

However my intial experiments using Hibernate 2 suggest that when you save a Calendar object that is in an unset state, a zero is written to the database presumably becasue the Calendar.clear() method actually sets the time to zero. As a result when the Calendar object is subsequently reloaded it is set to midnight 1st January 1970 and this will not do at all.

As a relative newbie to Hibernate, I am hoping that there are more experienced members of the community who have found solutions to this problem and can advise on:

1. If I am missing a mapping technique that enables unset Calendar obejcts to written as nulls rather than zero's and visa-versa on reload

2. If not, then has anyone found an elegant way to represent dates such that an unset date is represented as a null in the DB, but as an unset Calendar in the object model?

Thank you all for any comments on this.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 08, 2005 7:50 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
UserType


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 10, 2005 7:56 am 
Newbie

Joined: Mon Feb 07, 2005 8:36 am
Posts: 2
Location: Cambridge, UK
Ah Ha - reading the section on UserType in chapter 6, I see we can easily accomplish what we need to here. I hadn't really twigged the significance of this construct.

Thanks Gavin.


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.