Hello, I've a problem when a try to insert in a table that have a many-to-one association.
I get de following
exception when run my application:
---------------------------------------------
Code:
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at es.leroymerlin.agoc.comun.dao.DAOBasicoFactory.getDAO(DAOBasicoFactory.java:50)
... 4 more
Caused by: es.leroymerlin.agoc.comun.dao.DAOException: net.sf.hibernate.MappingException: Repeated column in mapping for class es.leroymerlin.agoc.backend.vo.hojagestion.HojasGestionDetalle should be mapped with insert="false" update="false": ID_SECCIONCOMERCIAL
at es.leroymerlin.agoc.backend.comun.hi.LMHibDAOGenerico.inicializar(LMHibDAOGenerico.java:48)
at es.leroymerlin.agoc.backend.comun.hi.LMHibDAOGenerico.<init>(LMHibDAOGenerico.java:36)
at es.leroymerlin.agoc.backend.comun.hi.LMDAOBasico.<init>(LMDAOBasico.java:37)
at es.leroymerlin.agoc.backend.dao.hojagestion.HojaGestionDAO.<init>(HojaGestionDAO.java:54)
... 9 more
Caused by: net.sf.hibernate.MappingException: Repeated column in mapping for class es.leroymerlin.agoc.backend.vo.hojagestion.HojasGestionDetalle should be mapped with insert="false" update="false": ID_SECCIONCOMERCIAL
at net.sf.hibernate.persister.AbstractEntityPersister.checkColumnDuplication(AbstractEntityPersister.java:1015)
at net.sf.hibernate.persister.EntityPersister.<init>(EntityPersister.java:799)
at net.sf.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:42)
at net.sf.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:137)
at net.sf.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:805)
at es.leroymerlin.agoc.backend.comun.hi.LMHibDAOGenerico.inicializar(LMHibDAOGenerico.java:45)
... 12 more
--------------------------------------------
Here are
my two mappings:
HOJA_GESTION_DETALLE: Code:
<class
name="es.leroymerlin.agoc.backend.vo.hojagestion.HojasGestionDetalle"
table="HOJAS_GESTION_DETALLE"
schema="AGOC_DES_OWN"
>
<composite-id name="comp_id" class="es.leroymerlin.agoc.backend.vo.hojagestion.HojasGestionDetallePK">
<key-many-to-one name="">
</key-many-to-one>
<key-property
name="idSeccioncomercial"
column="ID_SECCIONCOMERCIAL"
type="java.lang.Long"
length="2"
/>
<key-property
name="idOpcomercial"
column="ID_OPCOMERCIAL"
type="java.lang.Long"
length="9"
/>
<key-property
name="idArticulo"
column="ID_ARTICULO"
type="java.lang.Long"
length="9"
/>
</composite-id>
< SOME SIMPLE PROPERTIES....... >
</many-to-one>
<!-- bi-directional many-to-one association to GruposArticulo -->
<many-to-one
name="gruposArticulo"
class="es.leroymerlin.agoc.backend.vo.hojagestion.GruposArticulo"
not-null="true">
<column name="GRUPOS_ARTICULOS.ID_GRUPOARTICULO" />
<column name="GRUPOS_ARTICULOS.ID_OPCOMERCIAL"/>
<column name="GRUPOS_ARTICULOS.ID_SECCIONCOMERCIAL"/>
</many-to-one>
</class>
</hibernate-mapping>
GRUPOS_ARTICULOS:Code:
<class
name="es.leroymerlin.agoc.backend.vo.hojagestion.GruposArticulo"
table="GRUPOS_ARTICULOS"
schema="AGOC_DES_OWN"
>
<composite-id name="comp_id" class="es.leroymerlin.agoc.backend.vo.hojagestion.GruposArticuloPK">
<key-property
name="idGrupoarticulo"
column="ID_GRUPOARTICULO"
type="java.lang.Long"
length="9"
/>
<key-property
name="idSeccioncomercial"
column="ID_SECCIONCOMERCIAL"
type="java.lang.Long"
length="2"
/>
<key-property
name="idOpcomercial"
column="ID_OPCOMERCIAL"
type="java.lang.Long"
length="9"
/>
</composite-id>
<!-- bi-directional one-to-many association to HojasGestionDetalle -->
<set
name="hojasGestionDetalles"
lazy="true"
inverse="true"
cascade="all"
>
<key>
<column name="ID_GRUPOARTICULO" />
<column name="ID_SECCIONCOMERCIAL" />
<column name="ID_OPCOMERCIAL" />
</key>
<one-to-many
class="es.leroymerlin.agoc.backend.vo.hojagestion.HojasGestionDetalle"
/>
</set>
</class>
</hibernate-mapping>
***********************************************************
The problem seems to be that the PK of the table
Quote:
GRUPOS_ARTICULOS
is part of the PK of the table
Quote:
HOJA_GESTION_DETALLE
but not completely:
id_SeccionComercial : is PK of HOJA_GESTION_DETALLE and FK to GRUPOS_ARTICULOS
id_OpComercial : is PK of HOJA_GESTION_DETALLE and FK to GRUPOS_ARTICULOS
id_GrupoFolleto : is NOT PK of HOJA_GESTION_DETALLE and FK to GRUPOS_ARTICULOS
I cannot put this relation as NULL is obligatory, and if I put :
insert = false
update = false
it throws another exception because this field cannot be NULL.
I'm using Hibernate 2.1
Please I need help!!
thank you