-->
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.  [ 7 posts ] 
Author Message
 Post subject: Criteria on transient field?
PostPosted: Wed Jul 02, 2008 11:54 am 
Newbie

Joined: Wed Jul 02, 2008 11:36 am
Posts: 6
I have agenda items with a date, and want to group these agenda items by week number, derived from their date. The date corresponds to a field in the database, the derived week number is annoted @Transient.

The list method of my Criteria throws a QueryException: could not resolve property: week of my.package.Agenda. Is there anything specific to be configured for transient fields? What am I overlooking here?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 08, 2008 1:32 pm 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Hi,

@Transient fields are not persisted into the database hence I believe you cannot use a criteria on this field. The sort by functionality tries to write a sql query adding a 'order by' clause. Ordering occurs in the db.

In your case I would recommend to have a look at the @Sort annotation together with a custom comparator.

Alternatively you could try using a SQL function. Provided that you have a function which returns the week number given the date it should work as well. See http://www.hibernate.org/hib_docs/v3/reference/en/html_single/#queryhql-ordering.

--Hardy


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 08, 2008 7:14 pm 
Newbie

Joined: Wed Jul 02, 2008 11:36 am
Posts: 6
Correct me if I'm wrong, but I don't think I can use the sql date functions in criteria...


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 09, 2008 4:00 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
That will depend on your underlying database. If you db allows to have functions in the order by clause it should work.

You would have to give it a go.

--Hardy


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 09, 2008 5:28 am 
Newbie

Joined: Wed Jul 02, 2008 11:36 am
Posts: 6
I had already tried it without success. It looks like Hibernate only supports those constructs which are more or less standard sql, anything specific for the underlying database is not supported.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 09, 2008 5:52 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Hi,

I actually expected that Hibernate is passing the function call through without any modifications.

Have you tried to turn on sql debug trace? This way you can see which queries get executed against the db.

--Hardy


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 09, 2008 6:08 am 
Newbie

Joined: Wed Jul 02, 2008 11:36 am
Posts: 6
I don't think my criteria are translated into an sql query at all (Hibernate generates an error before actually accessing the database). I'll generate some more specific info, if you want...


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