-->
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: write all table entries/rows in a Collection
PostPosted: Wed Jun 29, 2011 9:18 am 
Newbie

Joined: Mon Jun 27, 2011 9:31 am
Posts: 2
Hi community,

I am a hibernate newbie and a have a (maybe a beginner-) question:

I have these tables in my MySQL database:

SKILLDATA:
ID - Integer - PK
LVL - Integer
DESC - String

ITEM:
ID - Integer - PK
...
SKILLID - Integer - FOREIGN KEY to SKILLDATA.ID

I create a new java class called SkillData.java, add an one-to-many entry and reference the SkillData class in the ItemData.hmb.xml file:

Code:
...

<class name="packageOne.ItemData" table="ITEM">
<many-to-one class="packageOne.ItemSkillData" column="SKILLID" name="itemSkillData"/>
...
</class>

...

<class name="packageOne.ItemSkillData" table="SKILLDATA">
  <id column="ID" name="skillId" type="java.lang.Long" unsaved-value="0">
   <generator class="native">
    <param name="sequence">ITEMSKILLID_SEQ</param>
   </generator>
  </id>
  <property column="LVL" generated="never" lazy="false" name="level" type="integer"/>
  <property column="DESC" generated="never" lazy="false" name="description" type="text"/>
</class>

...


Now I've a SkillData object in the ItemData class which contains the corresponding skill level. this works fine!

What I want to implement is a List / Array / Set into the ItemData class which contains all entries (rows) from the table SKILLDATA. This List should save entries as SkillData objects. (e.g. Collection<SkillData> allSkillDataEntries;)

How could I realize that? What I've to add/change in the ItemData.hmb.xml and ItemData.java?

Thank you for your help


Top
 Profile  
 
 Post subject: Re: write all table entries/rows in a Collection
PostPosted: Thu Jun 30, 2011 1:25 pm 
Newbie

Joined: Thu Apr 21, 2011 8:59 am
Posts: 14
Hi,
Not sure if you were already able to solve this or not.
If not, the code blocks at http://www.vaannila.com/hibernate/hibernate-example/hibernate-mapping-one-to-many-1.html gives a clear example for your scenario.

_________________
Lokesh, C
( SCBCD 5, CCENT, SCJP 5 )


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.