Hi,
I've got a parent/child relationship between classes HistoricalNote and NoteItem. My problem is that when I do a "select all" on HistoricalNote, I see the NoteItem table not only being selected (fine), but then subsequently updated (not fine). See the SQL trace below - it looks like the foreign key field is being nulled then set again.
This update happens when I flush my session. Is there a way to avoid this behaviour? I haven't changed anything in my objects so I don't know why Hibernate thinks it needs to update the database.
Thanks in advance,
Phil
Hibernate version: 3.1.2
Mapping documents:
Code:
<hibernate-mapping>
<class
name="com.iris.citigroup.cube.csl.service.historicalnote.NoteItem"
dynamic-update="false"
dynamic-insert="false"
>
<id
name="id"
column="id"
type="java.lang.Long"
>
<generator class="native">
</generator>
</id>
<many-to-one
name="historicalNote"
class="com.iris.citigroup.cube.csl.service.historicalnote.HistoricalNote"
cascade="none"
outer-join="auto"
update="false"
insert="false"
access="property"
column="historicalnote_id"
/>
<property
name="type"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="type"
/>
<property
name="text"
type="java.lang.String"
update="true"
insert="true"
access="property"
>
<column
name="text"
length="4000"
/>
</property>
<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-NoteItem.xml
containing the additional properties and place it in your merge dir.
-->
</class>
</hibernate-mapping>
<hibernate-mapping>
<class
name="com.iris.citigroup.cube.csl.service.historicalnote.HistoricalNote"
dynamic-update="false"
dynamic-insert="false"
>
<id
name="id"
column="id"
type="java.lang.String"
length="150"
>
<generator class="assigned">
</generator>
</id>
<property
name="date"
type="com.iris.csl.jdbc.hibernate.type.IDateType"
update="true"
insert="true"
access="property"
>
<column
name="date"
/>
</property>
<property
name="authorId"
type="java.lang.String"
update="true"
insert="true"
access="property"
>
<column
name="authorId"
/>
</property>
<property
name="instrumentUri"
type="com.iris.csl.jdbc.hibernate.type.ResolvableUriType"
update="true"
insert="true"
access="property"
>
<column
name="instrumentUri"
/>
</property>
<array
name="noteItems"
inverse="false"
cascade="all"
>
<key
column="historicalnote_id"
>
</key>
<index
column="noteitem_order"
/>
<one-to-many
class="com.iris.citigroup.cube.csl.service.historicalnote.NoteItem"
/>
</array>
<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-HistoricalNote.xml
containing the additional properties and place it in your merge dir.
-->
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
Code:
tranxHelper.getTransactionManager().begin();
Criteria criteria = session.createCriteria(HistoricalNote.class);
List historicalNotes = criteria.list();
session.flush();
tranxHelper.getTransactionManager().commit();
Full stack trace of any exception that occurs: NoneName and version of the database you are using: Sybase 15.0The generated SQL (show_sql=true):
Code:
Hibernate: select this_.id as id16_0_, this_.date as date16_0_, this_.authorId as authorId16_0_, this_.instrumentUri as instrume4_16_0_ from Hist
oricalNote this_
Hibernate: select noteitems0_.historicalnote_id as historic2_1_, noteitems0_.id as id1_, noteitems0_.noteitem_order as noteitem5_1_, noteitems0_.
id as id17_0_, noteitems0_.historicalnote_id as historic2_17_0_, noteitems0_.type as type17_0_, noteitems0_.text as text17_0_ from NoteItem notei
tems0_ where noteitems0_.historicalnote_id=?
Hibernate: update NoteItem set historicalnote_id=null, noteitem_order=null where historicalnote_id=?
Hibernate: update NoteItem set historicalnote_id=?, noteitem_order=? where id=?
Debug level Hibernate log excerpt: Sorry, but I've not been able to enable this yet.