-->
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: SQLRestriction using alias of the join Table.
PostPosted: Mon Mar 11, 2013 1:16 pm 
Newbie

Joined: Mon Mar 11, 2013 1:02 pm
Posts: 5
I want to use an alias in the SQLRestriction in the subcriteria

Criteria c1 = dao.getSession().createCriteria(Parent.class,"p")
.createCriteria("p.child", "c", Criteria.LEFT_JOIN)
.add(Restrictions.sqlRestriction("c.address ilike 'Address%'"));
print(dao, c1);

The SQL that gets generated is as follows
-----------------------------------------
select this_.id as id3_0_, this_.address as address3_0_, this_.phone as phone3_0_, this_.firstName as firstName3_0_
from
Parent this_
left outer join Child this_1_
on
this_.id=this_1_.id
where
c.address ilike 'Address%'

But I am expecting the below sql so that i can use alias in my where clause.

select this_.id as id3_0_, this_.address as address3_0_, this_.phone as phone3_0_, this_.firstName as firstName3_0_
from
Parent this_
left outer join Child c
on
this_.id=this_1_.id
where
c.address ilike 'Address%'


can someone help me with the createCriteria which can help me achieve the SQL?

Thanks a million.

-Vidhya


Top
 Profile  
 
 Post subject: Re: SQLRestriction using alias of the join Table.
PostPosted: Fri Mar 29, 2013 3:15 am 
Newbie

Joined: Mon Mar 11, 2013 1:02 pm
Posts: 5
Instead of using SQLRestriction, we resolved it by extending SimpleExpression

public class CustomSimpleExpression extends SimpleExpression{
public CustomSimpleExpression(String propertyName, Object value, String op){
super(propertyName, value, op);
}
}


public class CustomRestrictions{
public static SimpleExpression regex(String propertyName, Object value){
return new CustomSimpleExpression(propertyName, value, " ~* ");
}
}


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.