ew0kian wrote:
thanks. and how would i map the one to many from user to user_roles so i could do something like user.getRoles()?
You could do:
Code:
<hibernate-mapping>
<class name="test.model.data.User" table="Users" mutable="true" >
<id name="userId" type="string" unsaved-value="null">
<column name="USER_ID"/>
<generator class="assigned"/>
</id>
<set name="roles">
<key column="USER_ID"/>
<one-to-many class="test.model.data.Role" />
</set>
</class>
</hibernate-mapping>
in which roles is a collection of Role. However, you can do everything is a simpler way, in which you don't need a Role class and a User class is enough:
Code:
<hibernate-mapping>
<class name="test.model.data.User" table="Users" mutable="true" >
<id name="userId" type="string" unsaved-value="null">
<column name="USER_ID"/>
<generator class="assigned"/>
</id>
<set name="roles" table="ROLES">
<key column="USER_ID"/>
<element column="ROLE_ID" type="string" />
</set>
</class>
</hibernate-mapping>
in which, roles is a collection of Strings. I do suggest this one if the role class does not have more properties. The Java class for the latter will be:
Code:
package test.model.data;
import java.util.Set;
import java.util.HashSet;
public class User
{
private String userId;
private Set<String> roles = new HashSet<String>();
public String getUserId()
{
return userId;
}
public void setUserId(String userId)
{
this.userId = userId;
}
public Set<String> getRoles()
{
return roles;
}
public void setRoles(Set<String> roles)
{
this.roles = roles;
}
}
Farzad-