I can't get the users of a group.
I have three different classes/tables.
1. Id, contains id and parent
2. User, contains user info, extends Id
3. Group, contains group info, extends Id
Tables:
Code:
_______
| Id
|_______
|
| PK id
| parent
|_______
_______
| User
|_______
|
| id
| name
| sign
|_______
_______
| Groups
|_______
|
| id
| name
|_______
The basic idea to separate the Id from the User and Group classes is to be able to create a user/group hierarchy used elsewhere. Naturally I want the ability to list all users of a group. Or get the parent group of a group. the Id-table uses the "parent" id to set the parent group.
I've created a hbm-file to handle this structure, but here I fail. I can create new users/groups, but I cant list a grup's users.
hbm-file:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="se.two.test.beans" polymorphism="implicit">
<class name="Id">
<id
name="id"
column="id"
type="long">
<generator class="native"/>
</id>
<many-to-one name="parent" column="parent" type="long" class="Id">
<key column="id"/>
</many-to-one>
<joined-subclass name="Group" table="groups">
<key column="id"/>
<property name="name"/>
<set name="users"
table="id"
inverse="true"
cascade="none">
<key column="id"/>
<!-- this doesn't work -->
<one-to-many class="User"/>
<!-- this creates an error:
java.lang.NullPointerException
org.hibernate.mapping.Collection.createForeignKeys(Collection.java:378)
-->
<many-to-one name="user"
class="Id"
column="id"
property-ref="parent"
/>
</set>
</joined-subclass>
<joined-subclass name="User" table="user">
<key column="id"/>
<property name="name"/>
<property name="sname"/>
<property name="sign"/>
</joined-subclass>
</class>
</hibernate-mapping>
Can anyone help me with this ?
Thank you,
Fredric