-->
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: Mapping many-to-many problem
PostPosted: Mon Feb 06, 2006 11:20 am 
Newbie

Joined: Tue Jan 31, 2006 5:22 pm
Posts: 6
Location: Argentina
Hi!!

I'm having a problem and need help (huge help!!).

I'll explain the context.
Tables (..table names are in spanish... ups!!):

Code:
TABLE Carrera {
id_carrera: PK
....
}

TABLE Materia {
id_materia: PK
id_carrera: PK
id_departamento: FK
....
}

TABLE Departamento {
id_departamento: PK
....
}

TABLE Integracion {
id_materia: PK
id_carrera: PK
id_materia_padre : PK
}


Quote:
"id_materia_padre" refers to "id_materia" in Table "Materia"..

"Integracion" would be a table to represent a "many-to-many" relationship between "Materia" and
"Materia" (same entities..), but an exception occurs:

org.hibernate.MappingException:
Repeated column in mapping for collection: com.epidataconsulting.test.Materia.materiasCorrelativas column: ID_CARRERA

Materia.java:
Code:
public class Materia implements Serializable {

   private int id;
   private String nombre;
   private int creditos;
   private String contMin;
   private String objetivo;
   private Departamento departamento;
   private Set materiasCorrelativas = new HashSet();
   private Carrera carrera;

   .....

}

Mapping file: (Materia.hbm.xml)
Code:
<hibernate-mapping package="com.epidataconsulting.test">
   
    <class name="Materia" table="MATERIA">
      
   <composite-id>
      <key-property name="id" column="ID" type="integer" />
      <key-many-to-one name="carrera" class="Carrera" column="ID_CARRERA"/>
   </composite-id>

        <property name="nombre" column="NOMBRE" type="string" length="20" />
        <property name="creditos" column="CREDITOS" type="integer" />
        <property name="contMin" column="CONT_MIN" type="string" length="20" />
        <property name="objetivo" column="OBJETIVO" type="string" length="20" />

   <many-to-one    name="departamento" class="Departamento"
               cascade="all" outer-join="auto"  not-null="true"
               fetch="join" column="ID_DEPARTAMENTO" />
                  
         <many-to-one   name="carrera" class="Carrera"
                     cascade="none" outer-join="auto"
                     column="ID_CARRERA" not-null="true"
                     fetch="join" />

   <set name="materiasCorrelativas" table="MATERIA_CARRERA" inverse="true"> 
      <key > 
         <column name="ID_MATERIA" />
         <column name="ID_CARRERA" />
      </key>
      <many-to-many class="Materia"> 
         <column name="ID_MATERIA_PADRE"/>
         <column name="ID_CARRERA"  />
      </many-to-many>
   </set>      

    </class>

</hibernate-mapping>

After looking for an answer in google i found out that there's a bug related to this issue.
Is there a way to solve this? ... i can't change the column name because the entities are
the same ones....


P.S.: Sorry for my english!!


Top
 Profile  
 
 Post subject: follow up?
PostPosted: Wed May 17, 2006 3:49 pm 
Newbie

Joined: Sat May 13, 2006 12:00 pm
Posts: 19
Are there any follow ups to this issue?

Is it a known bug in Hibernate 3.1.x?

I seem to be running into the same issue.

I'm trying to map a legacy table to a new table (it's a pretty standard Tomcat security realm setup where, by default, the user identifiers between the two tables must match).

Code:
users
=====
id (primary key)
login (natural-id)
password

user_roles
=====
login (composite-key)
role (composite-key)


(note, unfortunately, the user_roles table does not have a generated id; login and role together are the composite-id)

Anyway, I can't get the mapping (which is similar to the one described in this post so I won't repeat it...) to process.

I get that same:

Repeated column in mapping for collection: ...


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 23, 2006 4:22 pm 
Newbie

Joined: Tue Jan 31, 2006 5:22 pm
Posts: 6
Location: Argentina
I solved it using <formula> instead of <column>.

Quote:
<set name="materiasCorrelativas" table="MATERIA_CARRERA" cascade="all" fetch="join">
<cache usage="read-write"/>
<key >
<column name="ID_MATERIA" />
<column name="ID_CARRERA" />
</key>
<many-to-many class="Materia" >
<column name="ID_MATERIA_PADRE"/>
<formula>ID_CARRERA</formula>
</many-to-many>
</set>


Bye!!!


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.