-->
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.  [ 3 posts ] 
Author Message
 Post subject: HQL NOT IN Syntax Problem w/MySQL
PostPosted: Wed Jun 30, 2004 3:44 pm 
Regular
Regular

Joined: Wed Dec 17, 2003 1:58 pm
Posts: 102
Query:
Code:
        Query query = session.createQuery("from cmcflex.salesweb.model.admin.UserType u " +
                                          "WHERE :userType IN elements(u.userTypesWithPermissionToAssign) " +
                                          "AND u.id NOT IN :idList ");
        query.setParameter("userType", userType);
        query.setParameterList("idList", theform.getUserTypesWithPermissionToAssignChosen());


theform.getUserTypesWithPermissionToAssignChosen() returns an arrayList of String[] type containing the id's.


Generated Code and Error:
Code:
Hibernate: select usertype0_.id as id, usertype0_.description as descript2_, usertype0_.name as name, usertype0_.rootPath as rootPath, usertype0_.userClassName as userClas5_ from adminUserType usertype0_ where (? IN(select usertypesw1_.userType2_id from adminUserType_UserType usertypesw1_ where usertype0_.id=usertypesw1_.userType_id))AND(usertype0_.id NOT IN ? , ? , ? )
59328 [http-80-Processor24] ERROR util.JDBCExceptionReporter  - Syntax error or access violation,  message from server: "You have an error in your SQL syntax.  Check the manual that corresponds to your MySQL server version for the right syntax to use near '33 , 20 , 28 )' at line 1"
59328 [http-80-Processor24] ERROR util.JDBCExceptionReporter  - Syntax error or access violation,  message from server: "You have an error in your SQL syntax.  Check the manual that corresponds to your MySQL server version for the right syntax to use near '33 , 20 , 28 )' at line 1"
59343 [http-80-Processor24] ERROR util.JDBCExceptionReporter  - Could not execute query
java.sql.SQLException: Syntax error or access violation,  message from server: "You have an error in your SQL syntax.  Check the manual that corresponds to your MySQL server version for the right syntax to use near '33 , 20 , 28 )' at line 1"


Mapping for UserType class:
Code:
<hibernate-mapping>
    <class name="cmcflex.salesweb.model.admin.UserType" table="adminUserType">
      <id name="id" type="long" unsaved-value="null">
           <generator class="identity"/>
        </id>
        <property name="description"/>
        <set name="roles" table="adminUserType_Role" lazy="true">
            <key>
                <column name="userType_id" not-null="true"/>
            </key>
            <many-to-many class="cmcflex.salesweb.model.admin.Role">
                <column name="role_id" not-null="true"/>
            </many-to-many>
        </set>
        <property name="name"/>
        <property name="rootPath"/>
        <set name="users" cascade="none" lazy="true" inverse="true">
         <key column="userType_id"/>
         <one-to-many class="cmcflex.salesweb.model.admin.User"/>
        </set>
        <set name="userTypesWithPermissionToAssign" table="adminUserType_UserType" lazy="true" sort="cmcflex.salesweb.model.admin.UserTypeNameComparator">
            <key>
                <column name="userType_id" not-null="true"/>
            </key>
            <many-to-many class="cmcflex.salesweb.model.admin.UserType">
                <column name="userType2_id" not-null="true"/>
            </many-to-many>
        </set>
        <property name="userClassName"/>
    </class>

</hibernate-mapping>


It appears that hibernate SHOULD be wrapping the id's specified for the NOT IN statement with parenthesis but its not happening.. ie NOT IN ('12', 13', '14') I'm using Hibernate 2.1. Any ideas?

I also found that if I executed the above query without adding a space at the end I was getting char replacement exceptions.. very odd.

Thanks in advance,
David


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 30, 2004 4:04 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
use (:something) like specified in the manual at http://www.hibernate.org/hib_docs/reference/en/html/manipulatingdata.html#manipulatingdata-queryinterface - besides, elements() is implementd using subselects, which most mysql versions don't support.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 30, 2004 4:43 pm 
Regular
Regular

Joined: Wed Dec 17, 2003 1:58 pm
Posts: 102
Bingo, thanks Michael, as always fantastic help from the pros =)
-David


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