-->
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: Creating .hbm file for link table
PostPosted: Wed Oct 14, 2009 10:45 am 
Newbie

Joined: Sun Oct 04, 2009 2:49 pm
Posts: 4
Hello all.

So, I am currently attempting to create a .hbm file for a link table, and running into some issues. First off, some details:

I have 1 table called Ability and another table called CastMember. These tables have a many-to-many relationship (cast members can have many abilities and vice versa), so I created a link table, called Ability_CastMember. Here are the table details:

Code:
Ability

create table Ability   
(   
  id int not null primary key,   
  name varchar(30),   
  description text,   
  abilityTypeID int not null references AbilityType(id)   
)type=InnoDB; 

CastMember

create table CastMember   
(   
  id int not null primary key,   
  name varchar(30),
  displayName varchar(30),   
  description text,
  quote text   
)type=InnoDB;

Ability_CastMember

create table Ability_CastMember
(
  abilityID int not null,
  castMemberID int not null,
  primary key (abilityID, castMemberID),
  foreign key (abilityID) references Ability (id),
  foreign key (castMemberID) references CastMember (id)
)type=InnoDB;


Now, I currently have a mapping file for the Ability table which allows me to get a Set containing all CastMembers, and was going to do the inverse in my CastMember mapping file. At any rate, here is Ability.hbm.xml:

Code:
<hibernate-mapping>

   <class name="com.brc.roe.db.ability.entity.Ability" table="Ability">

      <id name="id" column="ID">
         <generator class="assigned" />
      </id>

      <property name="name" type="string">
         <column name="name"/>
      </property>

      <property name="description" type="text">
         <column name="description" />
      </property>
      
      <many-to-one name="abilityType" class="com.brc.roe.db.ability.entity.AbilityType" lazy="false">
         <column name="abilityTypeID" />
      </many-to-one>
      
      <set name="castMembers" table="Ability_CastMember" cascade="all" lazy="false">
         <key column="abilityID" />
         <many-to-many column="castMemberID" class="com.brc.roe.db.cast.entity.CastMember"/>
      </set>
      
   </class>
</hibernate-mapping>


This of course works as expected. So at this point, I was thinking that I didn't even need to have a entity/mapping for the link table! Now here is the issue... All of the data for these tables is static, and thus I keep it in xml files. I use Castor to unmarshall the XML into the entities, and then use hibernate to persist them. So, turns out I need a Ability_CastMember entity and mapping file, if only to be able to load the data with my current system. It won't be used for anything else (that I can think of at the moment). I have googled everything known to man, and have gone through the various docs on the Hibernate main site, but I am still not able to find what I need to create it.

Any help would be greatly appreciated.

Thanks!


Top
 Profile  
 
 Post subject: Re: Creating .hbm file for link table
PostPosted: Thu Oct 15, 2009 1:24 am 
Newbie

Joined: Sun Oct 04, 2009 2:49 pm
Posts: 4
I was able to figure it out. Here is the .hbm I created:

Code:
<hibernate-mapping>

   <class name="com.brc.roe.db.ability_castmember.entity.Ability_CastMember" table="Ability_CastMember">
   
     <composite-id>
        <key-many-to-one name="abilityID" class="com.brc.roe.db.ability.entity.Ability" column="abilityID"></key-many-to-one>
        <key-many-to-one name="castMemberID" class="com.brc.roe.db.cast.entity.CastMember" column="castMemberID"></key-many-to-one>
     </composite-id>
   
   </class>
</hibernate-mapping>


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.