user2093904
user2093904

Reputation: 33

Hibernate not saving collection

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC  "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-   mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.business.Test" table="Test">
    <composite-id name="key">
        <key-property name="x" column="X"/>
        <key-property name="y" column="Y"/>
    </composite-id>

    <set name="valueObjects" inverse="false" lazy="false" cascade="all">
        <key>
            <column name="X"/>
            <column name="Y"/>          
        </key>
        <one-to-many class="com.business.ValueObjects" />
    </set>

</class>
</hibernate-mapping>




<?xml version="1.0"?>

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

<hibernate-mapping>
<class name="com.business.ValueObjects" table="ValueObjects" mutable="false">
    <id name="id" type="java.lang.Long" column="ID">
      <generator class="sequence">
          <param name="sequence">ID_SEQ</param>
      </generator>
    </id>

    <property name="x" column="X"/>
    <property name="y" column="Y"/>

</class>
</hibernate-mapping>

When i load the Test object, hibernate loads the ValueObjects collections. But when i update the ValueObjects and save Test. I dont see any insert or Update statements.

PLease suggest what to do.

Raulito

Upvotes: 1

Views: 687

Answers (1)

Chakri Chakradhar
Chakri Chakradhar

Reputation: 166

In hibernate, ‘mutable‘ is default to ‘true’ in class and its related collection, it mean the class or collection are allow to add, update and delete. On the other hand, if the mutable is changed to false, it has different meaning in class and its related collection. So You need to remove mutable attribute and set inverse attribute to true.

Upvotes: 2

Related Questions