-->
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: Converting string property to sql type date
PostPosted: Wed Apr 11, 2007 5:54 am 
Newbie

Joined: Wed Apr 11, 2007 5:34 am
Posts: 2
Hi,

I have a domain object which has a date property "birthDate" but the type of this property is String.

class PersonInfo{
String birthDate;

.....

}

In my hbm file i have following mapping

<class name="PersonInfo"..>

<property name="birthDate" type="string" >
<column name="BirthDate" sql-type="date" />
</property>

....
</class>


Here i want hibernate to parse the given date string and store into database. Is this possible?

when i enter a date string in the mm\dd\yyyy format its not able to parse the string and stores 0000-00-00 00:00:00 in the database. Is there a way to specify the date format in hibernate?

How to convert a date string to sql-type date in hibernate?


Thanx
Rupali


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 11, 2007 6:21 am 
Expert
Expert

Joined: Tue Jan 30, 2007 12:45 am
Posts: 283
Location: India
Hi Rupali,

Try

in PersonInfo class you should have property Date birthDate.

<class name="PersonInfo"..>

<property name="birthDate" type="date" column="BirthDate" />
</property>

....
</class>


If you have constrain that you can only pass String then in setter of that you can write a code to convert it to Date and assign to birthDate.

_________________
Dharmendra Pandey


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.