The following mapping doesn't result in save operations cascading to the associated set of Role objects.
To be clear, I'm expecting it to mark the new Role as persisted and assign it an ID even before I call session.close(). I believe this is the expected behavior.
This fails both for already-created objects (save) and pre-existing objects (update). My Dao doesn't distinguish, it calls session.saveOrUpdate(obj).
-Kevin
Hibernate version:
3.1.rc3
Mapping documents:
<hibernate-mapping package="net.speakeasy.domain.account"
schema="moses">
<class name="User" table="userids">
<id name="id" column="userid_id">
<generator class="sequence">
<param name="sequence">userids_gen</param>
</generator>
</id>
<property name="name" column="userid" />
<property name="status" column="status" type="Status" />
<many-to-one name="customer" column="customer_id"
class="net.speakeasy.domain.account.Customer" not-null="true"
cascade="persist,merge,save-update" />
<set name="roles" table="userid_groups" cascade="all">
<key column="userid_id" />
<many-to-many class="net.speakeasy.domain.account.Role"
column="group_id" />
</set>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
testUser = TestData.getUnitTestUser(gateway);
newRole = new Role();
newRole.setDescription("UserDaoTest role");
testUser.addRole(newRole);
userDao.save(testUser);
//this assert fails
assertTrue("Session does not contain new role", getSessionFactory()
.getCurrentSession().contains(newRole));
Name and version of the database you are using:
Oracle 9i
|