Hi,
I have a Will entity that has
many-to-many Solicitors
many-to-one Executors
When I add to the collections in the Will, the new collections are persisted perfectly to the database.
e.g.
Code:
// will, solicitor and executor are all managed
will.getSolicitors().add(solicitor);
will.getExecutors().add(executor);
getEntityManager().merge(will);
...but when I remove from the collections, and merge, no update statements go to the database. The current instance of the Will is OK but when reloaded/refreshed from the database I can see that the removed solicitors and executors are loaded back into the collections.
e.g.
Code:
// will, solicitor and executor are all managed
will.getSolicitors().remove(solicitor);
will.getExecutors().remove(executor);
getEntityManager().merge(will);
I've mapped the executors and solicitors like this...
Will model
Code:
@OneToMany(fetch = FetchType.EAGER, mappedBy = "will", cascade = { CascadeType.ALL })
@Cascade( { org.hibernate.annotations.CascadeType.MERGE })
private Set<Executor> executors;
@ManyToMany(fetch = FetchType.EAGER, mappedBy = "wills", cascade = { CascadeType.ALL })
@Cascade( { org.hibernate.annotations.CascadeType.SAVE_UPDATE })
private List<Solicitor> solicitors;
Note I've tried Set,List and numerous variations on Cascade to see if that makes any difference.
Executor
Code:
@ManyToOne(optional = true, cascade = { CascadeType.ALL })
@Cascade( { org.hibernate.annotations.CascadeType.MERGE })
private Will will;
Solicitor
Code:
@ManyToMany(fetch=FetchType.EAGER, cascade = { CascadeType.ALL })
private List<Will> wills;
Thanks for any help.
Tim
Hibernate version: 3.2 Spring 2.0PostgreSQL 8.3Code:
<bean id="dataSource"
class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close">
<property name="driverClass" value="${jdbc.driver}" />
<property name="jdbcUrl" value="${jdbc.url}" />
<property name="user" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
</bean>
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="jpaVendorAdapter">
<bean
class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="showSql" value="${jdbc.show_sql}" />
<property name="generateDdl" value="${update.schema}" />
<property name="databasePlatform"
value="${jdbc.dialect}" />
</bean>
</property>
</bean>
<bean id="transactionManager"
class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory"
ref="entityManagerFactory" />
<property name="dataSource" ref="dataSource" />
</bean>
<tx:annotation-driven />