-->
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.  [ 3 posts ] 
Author Message
 Post subject: many-to-many used in a map
PostPosted: Wed Dec 10, 2003 9:06 am 
Newbie

Joined: Thu Dec 04, 2003 5:53 am
Posts: 11
Location: Toulouse, France
Hello. Using Hibernate 2.0.3. I'm having problems creating a Map which represents a many-to-many relationship.

I chose a many-to-many between students and classes as a classical example.
I want a student to have a Map of classes, indexed by classId.

My mapping document looks like this:
Code:
<hibernate-mapping>
    <class
        name="tests.Student"
        table="Student"
        dynamic-update="false"
        dynamic-insert="false">

        <id name="studentId" column="studentId" type="long">
            <generator class="hilo" />
        </id>

        ...

        <map
            name="classes"
            table="StudentClass"
            lazy="true"
            sort="unsorted"
            inverse="true"
            cascade="none">
              <key column="studentId" />
              <index column="classId" type="long" />
              <many-to-many
                  class="tests.Class"
                  column="classId"
                  outer-join="auto"
              />
        </map>
    </class>
</hibernate-mapping>


The error I get is this:
net.sf.hibernate.MappingException: Repeated column in mapping for collection: tests.Student.classes column: studentId

I can see that I'm mapping both the index and the many-to-many to classId, but isn't this precisely what I want to do?

Thanks in advance,
Assaf


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 12, 2003 3:16 pm 
Newbie

Joined: Thu Dec 11, 2003 6:21 am
Posts: 8
Don't you want a Set or a List rather than a Map for this kind of association?


Top
 Profile  
 
 Post subject: Re: many-to-many used in a map
PostPosted: Sat Dec 13, 2003 6:18 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
assaf wrote:
I can see that I'm mapping both the index and the many-to-many to classId, but isn't this precisely what I want to do?

Can't do that. The map index can be set by be user building the Map, so it cannot be mapped to an already mappede column. It has to be a new one, and it won't be related to classId, unless the application always use classId as map index.

_________________
Emmanuel


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