-->
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.  [ 4 posts ] 
Author Message
 Post subject: Joda DateTime mapping
PostPosted: Tue Jun 22, 2010 5:15 pm 
Pro
Pro

Joined: Mon Apr 16, 2007 8:10 am
Posts: 246
Hello,

I have a domain class property being a Joda DateTime that gives me an exception when running an integration test against an in memory hsqldb database.

Here is the exception
Code:
Hibernate:
    select
        this_.id as id69_0_,
        this_.version as version69_0_,
        this_.address_id as address3_69_0_,
        this_.firstname as firstname69_0_,
        this_.lastname as lastname69_0_,
        this_.company as company69_0_,
        this_.email as email69_0_,
        this_.fax as fax69_0_,
        this_.home_phone as home9_69_0_,
        this_.work_phone as work10_69_0_,
        this_.mobile_phone as mobile11_69_0_,
        this_.password as password69_0_,
        this_.password_salt as password13_69_0_,
        this_.readable_password as readable14_69_0_,
        this_.valid_until as valid15_69_0_,
        this_.profile as profile69_0_,
        this_.image as image69_0_,
        this_.mail_subscribe as mail18_69_0_,
        this_.sms_subscribe as sms19_69_0_,
        this_.creation_datetime as creation20_69_0_
    from
        user this_
    where
        this_.valid_until<>?
        and this_.valid_until<?
    order by
        this_.firstname asc,
        this_.lastname asc
23:03:45,230  INFO TransactionalTestExecutionListener:279 - Rolled back transaction after test execution for test context [[TestContext@1d6c336 testClass = UserDaoTest, locations = array<String>['classpath:spring-hibernate.xml', 'classpath:spring-hibernate-dao.xml', 'classpath:spring-data-source.xml'], testInstance = core.dao.UserDaoTest@80669d, testMethod = testFindNotValid@UserDaoTest, testException = java.lang.ClassCastException: java.lang.String cannot be cast to org.joda.time.DateTime]]


The domain class
Code:
   
import org.joda.time.DateTime;
...
   private DateTime validUntil;

   public DateTime getValidUntil() {
      return this.validUntil;
   }

   public void setValidUntil(DateTime validUntil) {
      this.validUntil = validUntil;
   }


The mapping
Code:
<property name="validUntil" type="org.joda.time.contrib.hibernate.PersistentDateTime">
   <column name="valid_until" not-null="false" />
</property>


The Dao method
Code:
   public List<User> findValidTemporarily(DateTime dateTime) {
      Criteria criteria = getSession().createCriteria(User.class);
      criteria.add(Restrictions.ne("validUntil", "")).add(Restrictions.ge("validUntil", dateTime)).addOrder(Order.asc("firstname")).addOrder(Order.asc("lastname"));
      return criteria.list();
   }


And the test
Code:
   @Test
   public void testFindNotValid() {
      user0 = userDao.makePersistent(user0);
      user1 = userDao.makePersistent(user1);
      DateTime today = new DateTime();
      List<User> users = userDao.findNotValid(today.toDateTime());
      assertEquals(1, users.size());
      assertEquals(email0, users.get(0).getEmail());
   }


Top
 Profile  
 
 Post subject: Re: Joda DateTime mapping
PostPosted: Wed Jun 23, 2010 12:12 am 
Pro
Pro

Joined: Mon Apr 16, 2007 8:10 am
Posts: 246
The problem was that I was using the following Criteria Restriction in the find... Dao method

.add(Restrictions.ne("validUntil", ""))

Now I wonder how to check that a date is set...


Top
 Profile  
 
 Post subject: Re: Joda DateTime mapping
PostPosted: Wed Jun 23, 2010 2:42 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
What about Restrictions.isNotNull("validUntil") ?


Top
 Profile  
 
 Post subject: Re: Joda DateTime mapping
PostPosted: Wed Jun 23, 2010 2:56 am 
Pro
Pro

Joined: Mon Apr 16, 2007 8:10 am
Posts: 246
Hej Nordborg,

Thanks for the reply.

I posted a full request at viewtopic.php?f=1&t=1005394

Kind Regards,

Stephane


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