-->
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: Using property name with a SQL scalar function
PostPosted: Mon Mar 27, 2006 9:46 am 
Newbie

Joined: Mon Mar 27, 2006 9:38 am
Posts: 4
I am using Hibernat 3.1.3 with MySQL 5.0.19.

I have a class ChangeHistory that has a property actionTime of type timestamp. I want to use the Criteria facility to add an equality restriction on actionTime for a Date (not Timestamp). The native SQL would be:

select * from change_history where date(action_time) = '2005-11-30'.

How do I express this using the Criteria API? I am using DetachedCriteria.

Thanks,
Vidur


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 27, 2006 10:21 am 
Expert
Expert

Joined: Sat Oct 25, 2003 8:49 am
Posts: 490
Location: Vrhnika, Slovenia
Write your own UserType.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 27, 2006 11:11 am 
Newbie

Joined: Mon Mar 27, 2006 9:38 am
Posts: 4
Not sure I understand the solution. Do I need to write a custom UserType for each function that I need to call? If that's the case, then how would one use the same property with different functions?

I was hoping the solution would be something simpler such as Restrictions.sqlRestriction ("date(changeHistory.actionTime) = ?") which doesn't work as the changeHistory.actionTime is not translated to the column name.

Thanks,
Vidur


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 27, 2006 11:25 am 
Expert
Expert

Joined: Sat Oct 25, 2003 8:49 am
Posts: 490
Location: Vrhnika, Slovenia
What exactly are you trying to do?
And where is the problem?

With Restrictions.sqlRestriction you probably have to assign alias.


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.