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