-->
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.  [ 7 posts ] 
Author Message
 Post subject: Implementing many to many self reference
PostPosted: Fri Jun 09, 2006 7:32 am 
Newbie

Joined: Fri Jun 09, 2006 6:58 am
Posts: 1
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Did that, and did not find anything

One of the project I am working on has following requirements,
Need to store technology names and their versions to a database and also any sub technology it might use. Sub technology is again another technology itself.
A technology may or may not have sub technologies
A technology may have more than one sub technology under it
A technology can be a sub technology for more than one parent technology.
I think this is a case of many to many self reference.

So I have two tables

Technology (TechID, Name, Version) --- The main table
TechSubTech(ParentTechID, ChildTechID) --- The link table

But how do I map this to hiberate mapping files and POJO's??

Can some one please help or tell me if it is possible to do so with hibernate or not?

[b]Hibernate version:[/b]
Hibernate 3.1


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 11, 2006 4:32 pm 
Regular
Regular

Joined: Mon Jun 13, 2005 12:21 pm
Posts: 61
Location: Hannover
You can always break a many to many reference into two one to many references, I guess this would be good approach for you're requirement.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 11, 2006 9:57 pm 
Senior
Senior

Joined: Sun Jun 04, 2006 1:58 am
Posts: 136
you can try something like this

<class name="Technology">
<set name="subtechnologies" table="TechSubTech">
<key column="ParentTechID"/>
<many-to-many column="ChildTechID"
class="Technology"/>
</set>
<join table="TechSubTech"
>
<key column="ParentTechID" unique="true"/>
<many-to-one name="Technology"
column="ChildTechID"
not-null="true"/>
</join>

</class>


Top
 Profile  
 
 Post subject: Re: Implementing many to many self reference
PostPosted: Mon Jun 12, 2006 11:36 am 
Newbie

Joined: Tue May 24, 2005 11:25 am
Posts: 16
shree_kotekar wrote:
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Did that, and did not find anything

One of the project I am working on has following requirements,
Need to store technology names and their versions to a database and also any sub technology it might use. Sub technology is again another technology itself.
A technology may or may not have sub technologies
A technology may have more than one sub technology under it
A technology can be a sub technology for more than one parent technology.
I think this is a case of many to many self reference.

So I have two tables
..


If you are using Oracle, take a look on this one. It will work in your case perfectly.


Top
 Profile  
 
 Post subject: Re: Implementing many to many self reference
PostPosted: Mon Jun 12, 2006 7:14 pm 
Senior
Senior

Joined: Sun Jun 04, 2006 1:58 am
Posts: 136
This in not the right way to promote your stuff man. Not cool.



vitalir wrote:
shree_kotekar wrote:
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Did that, and did not find anything

One of the project I am working on has following requirements,
Need to store technology names and their versions to a database and also any sub technology it might use. Sub technology is again another technology itself.
A technology may or may not have sub technologies
A technology may have more than one sub technology under it
A technology can be a sub technology for more than one parent technology.
I think this is a case of many to many self reference.

So I have two tables
..


If you are using Oracle, take a look on this one. It will work in your case perfectly.


Top
 Profile  
 
 Post subject: Re: Implementing many to many self reference
PostPosted: Mon Jun 12, 2006 8:30 pm 
Newbie

Joined: Tue May 24, 2005 11:25 am
Posts: 16
scarface wrote:
This in not the right way to promote your stuff man. Not cool.


Why not if there are tools out there where simple things are really simple and not even questionable? Just so people aware of them. They are not obliged to switch are they?


Top
 Profile  
 
 Post subject: Re: Implementing many to many self reference
PostPosted: Wed Jun 14, 2006 7:17 am 
Newbie

Joined: Tue Jun 13, 2006 4:26 am
Posts: 3
Location: Bristol
shree_kotekar wrote:
One of the project I am working on has following requirements,
Need to store technology names and their versions to a database and also any sub technology it might use. Sub technology is again another technology itself.

So I have two tables

Technology (TechID, Name, Version) --- The main table
TechSubTech(ParentTechID, ChildTechID) --- The link table

But how do I map this to hiberate mapping files and POJO's??


This should do what you want:

Code:
<class  name="Technology" table="Technology" >
    <id name="techID" column="TechID" type="long">
        <generator class="sequence"/>
    </id>

    <property name="name" type="string">
    <property name="version" type="string">

    <set table="TechSubTech" name="subTechs" >
        <key column="parentTechID" not-null="true" />
        <many-to-many column="childTechID" class="Technology" />
    </set>
</class>

Your POJOs should be as you expect:

Code:
class Technology {
   private long techID;
   private String name;
   private String description;
   private Set<Technology> subTechs = new HashSet<Technology>();

   /* include getters and setters as normal *.
}


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 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.