-->
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: How to create alias for property in sql restriction
PostPosted: Tue Nov 20, 2007 9:27 am 
Newbie

Joined: Tue Nov 20, 2007 8:58 am
Posts: 1
Hi everyone!

I would like to ask, if its possible to create also alias for property in sql restriction when querying with hibernate criteria.

Code:
Criteria c = this.getSession().createCriteria(Cat.class);
c.add(Restrictions.sqlRestriction("{alias}.CAT_NAME ilike ?","tom", Hibernate.STRING));


Is it also possible to create alias for column name? So the sql query depends not on database column name, the column name takes from mapping. So the query would look like :

Code:
Criteria c = this.getSession().createCriteria(Cat.class);
c.add(Restrictions.sqlRestriction("{alias}.name ilike ?","tom", Hibernate.STRING));


Property Cat.name would be mapped to column CAT_NAME

Is this possible ?

Also, I would like to ask, if it is possible to set the query object so, that it would ignore null or empty values;
So I add property with null or emty value and criteria will ignore it.
I want it because I dont want to write for every restriction null or empty value test.

Thanks a lot for your help


Top
 Profile  
 
 Post subject: Re: How to create alias for property in sql restriction
PostPosted: Mon Jan 11, 2010 5:49 pm 
Beginner
Beginner

Joined: Wed Feb 15, 2006 2:51 pm
Posts: 20
Here is my solution, I created couple new classes

hope this helps

Restrictions.sqlRestriction - extract column name from property
http://javarobski.blogspot.com/2010/01/restrictionssqlrestriction-extract.html


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.