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