This works perfectly, but I cant do the same with @Annotations
AfiliadoDiscapacitado [1]----->[1..*] AfiliadoDDM
Code:
<list name="afiliadoDDMList" table="afiliado_ddm" inverse="false" cascade="all" lazy="false" fetch="select">
<key column="afiliado_discapacitado_id" />
<index column="id"/>
<one-to-many class="modelo.AfiliadoDDM"/>
</list>
the closer I was to get it is this:
Code:
@JoinTable(name = "afiliado_ddm"
, joinColumns = @JoinColumn(name = "afiliado_discapacitado_id")
, inverseJoinColumns = @JoinColumn(name = "id")
)
@OneToMany(cascade = CascadeType.ALL)
private List<AfiliadoDDM> afiliadoDDMList;
but the SQL insert is not correct:
Caused by: java.sql.BatchUpdateException: Batch entry 0 insert into afiliado_ddm (afiliado_discapacitado_id, id) values ('6', '7') was aborted. Call getNextException to see the cause.it should be inserting 4 entities and afiliado_discapacitado_id because..
Code:
<hibernate-mapping>
<class name="modelo.AfiliadoDDM" table="afiliado_ddm" schema="public">
<id name="id" type="integer">
<column name="id" />
<generator class="identity" />
</id>
<many-to-one name="discapacidadesGradoGravedad" class="modelo.DiscapacidadesGradoGravedad" fetch="select">
<column name="discapacidades_grado_gravedad" not-null="true" />
</many-to-one>
<many-to-one name="discapacidades" class="modelo.Discapacidades" fetch="select">
<column name="discapacidades" not-null="true" />
</many-to-one>
<many-to-one name="deficiencias" class="modelo.Deficiencias" fetch="select">
<column name="deficiencias" not-null="true" />
</many-to-one>
<many-to-one name="minusvalias" class="modelo.Minusvalias" fetch="select">
<column name="minusvalias" not-null="true" />
</many-to-one>
<many-to-one name="afiliadoDiscapacitado" class="modelo.AfiliadoDiscapacitado">
<column name="afiliado_discapacitado_id" not-null="true" />
</many-to-one>
</class>
</hibernate-mapping>
I would really appreciate a hand..