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.  [ 8 posts ] 
Author Message
 Post subject: one-to-many problem
PostPosted: Tue Apr 17, 2007 12:05 pm 
Newbie

Joined: Tue Mar 27, 2007 5:28 am
Posts: 7
I have 2 tables:
tblcurriculum
- curriculum_id (suregat key)
- student_id
- opleidingsonderdeel_id

tblopleidingsonderdeel
-opleidingsonderdeel_id
-...

In my class curriculum I want to map the corresponding opleidingsonderdeel objects to an arraylist. But it doesn't work out very good...

Here is the mapping file I have tried to use:

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>
   <class name="curriculum" table="tblcurriculum">
       <id name="curriculum_id" column="curriculum_id" type="int">
         <generator class="native"/>
      </id>
         
      <list name="opleidingsonderdelen" table="tblopleidingsonderdeel">
         <key column="opleidingsonderdeel_id" />
         <index column="opleidingsonderdeel_id" type="int"/>
         <one-to-many class="opleidingsonderdeel" />
      </list>
   </class>
</hibernate-mapping>


Any one any idea what's wrong with it? I always get an error "Repeated column in mapping for collection: curriculum.opleidingsonderdelen column: opleidingsonderdeel_id


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 17, 2007 12:58 pm 
Newbie

Joined: Tue Apr 17, 2007 9:02 am
Posts: 7
First of all curriculum_id column should be present in your tblopleidingsonderdeel table.

Only then you can have a list of opleidingsonderdeel in one instance of curriculum i.e. you want multiple rows of table tblopleidingsonderdeel to have the same curriculum_id

Then, the appropriate mapping would be:

<list name="opleidingsonderdelen" table="tblopleidingsonderdeel">
<key column="curriculum_id" />

_________________
Excellence Inc


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 17, 2007 5:19 pm 
Newbie

Joined: Tue Mar 27, 2007 5:28 am
Posts: 7
But what about the index tag? I've read it contains index of the list but how do you need to do this in the table? Can't it be done automatically?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 18, 2007 12:51 am 
Newbie

Joined: Tue Apr 17, 2007 9:02 am
Posts: 7
Index would be the name of your index ON the curriculum_id column of tblopleidingsonderdeel table.

_________________
Excellence Inc


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 18, 2007 5:01 am 
Newbie

Joined: Tue Mar 27, 2007 5:28 am
Posts: 7
I'doesn't work out I've tried several things but it just won't work.

Now I've tried to use a set:
Code:
<set name="opleidingsonderdelen" table="tblopleidingsonderdeel">
      <key column="curriculum_id"/>
      <one-to-many class="opleidingsonderdeel"/>
      </set>

But now I always get the following error: identifier of instance was altered from 1 to 0


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 18, 2007 5:16 am 
Newbie

Joined: Tue Apr 17, 2007 9:02 am
Posts: 7
glennvc i can understand the frustration.
But dont give up on it and consider the step by step approach. Your mapping is fine now - just check whether your primary keys are fine.

Just a checklist to help you go through the problem:

1)
Your mapping for Curriculum should be:
<set name="opleidingsonderdelen" inverse="true">
<key>
<column name="curriculum_id"/>
</key>
<one-to-many class="fully.qualified.classname.opleidingsonderdeel" />
</set>


2)
Your mapping for Opleidingsonderdeel should contain:

<many-to-one name="curriculum" class="fully.qualified.classname.Curriculum">
<column name="CURRICULUM_ID" />
</many-to-one>

3) Class Curriculum should have a getter / setter for Set opleidingsonderdelen

4) Class Opleidingsonderdeel should have a gettter / setter for Curriculum

5) Just open a session and execute
session.createQuery(" from Curriculum c ").list()

Has to work!

Hope you get it to work :)

_________________
Excellence Inc


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 18, 2007 5:25 am 
Newbie

Joined: Tue Mar 27, 2007 5:28 am
Posts: 7
Do I really need a link to curriculum in opleidingsonderdeel? Cause the main thought is that one curriculums have multiple opleidingsonderdeel instances but an opleidingsonderdeel can be placed in several curriculums instances, but in opleidingsonderdeel isn't normaly a link to a curriculum.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 19, 2007 3:39 am 
Newbie

Joined: Tue Mar 27, 2007 5:28 am
Posts: 7
It really doesn't seame to work out...

For the record.

The 2 tables look like this:

tlbcurriculum
curriculum_id | student_id | opleidingsonderdeel_id
1 1 1
2 1 2
tblopleidingsonderdeel
opleidingsonderdeel_id | benaming
1 test
2 test

in my class curriculum I have a set<opleidingsonderdeel> that I want to fill with instances of the class opleidingsonderdeel according to the tables.

But It just won't work using hibernate. Anyone that can help me out?


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