-->
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: [SOLVED] subclass join component with many-to-many
PostPosted: Mon Oct 20, 2014 12:41 am 
Newbie

Joined: Thu Sep 23, 2010 11:14 am
Posts: 10
Hi all!!

I have this clases:

Code:
class Persona{
id
name
...
}

class Cliente extends Persona{
Date medicalRecord
...
}

class Empleado extends Persona{
Especialidad specs
int points
...
}

class Especialidad{
   ...
}

class EmpleadoEspecialidad{
   long id
   Empleado emp
   Especialidad esp
}

I have this mapping:

Code:
    <class name="Persona" table="persona">
        <id name="ID" type="long" unsaved-value="null">
            <column name="persona_id" index="id_index" />
            <generator class="identity" />
        </id>

        <discriminator column="per_tipo" force="true" insert="true" not-null="true" />
        <subclass name="Cliente" discriminator-value="cliente">
            <join table="cliente">
                <key column="cl_id" />
            </join>
        </subclass>
        <subclass name="Empleado" discriminator-value="empleado">
            <join table="empleado">
                <key column="em_id" />
            </join>
        </subclass>
    </class>
</hibernate-mapping>


with this tables:

Code:
+-----------------------+
| Tables                |
+-----------------------+
| cliente               |
| empleado              |
| empleado_especialidad |
| especialidad          |
| persona               |
+-----------------------+


I want to add on Empleado one or more objects type Especialidad and save each record (empleado_id and especialidad_id) on table empleado_especialidad and get a list of Especialidad direct from Empleado (like List<Especialidad> getListOfEspecialidad()) How can I archieve this?

I want many-to-many because, in some part of my application I have to list all Empleado from certain especialidad.

I tried with this:

Code:
<component name="component" >
    <list name="list" table="empleado_especialidad" cascade="all">
        <key column="em_id" />
        <index column="es_id" />
        <one-to-many class="Especialidades" not-found="ignore" />
    </list>
</component>


inside join of subclass Empleado, but each records goes to table especialidad where I have a list (configurable by user) of object especialidad and I can't use same especialidad on more than one Empleado.

I want to have on database this case:

Quote:
Persona
id:1 Name:Emp1
id:2 Name:EmpOfMonth

Empleado:
id:1 points:10
id:2 points:5

Especialidad
id:1 name:Especialidad1
id:2 name:EspecialidadX
id:3 name:Especialidad2
id:4 name:EspecialidadN

EmpleadoEspecialidad
emp_id:1 esp_id:1
emp_id:1 esp_id:3
emp_id:2 esp_id:2
emp_id:2 esp_id:1
emp_id:2 esp_id:3


Thanks in Advance
Regards Juan Pablo from Argentina


Last edited by jotapdiez on Sat Dec 06, 2014 2:57 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: subclass join component with many-to-many
PostPosted: Mon Oct 20, 2014 9:53 pm 
Newbie

Joined: Thu Sep 23, 2010 11:14 am
Posts: 10
The solution was change this:
Code:
<one-to-many ... />


to this
Code:
<many-to-many ... />


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.