Hi, All:
I tried to do some bulk operations without using the cache. But I found very simple updates cannot be handled by Hibernate 3 if the composite ID is used.
Below is my mapping file for the table:
<hibernate-mapping>
<class name="Entityoid" table="ENTITYOID" >
[b] <composite-id name="comp_id" class="EntityoidPK">
<key-property name="idType" column="ID_TYPE" type="java.lang.String" length="16" />
<key-property name="entityoid" column="ENTITYOID" type="java.lang.Long" length="10" />
</composite-id> [/b]
<property name="description" type="java.lang.String" column="DESCRIPTION" length="512" />
...
</class>
</hibernate-mapping>
And here's my simple update:
... //create session
Transaction trans = session.beginTransaction();
try{
String hqlUpdate = "update Entityoid set description=:newDesc " +
"where comp_id.idType= :type and" +
" comp_id.entityoid = :entityOID" ;
int updatedEntities =
session.createQuery( hqlUpdate)
.setString("newDesc", newDesc)
.setString("type", type)
.setLong("entityOID", entityOID)
.executeUpdate();
trans.commit();
}
The database I used is Oracle10g. And here's what I got:
Hibernate: update ENTITYOID set DESCRIPTION=? where entit0_.ID_TYPE=? and entit0_.ENTITYOID=?
- SQL Error: 904, SQLState: 42000
- ORA-00904: "ENTIT0_"."ENTITYOID": invalid identifier
org.hibernate.exception.SQLGrammarException: could not execute update query
It seems Hibernate translates comp_id incorrectly to get this error. If I don't use any comp_id field in the update, then it runs fine.
Is this a Hibernate bug?
Thanks!
|