-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Problems with many-to-one in inherited class structures
PostPosted: Tue Dec 19, 2006 5:55 am 
Newbie

Joined: Tue Dec 19, 2006 5:22 am
Posts: 4
Location: Karlstad, Sweden
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.