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.  [ 2 posts ] 
Author Message
 Post subject: Composite pattern (FileSystemObject, Folder, File)
PostPosted: Sat Jun 21, 2008 10:26 am 
Newbie

Joined: Sat Jun 21, 2008 10:15 am
Posts: 2
Hi all,

I have to implement a business case that is exaclty like the file system (composite) problem. There is an example in the documentation that shows how to do it. However, it does not work in my case as I do not have just one type (e.g. Node) but 3 types: FileSystemObject as super class and Folder and File, which inherit from it.

This is my mapping file:

Code:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default-lazy="false">
  <class name="FileSystemObject, X" table="fileSystemObject">
    <id name="Id" column="id" type="integer">
      <generator class="assigned" />
    </id>

    <property name="Path" column="path" type="String"/>
    <many-to-one name="ParentObject" class="Folder, X" column="parentFolderID"/>

    <joined-subclass name="Folder, X" table="folder">
      <key column="Id"/>
      <property name="NameShown" column="name" type="String"/>

      <set name="Children" lazy="true" cascade="all">
        <key column="Id"/>
        <one-to-many class="FileSystemObject, X"/>
      </set>

    </joined-subclass>

    <joined-subclass name="File, X" table="file">
      <key column="Id"/>
      <property name="SizeKB" column="sizeKB" type="integer"/>
    </joined-subclass>
  </class>
</hibernate-mapping>


The ParentObject property works fine, however, the Children property always contains one object, which is an instance of the current object.
Has anybody an idea about what is going wrong here??

Thanks!

Cheers,
Brad[quote][/quote]


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jun 21, 2008 10:57 am 
Newbie

Joined: Sat Jun 21, 2008 10:15 am
Posts: 2
Found the problem..

Instead of
Code:
      <set name="Children" lazy="true" cascade="all">
        <key column="Id"/>


it's
Code:
      <set name="Children" lazy="true" cascade="all">
        <key column="parentFolderID"/>


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

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.