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