I want do bulk delete and use many-to-one property in where-clause:
mycode:
Code:
String sql = "delete User where group.id=100";
session.createQuery(sql).executeUpdate();
result, hibernate generated SQL:
Code:
delete from ums_user where user0_.id=100
and throw exception:
Code:
(Hibernate operation): encountered SQLException [General error, message from server: "Unknown table 'user0_' in where clause"]; nested exception is java.sql.SQLException: General error, message from server: "Unknown table 'user0_' in where clause"
My Hibernate version:hibernate3.0.1,hibernate3.0.3
part of my Mapping documents:
Code:
<hibernate-mapping>
<class name="example.entity.User" dynamic-update="false"
dynamic-insert="false" table="ums_user" >
<id name="id" column="id" type="java.lang.Long" unsaved-value="null">
<generator class="native"></generator>
</id>
<property name="name" type="java.lang.String" column="name" />
<many-to-one name="group" column="group_id"/>
</class>
</hibernate-mapping>
<hibernate-mapping>
<class name="example.entity.Group" dynamic-update="false"
dynamic-insert="false" table="ums_group" lazy="false">
<id name="id" column="id" type="java.lang.Long" unsaved-value="null">
<generator class="native"></generator>
</id>
<property name="name" type="java.lang.String" column="name" />
</class>
</hibernate-mapping>
though i can complete this bulk delete in this way:
my code:
Code:
String sql = "delete User where group_id=100";
session.createQuery(sql).executeUpdate();
hibernate generated SQL:
Code:
delete from ums_user where group_id=100
but, it's not HQL.