These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: NEWBIE - flush() after SELECT causes DB updates
PostPosted: Wed Aug 16, 2006 7:00 am 
Newbie

Joined: Wed Aug 16, 2006 6:31 am
Posts: 2
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: None

Name and version of the database you are using: Sybase 15.0

The 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.


Top
 Profile  
 
 Post subject: Duh - the answer was in the FAQ's
PostPosted: Wed Aug 16, 2006 8:48 am 
Newbie

Joined: Wed Aug 16, 2006 6:31 am
Posts: 2
I re-read the FAQs and found the solution to my problem.

It's titled "Hibernate keeps deleting and recreating my collection".

My parent class (HistoricalNote) was returning a collection from getNoteItems() that was not object-identical to setNoteItems(..). Once I'd changed that, my flush() call no longer caused a database update.

Note to self: read FAQs more carefully.....


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.