I have this .hbm.xml file :
Evenement.hbm.xml :
<hibernate-mapping package="com.af.evenement">
<class name="Evenement" table="TB_EVENEMENT">
<id name="id" type="string" column="CODE_EVENEMENT">
<generator class="assigned" />
</id>
<set name="causesAnnexes">
<key column="CODE_EVENEMENT" />
<one-t开发者_开发问答o-many class="CausesAnnexesEvt" />
</set>
........
and I've got this other .hbm.xml file : CausesAnnexesEvt :
<class name="CausesAnnexesEvt" table="TB_CAUSESANNEXES_EVT">
<composite-id name="id" class="CausesAnnexesEvtPK">
<key-many-to-one
class="Evenement"
column="CODE_EVENEMENT"
name="Evenement"
/>
<key-many-to-one
class="Cause"
column="CODE_CAUSE"
name=cause"
/>
</composite-id>
</class>
when I try to delete an Evenement object with this line of code :
Session s=getCurrentSession();
tx=s.beginTransaction();
s.delete(evenement);
s.flush();
s.clear();
when I run the above code, I get the following exception :
QueryException : could not resolve property : causesAnnexesEvt.
Hibernate looks for a field called causesAnnexesEvt
in your class Evenement
but it can't find it. Make sure the field in the class and the column definition in the hbm.xml use the same name.
The exception shown is not thrown by session.delete(). Either you haven't shown us the complete code (stack trace would be helpful, btw) OR it's thrown during session factory initialization (invoked from within getCurrentSession()
?) because one of your named queries can't be parsed.
So while Aaron is right about missing causesAnnexesEvt
property being the cause of this exception there's absolutely nothing in your post suggesting that it should be a property of Evenement
. Search all your named queries for causesAnnexesEvt
and see which one references it and which entity it's looking to get it from.
精彩评论