-->
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: Problem with dates when parsing a XML file
PostPosted: Wed Nov 02, 2005 6:01 pm 
Newbie

Joined: Mon Oct 24, 2005 9:16 am
Posts: 7
I'm getting a parse error when parsing a date from a XML file. I'm using entitymode.dom4j to load tables. The mapping file specify a date type. If i change it for string, no error is generated.

Code:
Hibernate: insert into agegroup (lowend, highend, name) values (?, ?, ?)
<Period id="1">
      <startdate>2005-5-5</startdate>
      <enddate/>
      <name>High Season</name>
      
   </Period>
Exception in thread "main" org.hibernate.HibernateException: could not parse XML
   at org.hibernate.type.DateType.fromStringValue(DateType.java:95)
   at org.hibernate.type.CalendarDateType.fromStringValue(CalendarDateType.java:54)
   at org.hibernate.type.NullableType.fromXMLString(NullableType.java:102)
   at org.hibernate.type.NullableType.fromXMLNode(NullableType.java:126)
   at org.hibernate.property.Dom4jAccessor$ElementGetter.get(Dom4jAccessor.java:192)
   at org.hibernate.property.Dom4jAccessor$Dom4jGetter.getForInsert(Dom4jAccessor.java:93)
   at org.hibernate.tuple.AbstractTuplizer.getPropertyValuesToInsert(AbstractTuplizer.java:189)
   at org.hibernate.persister.entity.BasicEntityPersister.getPropertyValuesToInsert(BasicEntityPersister.java:3005)
   at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:216)
   at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:160)
   at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:95)
   at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:184)
   at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:33)
   at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:173)
   at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:27)
   at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:69)
   at org.hibernate.impl.SessionImpl.save(SessionImpl.java:481)
   at com.optionaltours.util.TourLoader.recurLoadXml(TourLoader.java:74)
   at com.optionaltours.util.TourLoader.recurLoadXml(TourLoader.java:71)
   at com.optionaltours.util.TourLoader.loadDatabaseFromXml(TourLoader.java:56)
   at com.optionaltours.util.TourLoader.main(TourLoader.java:33)
Caused by: java.text.ParseException: Unparseable date: "2005-5-5"
   at java.text.DateFormat.parse(DateFormat.java:335)
   at org.hibernate.type.DateType.fromStringValue(DateType.java:92)
   ... 20 more


Top
 Profile  
 
 Post subject: See java.text.SimpleDateFormat
PostPosted: Wed Nov 02, 2005 6:11 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
As the exception says, this is a parse problem in SimpleDateFormat. Hibernate's DateType uses new SimpleDateFormat().parse(<yourdate>) to parse the date, so if you want to use a custom format like "yyyy-MM-dd", you'll have to set up your own usertype for it.

Alternatively you could use a format that SimpleDateFormat() (default constructor) handles. This is dependent on your locale. See the javadocs of SimpleDateFormat for more specifics.

If (almost) all your dates throughout your application are in the same format, then probably the best solution is to configure your locale. That's not a hibernate solution; see a more general java forum to learn how to do that.


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.