can auto save "Set" property when saving a object?
for example:
Set authorities = new CopyOnWriteArraySet();
for (int i=0; i<model.getRoles().length; i++) {
AuthoritiesId authoritiesId = new AuthoritiesId();
authoritiesId.setUserDetails(userDetails);
authoritiesId.setRoleDefiniens(roleDefiniensDao.loadByPrimaryKey(model.getRoles()[i]));
Authorities authority = new Authorities(authoritiesId);
authorities.add(authority);
}
userDetails.setSetOfAuthorities(authorities);
session.save(userDetails);
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping
DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<!--
Auto-generated mapping file from
the hibernate.org cfg2hbm engine
-->
<class name="demos.UserDetails"
table="KYDA_USER_DETAILS">
<id name="relId" type="java.lang.Integer">
<column name="REL_ID" not-null="true" unique="true"
sql-type="INTEGER" />
<generator class="native">
<param name="sequence">kyda_user_details_rel_id</param>
</generator>
</id>
<property name="username" type="java.lang.String">
<column name="USERNAME" length="50" not-null="true"
unique="true" sql-type="VARCHAR" />
</property>
<property name="realname" type="java.lang.String">
<column name="REALNAME" length="50" not-null="true"
sql-type="VARCHAR" />
</property>
<property name="password" type="java.lang.String">
<column name="PASSWORD" length="50" not-null="true"
sql-type="VARCHAR" />
</property>
<property name="accountNonExpired" type="java.lang.Boolean">
<column name="ACCOUNT_NON_EXPIRED" not-null="true"
sql-type="BOOLEAN" />
</property>
<property name="credentialsNonExpired" type="java.lang.Boolean">
<column name="CREDENTIALS_NON_EXPIRED" not-null="true"
sql-type="BOOLEAN" />
</property>
<property name="accountNonLocked" type="java.lang.Boolean">
<column name="ACCOUNT_NON_LOCKED" not-null="true"
sql-type="BOOLEAN" />
</property>
<property name="enabled" type="java.lang.Boolean">
<column name="ENABLED" not-null="true" sql-type="BOOLEAN" />
</property>
<!--
<property name="authorities" type="java.lang.String">
<column name="AUTHORITIES" length="1024" not-null="true"
sql-type="VARCHAR" />
</property>
-->
<set name="setOfUserGroupRelation">
<key>
<column name="USER_REL_ID" not-null="false"
unique="true" />
</key>
<one-to-many
class="demos.UserGroupRelation" />
</set>
<set name="setOfAuthorities">
<key>
<column name="REL_ID" not-null="false" unique="true" />
</key>
<one-to-many
class="demos.Authorities" />
</set>
</class>
</hibernate-mapping>