It doesn't look like onSave gets called for userxref below. Note that userxref is a composite-element used for extra cols in a many-to-many. Should onSave get called? Or must I loop thru the collection (roles) myself, knowing that if this user is new then all the UserRole's are by default new?
Jeff
Code:
roleA = new Role( new Long (1), "Role A");
roleB = new Role( new Long (2), "Role B");
user = new AppUser( new Long(100), "Jeff Boring ");
user.setEmailAddr( "jeff.boring@siemens.com");
user.setUserId( "jwboring");
user.setPassword( "password");
userxref = new UserRole("Serving as role A on project", roleA, user );
userxref.setUserId("JWB");
userxref.setTransCode("add");
user.getRoles().add( userxref );
sess.save( roleA );
sess.save( roleB );
sess.save( user );
Mapping file:
Code:
<class name="AppUser" table="AppUser" >
<id
name="userskey"
type="java.lang.Long"
unsaved-value="any"
>
<generator class="assigned" />
</id>
<property name="name" type="java.lang.String" length="20" />
<property name="emailAddr" type="java.lang.String" length="50" />
<property name="userId" type="java.lang.String" length="20" />
<property name="password" type="java.lang.String" length="20" />
<!-- bi-directional many-to-many association to Role -->
<set name="roles" lazy="false" table="UserRole" cascade="all" >
<key column="userskey" />
<composite-element class="UserRole" >
<property not-null="true" name="noteComment" type="java.lang.String" />
<property not-null="false" name="userId" type="java.lang.String" />
<property not-null="false" name="transCode" type="java.lang.String" />
<many-to-one name="role" class="Role">
<column name="roleskey" />
</many-to-one>
</composite-element>
</set>
</class>
[/code]