-->
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: problems with sqlRestrictions and alias
PostPosted: Tue Sep 19, 2006 6:58 am 
Newbie

Joined: Tue Sep 19, 2006 6:47 am
Posts: 15
Hi everybody,

I try to use sqlRestrictions but have a problem using it with an alias table. In fact I use several aliases in my criterion. It seems to me that {alias} is replaced by the first alias table name that is found and I don't know how to give the name of my alias table.

Hibernate version: 3.1.3

Full stack trace of any exception that occurs:
Code:
org.springframework.jdbc.BadSqlGrammarException: Hibernate operation: could not execute query; bad SQL grammar [

select ...
from bo_DocumentContainer this_ inner join bo_Order this_1_ on this_.id=this_1_.documentContainer_ref inner join bo_CustomerOrder this_2_ on this_.id=this_2_.order_ref inner join set_OrderRole roles4_ on this_.id=roles4_.order_ref inner join bo_Role role1_ on roles4_.role_ref=role1_.id left outer join bo_AccountingRole role1_1_ on role1_.id=role1_1_.role_ref inner join bo_DocumentContainer customer2_ on role1_.associate_ref=customer2_.id left outer join bo_Associate customer2_1_ on customer2_.id=customer2_1_.documentContainer_ref left outer join bo_Party customer2_2_ on customer2_.id=customer2_2_.associate_ref left outer join bo_Person customer2_3_ on customer2_.id=customer2_3_.party_ref left outer join bo_System customer2_4_ on customer2_.id=customer2_4_.person_ref left outer join bo_Group customer2_5_ on customer2_.id=customer2_5_.party_ref left outer join bo_RemoteParty customer2_6_ on customer2_.id=customer2_6_.associate_ref left outer join bo_RemotePerson customer2_7_ on customer2_.id=customer2_7_.remoteParty_ref left outer join bo_RemoteGroup customer2_8_ on customer2_.id=customer2_8_.remoteParty_ref left outer join bo_PaymentMode paymentmod7_ on this_1_.paymentMode_ref=paymentmod7_.id left outer join bo_Task translatio8_ on this_2_.task_ref=translatio8_.id

where

((role1_.type=? and (lower(customer2_1_.name) like ? or lower(customer2_3_.firstName) like ? or 'Mustermann' SOUNDS LIKE role1_.name or 'Mustermann' SOUNDS LIKE role1_.firstName))) order by this_.id desc]; nested exception is java.sql.SQLException: Unknown column 'role1_.name' in 'where clause'
java.sql.SQLException: Unknown column 'role1_.name' in 'where clause'

Name and version of the database you are using: MySql 4.1


Code snippet
Code:
roleCriteria.createAlias("associate", "customer");
                if (customerId != null) {
                    conjunction.add(Restrictions.eq("customer.id", customerId));
                }
                if (StringUtils.hasText(customerName)) {
                   
                        Disjunction nameCriterion = Restrictions.disjunction();
                        nameCriterion.add(Restrictions.ilike("customer.name",
                                customerName, MatchMode.ANYWHERE));
                        nameCriterion.add(Restrictions.ilike(
                                "customer.firstName", customerName,
                                MatchMode.ANYWHERE));
                        nameCriterion
                                .add(Restrictions.sqlRestriction("'"
                                        + customerName
                                        + "' SOUNDS LIKE {alias}.name"));
                        nameCriterion.add(Restrictions.sqlRestriction("'"
                                + customerName
                                + "' SOUNDS LIKE {alias}.firstName"));
                        conjunction.add(nameCriterion);
                }


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 25, 2006 7:45 am 
Newbie

Joined: Tue Aug 29, 2006 10:56 am
Posts: 15
Hi,
I have the same problem!


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.