When I create a new object, then persist it, the array is not saved; however if I update it after it has been created, the array is saved. I have cascade set to "all", and it is performing the insert statements, but parent_id is being set to 0. The id attribute of MyObject defaults to undefined when a new instance is created and I have a generator set up for when it is stored in the database
Hibernate version:
3.0
Mapping documents:
This array is inside of another object.
Code:
<hibernate-mapping>
<class name="MyObject" table="table1">
<id name="id" type="int">
<column name="id" not-null="true" unique-key="true"/>
<generator class="assigned"/>
</id>
<array name="variable" cascade="all" table="table2">
<key foreign-key="true" column="parent_id" unique="false" not-null="true" />
<list-index column="idx" />
<element column="array_column" type="string" not-null="true" />
</array>
</class>
</hibernate-mapping>
Code that persists/updates object:I use spring's HibernateTemplate:
Code:
MyObject object = new MyObject({"a", "b", "c"}); //array passed to constructor
getHibernateTemplate().saveOrUpdate(object);
Name and version of the database you are using:MySQL
The generated SQL (show_sql=true):This is what I get when I try to insert the new object containing the array:
Code:
Hibernate: insert into table1 (col1, col2, col3, col4) values (?, ?, ?, ?)
Hibernate: insert into table2 (parent_id, idx, array_column) values (?, ?, ?)
Hibernate: insert into table2 (parent_id, idx, array_column) values (?, ?, ?)
Hibernate: insert into table2 (parent_id, idx, array_column) values (?, ?, ?)