-->
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: Criteria - SqlRestriction - no property/column conversion
PostPosted: Fri Sep 16, 2005 4:44 am 
Regular
Regular

Joined: Tue Oct 07, 2003 1:13 pm
Posts: 70
Location: Paris, France
Hibernate version: 3.1

Mapping documents:
<property name="postalCode" column="postal_code" ...>

Code between sessionFactory.openSession() and session.close():

Criteria crit = s.createCriteria(Person.class)
.setProjection( Projections.rowCount())
.add(Restrictions.or(
Restrictions.isNull("b.postalCode"),
Restrictions.sqlRestriction("length({alias}.postalCode)=?",0,Hibernate.INTEGER)
));

I'd like to know if it is considered as expected that the generated sql is :

Hibernate: select count(*) as y0_ from person this_ where (this_.postal_code is null or length(this_.postalCode)=?)

If it is, is there a way to force Hibernate to translate the property to the actual column name ?

BTW, a Criteria.setReadonly(boolean) a la Query would be really appreciated.
Thank you for your help
Richard


Top
 Profile  
 
 Post subject: sql
PostPosted: Mon Sep 19, 2005 1:35 pm 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
Code:
Restrictions.sqlRestriction("length({alias}.postalCode)=?",0,Hibernate.INTEGER)


Because you have specified SQL restrictions H does not do any magic, H thinks that supplied restriction is SQL.

_________________
--------------
Konstantin

SourceLabs - dependable OpenSource systems


Top
 Profile  
 
 Post subject: Re: sql
PostPosted: Tue Sep 25, 2007 8:35 pm 
Newbie

Joined: Tue Sep 25, 2007 8:29 pm
Posts: 1
How would you use hibernate to map the propertyname into the column name?

kgignatyev wrote:
Code:
Restrictions.sqlRestriction("length({alias}.postalCode)=?",0,Hibernate.INTEGER)


Because you have specified SQL restrictions H does not do any magic, H thinks that supplied restriction is SQL.


Top
 Profile  
 
 Post subject: Re: Criteria - SqlRestriction - no property/column conversion
PostPosted: Mon Jan 11, 2010 5:55 pm 
Beginner
Beginner

Joined: Wed Feb 15, 2006 2:51 pm
Posts: 20
here is my solution, I created couple new classes to convert property name to column...this can be extended....for now it does the trick...this should be part of the API

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


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.