-->
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: Updating Obj in Set of 1 to Many not updating
PostPosted: Thu Aug 21, 2008 5:03 pm 
Newbie

Joined: Thu Aug 21, 2008 4:33 pm
Posts: 2
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 313

I have 2 simple Entity tables.

TableA:
id (PK)
name

Table B:
id (PK)
data bytes[]
afk (FK) FK to Table A.

I have them both mapped as entities and there is a 1 to many from A to B.

I create A, then create B, then add B to A and persist. There is a cascade from A to B. This works great.


Problem is here:
In a later unit of work, I retrieve A, iterate over set, update the data bytes[] in this example with new data and save A.

Problem is the data never gets persisted. If I retrieve A, and loop around the set and look at the data bytes[], the data was what was originally put into the column. It never gets updated.

So I have a set of entities, that have cascades set, I update the data, and persist, but data does not get updated.

Mappings:
a, then B
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >

<hibernate-mapping>

    <class name="comppfi"
    table="FILE">
        <id name="Id" type="long" column="FILE_ID">
            <generator class="sequence">
                <param name="sequence">FILE_SEQ</param>
            </generator>
        </id>

        <set
            name="myBs"
            cascade="save-update"
        >
            <key column="x_FILE_ID" />
            <one-to-many class="com.BBBB"/> 
        </set> 
       
 
</hibernate-mapping>



<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >

<hibernate-mapping>
    <class
        name="PaymentProcessFileDataImpl"
        dynamic-insert="true"
        dynamic-update="true"
        table="FILE_DATA">
        <id name="id" type="long"
            column="DATA_ID">
            <generator class="sequence">
                <param name="sequence">DATA_ID_SEQ</param>
            </generator>
        </id>
       
        <property
            name="mydata"
            column="MY_DATA"
            type="blob"
            not-null="true" />

         
        <many-to-one
            name="myBBBB"
            class="com.BBBB"
        >
            <column name="x_FILE_ID"
                not-null="true" />
        </many-to-one>
           
    </class>
   
</hibernate-mapping>




Workflow is, create A, add B, persist A, using Transitive persistance have B saved. This works great.

Later on, fetch A, update B and persist A. B is not getting updated.

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 22, 2008 8:14 am 
Regular
Regular

Joined: Wed Jan 11, 2006 12:49 pm
Posts: 64
Location: Campinas, Brazil
Hi,

Your basic logic seems OK, but I one expression stands out here:
Quote:
Later on, fetch A, update B and persist A. B is not getting updated.


Hibernate (and more recently JPA in general) works by checking for changes in attached objects. So if you fetch A and update B (by calling B's setter methods), you should only call flush() on your Session or EntityManager.

Try showing the SQL queries and check the result of flushing right after updating B's attributes. You should see some update query on B's table.

Besides, cascading would be negatively affected if you set a new collection to the one-to-many property of A.

Show us some code if this does not clear up things, ok?

_________________
Henrique Sousa
Don't forget to rate useful responses


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.