-->
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.  [ 15 posts ] 
Author Message
 Post subject: Inserting Null Value many-to-one association
PostPosted: Tue Aug 30, 2005 10:23 pm 
Beginner
Beginner

Joined: Tue May 31, 2005 1:16 pm
Posts: 35
Location: Bogota, Colombia
The sql query is inserting null in field "csoc_codigolinea", which is a required field.

I have completely populated the object I want to save!.


Hibernate version:
Hibernate 2.1.8

Mapping documents:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >

<hibernate-mapping>
<!--
Created by the Middlegen Hibernate plugin 2.1

http://boss.bekk.no/boss/middlegen/
http://www.hibernate.org/
-->

<class
name="co.com.unionsoluciones.sofia.cartera.model.bo.SolicitudCredito"
table="solicitudcredito_soc"
>
<meta attribute="implements" inherit="false">net.sf.hibernate.Lifecycle</meta>
<meta attribute="implements" inherit="false">net.sf.hibernate.Validatable</meta>
<meta attribute="implement-equals" inherit="false">true</meta>

<composite-id name="comp_id" class="co.com.unionsoluciones.sofia.cartera.model.bo.SolicitudCreditoPK">
<key-property
name="codigoEmpresa"
column="nsoc_codigoempresa"
type="java.lang.Integer"
length="2"
/>
<key-property
name="codigoOficina"
column="nsoc_codigooficina"
type="java.lang.Integer"
length="2"
/>
<key-property
name="numeroSolicitud"
column="nsoc_numerosolicitud"
type="java.lang.Integer"
length="9"
/>
</composite-id>

<property
name="fechaSolicitud"
type="java.sql.Timestamp"
column="dsoc_fechasolicitud"
not-null="true"
length="23"
/>
<property
name="fechaRadicacion"
type="java.sql.Timestamp"
column="dsoc_fecharadicacion"
not-null="true"
length="23"
/>
<property
name="valor"
type="java.math.BigDecimal"
column="msoc_valor"
not-null="true"
length="19"
/>
<property
name="numeroPlazo"
type="int"
column="nsoc_numeroplazo"
not-null="true"
length="3"
/>
<property
name="tipoGarantia"
type="java.lang.String"
column="csoc_tipogarantia"
not-null="true"
length="1"
/>
<property
name="observacion"
type="java.lang.String"
column="csoc_observacion"
length="2147483647"
/>
<property
name="estado"
type="java.lang.String"
column="csoc_estado"
not-null="true"
length="1"
/>

<!-- Associations -->
<!-- derived association(s) for compound key -->
<!-- bi-directional many-to-one association to Oficina -->
<many-to-one
name="oficina"
class="co.com.unionsoluciones.sofia.cartera.model.bo.Oficina"
update="false"
insert="false"
>
<column name="nsoc_codigoempresa" />
<column name="nsoc_codigooficina" />
</many-to-one>

<!-- bi-directional many-to-one association to Empresa -->
<many-to-one
name="empresa"
class="co.com.unionsoluciones.sofia.cartera.model.bo.Empresa"
update="false"
insert="false"
>
<column name="nsoc_codigoempresa" />
</many-to-one>

<!-- end of derived association(s) -->

<!-- bi-directional many-to-one association to Moneda -->
<many-to-one
name="moneda"
class="co.com.unionsoluciones.sofia.cartera.model.bo.Moneda"
not-null="true"
>
<column name="csoc_codigomoneda" />
</many-to-one>
<property
name="codigoPrograma"
column="csoc_codigoprograma"
type="java.lang.String"
length="5"
not-null="true"
/>
<!-- bi-directional many-to-one association to Convenio -->
<many-to-one
name="convenio"
class="co.com.unionsoluciones.sofia.cartera.model.bo.Convenio"
not-null="true"
insert="false"
update="false"
>
<column name="nsoc_codigoempresa" />
<column name="csoc_codigoconvenio" />
</many-to-one>
<!-- bi-directional many-to-one association to LineaCredito -->
<many-to-one
name="lineaCredito"
class="co.com.unionsoluciones.sofia.cartera.model.bo.LineaCredito"
not-null="true"
insert="false"
update="false"
>
<column name="nsoc_codigoempresa" />
<column name="csoc_codigolinea" />
</many-to-one>
<!-- bi-directional many-to-one association to DestinoCredito -->
<many-to-one
name="destinoCredito"
class="co.com.unionsoluciones.sofia.cartera.model.bo.DestinoCredito"
not-null="true"
>
<column name="csoc_codigodestino" />
</many-to-one>
<!-- bi-directional many-to-one association to SectorEmpresa -->
<many-to-one
name="sectorEmpresa"
class="co.com.unionsoluciones.sofia.cartera.model.bo.SectorEmpresa"
not-null="true"
>
<column name="csoc_codigosector" />
</many-to-one>
<!-- bi-directional many-to-one association to AsesorCredito -->
<many-to-one
name="asesorCredito"
class="co.com.unionsoluciones.sofia.cartera.model.bo.AsesorCredito"
not-null="true"
insert="false"
update="false"
>
<column name="nsoc_codigoempresa" />
<column name="csoc_tipodocumentoasesor" />
<column name="msoc_identificacionasesor" />
</many-to-one>
<!-- bi-directional many-to-one association to PlazoSolicitud -->
<many-to-one
name="plazoSolicitud"
class="co.com.unionsoluciones.sofia.cartera.model.bo.PlazoSolicitud"
not-null="true"
>
<column name="csoc_codigoplazo" />
</many-to-one>
<!-- bi-directional one-to-many association to PersonaSolicitud -->
<set
name="personaSolicituds"
lazy="true"
inverse="true"
cascade="save-update"

>
<key>
<column name="npes_codigoempresa" />
<column name="npes_codigooficina" />
<column name="npes_numerosolicitud" />
</key>
<one-to-many
class="co.com.unionsoluciones.sofia.cartera.model.bo.PersonaSolicitud"
/>
</set>
<!-- bi-directional one-to-many association to GarantiaSolicitud -->
<set
name="garantiaSolicituds"
lazy="true"
inverse="true"
cascade="save-update"
>
<key>
<column name="ngas_codigoempresa" />
<column name="ngas_codigooficina" />
<column name="ngas_numerosolicitud" />
</key>
<one-to-many
class="co.com.unionsoluciones.sofia.cartera.model.bo.GarantiaSolicitud"
/>
</set>
<!-- bi-directional one-to-many association to DocumentoAnexo -->
<set
name="documentoAnexos"
lazy="true"
inverse="true"
cascade="save-update"
>
<key>
<column name="ndoa_codigoempresa" />
<column name="ndoa_codigooficina" />
<column name="ndoa_numerosolicitud" />
</key>
<one-to-many
class="co.com.unionsoluciones.sofia.cartera.model.bo.DocumentoAnexo"
/>
</set>

</class>
</hibernate-mapping>



Code between sessionFactory.openSession() and session.close():

this.getHibernateTemplate().save(objeto);

[Using HibernateDaoSupport from Spring]

Full stack trace of any exception that occurs:

INFO: Entrando a registrar solicitud
Hibernate: insert into solicitudcredito_soc (dsoc_fechasolicitud, dsoc_fecharadicacion, msoc_valor, nsoc_numeroplazo, csoc_tipogarantia, csoc_observacion, csoc_estado, csoc_codigomoneda, csoc_codigoprograma, csoc_codigodestino, csoc_codigosector, csoc_codigoplazo, nsoc_codigoempresa, nsoc_codigooficina, nsoc_numerosolicitud) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
30-Aug-2005 20:07:51 net.sf.hibernate.util.JDBCExceptionReporter logExceptions
WARNING: SQL Error: 515, SQLState: HY000
30-Aug-2005 20:07:51 net.sf.hibernate.util.JDBCExceptionReporter logExceptions
SEVERE: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]Cannot insert the value NULL into column 'csoc_codigolinea', table 'cartera.dbo.solicitudcredito_soc'; column does not allow nulls. INSERT fails.
30-Aug-2005 20:07:51 net.sf.hibernate.util.JDBCExceptionReporter logExceptions
WARNING: SQL Error: 3621, SQLState: HY000
30-Aug-2005 20:07:51 net.sf.hibernate.util.JDBCExceptionReporter logExceptions
SEVERE: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]The statement has been terminated.
30-Aug-2005 20:07:51 net.sf.hibernate.impl.SessionImpl execute
SEVERE: Could not synchronize database state with session
org.springframework.jdbc.UncategorizedSQLException: (Hibernate operation): encountered SQLException [[Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]Cannot insert the value NULL into column 'csoc_codigolinea', table 'cartera.dbo.solicitudcredito_soc'; column does not allow nulls. INSERT fails.]; nested exception is java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]Cannot insert the value NULL into column 'csoc_codigolinea', table 'cartera.dbo.solicitudcredito_soc'; column does not allow nulls. INSERT fails.
java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]Cannot insert the value NULL into column 'csoc_codigolinea', table 'cartera.dbo.solicitudcredito_soc'; column does not allow nulls. INSERT fails.
at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)
at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processErrorToken(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processReplyToken(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSRPCRequest.processReplyToken(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processReply(Unknown Source)
at com.microsoft.jdbc.sqlserver.SQLServerImplStatement.getNextResultType(Unknown Source)
at com.microsoft.jdbc.base.BaseStatement.commonTransitionToState(Unknown Source)
at com.microsoft.jdbc.base.BaseStatement.postImplExecute(Unknown Source)
at com.microsoft.jdbc.base.BasePreparedStatement.postImplExecute(Unknown Source)
at com.microsoft.jdbc.base.BaseStatement.commonExecute(Unknown Source)
at com.microsoft.jdbc.base.BaseStatement.executeUpdateInternal(Unknown Source)
at com.microsoft.jdbc.base.BasePreparedStatement.executeUpdate(Unknown Source)
at org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:101)
at net.sf.hibernate.impl.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:22)
at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:462)
at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:436)
at net.sf.hibernate.impl.ScheduledInsertion.execute(ScheduledInsertion.java:37)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2449)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2435)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2392)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2261)
at org.springframework.orm.hibernate.HibernateTemplate$22.doInHibernate(HibernateTemplate.java:595)
at org.springframework.orm.hibernate.HibernateTemplate.execute(HibernateTemplate.java:312)
at org.springframework.orm.hibernate.HibernateTemplate.flush(HibernateTemplate.java:593)
at co.com.unionsoluciones.sofia.cartera.model.dao.hibernate.SolicitudCreditoDaoHibernateImpl.guardarSolicitudCredito(SolicitudCreditoDaoHibernateImpl.java:37)
at co.com.unionsoluciones.sofia.cartera.model.service.impl.ServicioCreditoImpl.registrarSolicitud(ServicioCreditoImpl.java:61)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:284)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:155)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:122)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:56)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:144)
at org.springframework.orm.hibernate.HibernateInterceptor.invoke(HibernateInterceptor.java:163)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:144)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:174)
at $Proxy1.registrarSolicitud(Unknown Source)
at co.com.unionsoluciones.sofia.cartera.model.TestServicioCredito.testRegistrarSolicitud(TestServicioCredito.java:142)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:478)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
30-Aug-2005 20:07:51 co.com.unionsoluciones.sofia.cartera.model.service.impl.ServicioCreditoImpl registrarSolicitud
SEVERE: SolicitudCredito co.com.unionsoluciones.sofia.cartera.model.bo.SolicitudCredito@6c08b2[comp_id=co.com.unionsoluciones.sofia.cartera.model.bo.SolicitudCreditoPK@c74fe[codigoEmpresa=1,codigoOficina=1,numeroSolicitud=1]] ya existe
org.springframework.jdbc.UncategorizedSQLException: (Hibernate operation): encountered SQLException [[Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]Cannot insert the value NULL into column 'csoc_codigolinea', table 'cartera.dbo.solicitudcredito_soc'; column does not allow nulls. INSERT fails.]; nested exception is java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]Cannot insert the value NULL into column 'csoc_codigolinea', table 'cartera.dbo.solicitudcredito_soc'; column does not allow nulls. INSERT fails.
java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]Cannot insert the value NULL into column 'csoc_codigolinea', table 'cartera.dbo.solicitudcredito_soc'; column does not allow nulls. INSERT fails.
at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)
at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processErrorToken(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processReplyToken(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSRPCRequest.processReplyToken(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processReply(Unknown Source)
at com.microsoft.jdbc.sqlserver.SQLServerImplStatement.getNextResultType(Unknown Source)
at com.microsoft.jdbc.base.BaseStatement.commonTransitionToState(Unknown Source)
at com.microsoft.jdbc.base.BaseStatement.postImplExecute(Unknown Source)
at com.microsoft.jdbc.base.BasePreparedStatement.postImplExecute(Unknown Source)
at com.microsoft.jdbc.base.BaseStatement.commonExecute(Unknown Source)
at com.microsoft.jdbc.base.BaseStatement.executeUpdateInternal(Unknown Source)
at com.microsoft.jdbc.base.BasePreparedStatement.executeUpdate(Unknown Source)
at org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:101)
at net.sf.hibernate.impl.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:22)
at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:462)
at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:436)
at net.sf.hibernate.impl.ScheduledInsertion.execute(ScheduledInsertion.java:37)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2449)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2435)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2392)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2261)
at org.springframework.orm.hibernate.HibernateTemplate$22.doInHibernate(HibernateTemplate.java:595)
at org.springframework.orm.hibernate.HibernateTemplate.execute(HibernateTemplate.java:312)
at org.springframework.orm.hibernate.HibernateTemplate.flush(HibernateTemplate.java:593)
at co.com.unionsoluciones.sofia.cartera.model.dao.hibernate.SolicitudCreditoDaoHibernateImpl.guardarSolicitudCredito(SolicitudCreditoDaoHibernateImpl.java:37)
at co.com.unionsoluciones.sofia.cartera.model.service.impl.ServicioCreditoImpl.registrarSolicitud(ServicioCreditoImpl.java:61)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:284)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:155)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:122)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:56)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:144)
at org.springframework.orm.hibernate.HibernateInterceptor.invoke(HibernateInterceptor.java:163)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:144)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:174)
at $Proxy1.registrarSolicitud(Unknown Source)
at co.com.unionsoluciones.sofia.cartera.model.TestServicioCredito.testRegistrarSolicitud(TestServicioCredito.java:142)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:478)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)

Name and version of the database you are using:
MS SQL SERVER 2000

The generated SQL (show_sql=true):
Hibernate: insert into solicitudcredito_soc (dsoc_fechasolicitud, dsoc_fecharadicacion, msoc_valor, nsoc_numeroplazo, csoc_tipogarantia, csoc_observacion, csoc_estado, csoc_codigomoneda, csoc_codigoprograma, csoc_codigodestino, csoc_codigosector, csoc_codigoplazo, nsoc_codigoempresa, nsoc_codigooficina, nsoc_numerosolicitud) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)


======================================

Please Help! I'm in a hurry.......

_________________
Julian Garcia


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 30, 2005 10:32 pm 
Beginner
Beginner

Joined: Tue May 31, 2005 1:16 pm
Posts: 35
Location: Bogota, Colombia
I have temporally set a default value for field "csoc_codigolinea", and now the field "msoc_identificacionasesor" is causing the same problem.

Code:
[SQLServer 2000 Driver for JDBC][SQLServer]Cannot insert the value NULL into column 'msoc_identificacionasesor', table 'cartera.dbo.solicitudcredito_soc'; column does not allow nulls. INSERT fails.


It seems to be a problem with the "many-to-one" associations that reference a composite PK.

Is there anything special I have to do in order to map many-to-one relationships with composite PK's?

Probably I'm missing something very obvious here, please help!.

_________________
Julian Garcia


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 30, 2005 10:52 pm 
Beginner
Beginner

Joined: Tue May 31, 2005 1:16 pm
Posts: 35
Location: Bogota, Colombia
The reported null values are the ones defined by tags of type "column" inside my "many-to-one" associations, for instance.... csoc_codigoconvenio is reported null..... see mapping below

Code:
<many-to-one
        name="convenio"
        class="co.com.unionsoluciones.sofia.cartera.model.bo.Convenio"
        not-null="true"
      insert="false"
      update="false"
    >
        <column name="nsoc_codigoempresa" />
        <column name="csoc_codigoconvenio" />
    </many-to-one>

_________________
Julian Garcia


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 31, 2005 9:12 am 
Beginner
Beginner

Joined: Tue May 31, 2005 1:16 pm
Posts: 35
Location: Bogota, Colombia
I'm still struggling with this, I think it might be an error in the mapping file (which was generated with middlegen).

Any Ideas?

_________________
Julian Garcia


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 31, 2005 12:59 pm 
Beginner
Beginner

Joined: Tue May 31, 2005 1:16 pm
Posts: 35
Location: Bogota, Colombia
My insert wasn't including the required fields due to these lines in my mapping file:
Code:
insert="false"
update="false"

now, inside my many-to-one I have set

Code:
insert="true"


this will allow the insert statement to include the fields that were being reported null.

Now, I am getting this exception:

net.sf.hibernate.MappingException: Repeated column in mapping for class co.com.unionsoluciones.sofia.cartera.model.bo.SolicitudCredito should be mapped with insert="false" update="false".

The problem might be that as you can see on the full mapping, the field "nsoc_codigoempresa" is part of almost all my PK's.....


Is there any way to get rid of this error?

_________________
Julian Garcia


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 31, 2005 3:29 pm 
Beginner
Beginner

Joined: Tue May 31, 2005 1:16 pm
Posts: 35
Location: Bogota, Colombia
How can I fix my mapping in order to deal with this legacy database, plagued with composite ID's. Unfortunately almost all my tables are related to empresa!

Please help.!

_________________
Julian Garcia


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 31, 2005 8:16 pm 
Expert
Expert

Joined: Sat Jun 12, 2004 4:49 pm
Posts: 915
- you have to use <key-many-to-one> in composite key for complex schema

- don't use update=false or insert=false and you haven't to any column in mapping twice

- you have composite id class and key property for any class (SolicitudCredito)

etc ...

move to hibernate 3 - it is much better

regards


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 31, 2005 10:21 pm 
Beginner
Beginner

Joined: Tue May 31, 2005 1:16 pm
Posts: 35
Location: Bogota, Colombia
Thanks a lot snpesnpe, I really appreciate your help.

Quote:

- you have to use <key-many-to-one> in composite key for complex schema

I will try this and see if the prolem is fixed.

Quote:

don't use update=false or insert=false and you haven't to any column in mapping twice


the problem is that when I use update/insert=true, I get a BadMappingException telling me that there's a repeated column and I should use insert/update=false. I'm not sure if I am missunderstanding you at this point.....



Quote:
- you have composite id class and key property for any class (SolicitudCredito)


unfortuntately I'm working with a legacy DB, which impose a composite PK for almost all my entities....



Quote:
move to hibernate 3 - it is much better


I'd really like to try to move to Hibernate 3, but unfortunately as far as I understand middlegen doesn't generate mappings for version 3. We would like to generate the mapping from the legacy database...do you know anyway to try and move my middlegen-generated v2 mappings to v3?


Thannks......

_________________
Julian Garcia


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 01, 2005 9:07 am 
Expert
Expert

Joined: Sat Jun 12, 2004 4:49 pm
Posts: 915
update/insert=false tell hibernate that don't update/insert this column - do you want this ?

if you have composite class SolicitudCreditoPK then you haven't to have properties in composite key mapping (properties are in SolicitudCreditoPK)

new middlegen (CVS) work with hibernate3, but it isn't important - you need change DOCTYPE
in mapping file to hibernate3 dtd, only - see example in documentation - it is compatible with hibernate3


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 05, 2005 9:35 am 
Beginner
Beginner

Joined: Tue May 31, 2005 1:16 pm
Posts: 35
Location: Bogota, Colombia
Snpesnpe thanks for your kind help.

Quote:
update/insert=false tell hibernate that don't update/insert this column - do you want this ?


No, I dont want this, and in fact this was causing the problem, so I changed my mapping not using insert/update=false. That way, I got rid of this error:

Cannot insert the value NULL into column 'csoc_codigolinea', table 'cartera.dbo.solicitudcredito_soc'; column does not allow nulls.

Then, not using insert/update=false, I get this error

Repeated column in mapping for class co.com.unionsoluciones.sofia.cartera.model.bo.SolicitudCredito should be mapped with insert="false" update="false": nsoc_codigoempresa

Although Im using a class for my composite PK, not having the properties in composite key mapping causes an Invalid Mapping Exception.


On the other hand, considering migration to Hibernate 3, I think it will not help unless I change my mapping. Am I wrong with this?


Thnaks....

_________________
Julian Garcia


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 05, 2005 10:23 am 
Expert
Expert

Joined: Sat Jun 12, 2004 4:49 pm
Posts: 915
Julian,
You have map same column/columns twice (I think one in key and second in PK class)
don't map column twice and remove insert/update=false


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 05, 2005 12:36 pm 
Beginner
Beginner

Joined: Tue May 31, 2005 1:16 pm
Posts: 35
Location: Bogota, Colombia
Thanks....
I dont have a mapping hbm file for the composite key class SolicitudPK. I guess the prolem is that one of the fields of the primary key, is also referenced later in the mapping file, since it also belongs to another entity to which Solicitud is associated.

This is the original mapping:

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >

<hibernate-mapping>
<!--
Created by the Middlegen Hibernate plugin 2.1

http://boss.bekk.no/boss/middlegen/
http://www.hibernate.org/
-->

<class
name="co.com.unionsoluciones.sofia.cartera.model.bo.SolicitudCredito"
table="solicitudcredito_soc"
>
<meta attribute="implements" inherit="false">net.sf.hibernate.Lifecycle</meta>
<meta attribute="implements" inherit="false">net.sf.hibernate.Validatable</meta>
<meta attribute="implement-equals" inherit="false">true</meta>

<composite-id name="comp_id" class="co.com.unionsoluciones.sofia.cartera.model.bo.SolicitudCreditoPK">
<key-property
name="codigoEmpresa"
column="nsoc_codigoempresa"
type="java.lang.Integer"
length="2"
/>
<key-property
name="codigoOficina"
column="nsoc_codigooficina"
type="java.lang.Integer"
length="2"
/>
<key-property
name="numeroSolicitud"
column="nsoc_numerosolicitud"
type="java.lang.Integer"
length="9"
/>
</composite-id>

<property
name="fechaSolicitud"
type="java.sql.Timestamp"
column="dsoc_fechasolicitud"
not-null="true"
length="23"
/>
<property
name="fechaRadicacion"
type="java.sql.Timestamp"
column="dsoc_fecharadicacion"
not-null="true"
length="23"
/>
<property
name="valor"
type="java.math.BigDecimal"
column="msoc_valor"
not-null="true"
length="19"
/>
<property
name="numeroPlazo"
type="int"
column="nsoc_numeroplazo"
not-null="true"
length="3"
/>
<property
name="tipoGarantia"
type="java.lang.String"
column="csoc_tipogarantia"
not-null="true"
length="1"
/>
<property
name="observacion"
type="java.lang.String"
column="csoc_observacion"
length="2147483647"
/>
<property
name="estado"
type="java.lang.String"
column="csoc_estado"
not-null="true"
length="1"
/>

<!-- Associations -->
<!-- derived association(s) for compound key -->
<!-- bi-directional many-to-one association to Oficina -->
<many-to-one
name="oficina"
class="co.com.unionsoluciones.sofia.cartera.model.bo.Oficina"
update="false"
insert="false"
>
<column name="nsoc_codigoempresa" />
<column name="nsoc_codigooficina" />
</many-to-one>

<!-- bi-directional many-to-one association to Empresa -->
<many-to-one
name="empresa"
class="co.com.unionsoluciones.sofia.cartera.model.bo.Empresa"
update="false"
insert="false"
>
<column name="nsoc_codigoempresa" />
</many-to-one>

<!-- end of derived association(s) -->

<!-- bi-directional many-to-one association to Moneda -->
<many-to-one
name="moneda"
class="co.com.unionsoluciones.sofia.cartera.model.bo.Moneda"
not-null="true"
>
<column name="csoc_codigomoneda" />
</many-to-one>
<property
name="codigoPrograma"
column="csoc_codigoprograma"
type="java.lang.String"
length="5"
not-null="true"
/>
<!-- bi-directional many-to-one association to Convenio -->
<many-to-one
name="convenio"
class="co.com.unionsoluciones.sofia.cartera.model.bo.Convenio"
not-null="true"
insert="false"
update="false"
>
<column name="nsoc_codigoempresa" />
<column name="csoc_codigoconvenio" />
</many-to-one>
<!-- bi-directional many-to-one association to LineaCredito -->
<many-to-one
name="lineaCredito"
class="co.com.unionsoluciones.sofia.cartera.model.bo.LineaCredito"
not-null="true"
insert="false"
update="false"
>
<column name="nsoc_codigoempresa" />
<column name="csoc_codigolinea" />
</many-to-one>
<!-- bi-directional many-to-one association to DestinoCredito -->
<many-to-one
name="destinoCredito"
class="co.com.unionsoluciones.sofia.cartera.model.bo.DestinoCredito"
not-null="true"
>
<column name="csoc_codigodestino" />
</many-to-one>
<!-- bi-directional many-to-one association to SectorEmpresa -->
<many-to-one
name="sectorEmpresa"
class="co.com.unionsoluciones.sofia.cartera.model.bo.SectorEmpresa"
not-null="true"
>
<column name="csoc_codigosector" />
</many-to-one>
<!-- bi-directional many-to-one association to AsesorCredito -->
<many-to-one
name="asesorCredito"
class="co.com.unionsoluciones.sofia.cartera.model.bo.AsesorCredito"
not-null="true"
insert="false"
update="false"
>
<column name="nsoc_codigoempresa" />
<column name="csoc_tipodocumentoasesor" />
<column name="msoc_identificacionasesor" />
</many-to-one>
<!-- bi-directional many-to-one association to PlazoSolicitud -->
<many-to-one
name="plazoSolicitud"
class="co.com.unionsoluciones.sofia.cartera.model.bo.PlazoSolicitud"
not-null="true"
>
<column name="csoc_codigoplazo" />
</many-to-one>
<!-- bi-directional one-to-many association to PersonaSolicitud -->
<set
name="personaSolicituds"
lazy="true"
inverse="true"
cascade="none"

>
<key>
<column name="npes_codigoempresa" />
<column name="npes_codigooficina" />
<column name="npes_numerosolicitud" />
</key>
<one-to-many
class="co.com.unionsoluciones.sofia.cartera.model.bo.PersonaSolicitud"
/>
</set>
<!-- bi-directional one-to-many association to GarantiaSolicitud -->
<set
name="garantiaSolicituds"
lazy="true"
inverse="true"
cascade="none"
>
<key>
<column name="ngas_codigoempresa" />
<column name="ngas_codigooficina" />
<column name="ngas_numerosolicitud" />
</key>
<one-to-many
class="co.com.unionsoluciones.sofia.cartera.model.bo.GarantiaSolicitud"
/>
</set>
<!-- bi-directional one-to-many association to DocumentoAnexo -->
<set
name="documentoAnexos"
lazy="true"
inverse="true"
cascade="none"
>
<key>
<column name="ndoa_codigoempresa" />
<column name="ndoa_codigooficina" />
<column name="ndoa_numerosolicitud" />
</key>
<one-to-many
class="co.com.unionsoluciones.sofia.cartera.model.bo.DocumentoAnexo"
/>
</set>

</class>
</hibernate-mapping>


I will appreciate any help.....

_________________
Julian Garcia


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 05, 2005 3:26 pm 
Beginner
Beginner

Joined: Tue May 31, 2005 1:16 pm
Posts: 35
Location: Bogota, Colombia
The mapping above includes the insert/update=false, just as generated by Middlegen. I already changed them to insert/update=false, but then I get the invalid mapping exception.

_________________
Julian Garcia


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 05, 2005 3:27 pm 
Expert
Expert

Joined: Sat Jun 12, 2004 4:49 pm
Posts: 915
I can't check all your classes, but this is example mapping with more composite ids and collections
It work fine with hibernate 3 (it was fine with hibernate 2 before - i change doctype declaration only)

see speacially rob_dokrso

rob_dokr
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping default-lazy="false" package="yu.co.snpe.dbtable.model.hibernate">
   <!--
      Created by the Middlegen Hibernate plugin 2.1
      
      http://boss.bekk.no/boss/middlegen/
      http://www.hibernate.org/
   -->

   <class name="RobDokr" table="ROB_DOKR">
      <meta attribute="extends" inherit="false">BasePersister</meta>

      <composite-id>
         <key-property name="bd" column="BD" type="java.lang.String"
            length="10" />
         <key-many-to-one name="orgMt" column="MT" />
         <key-many-to-one name="robTipdr" column="TIP" />
      </composite-id>

      <property name="datdok" type="java.sql.Date" column="DATDOK"
         not-null="true" length="7" />
      <property name="datvaz" type="java.sql.Date" column="DATVAZ"
         not-null="true" length="7" />
      <property name="status" type="java.lang.String" column="STATUS"
         not-null="true" length="1" />
      <property name="sema" type="int" column="SEMA" not-null="true"
         length="5" />
      <property name="mt1" type="java.lang.String" column="MT1"
         length="4" />
      <property name="reg" type="java.lang.String" column="REG"
         length="20" />
      <property name="zapi" type="java.lang.String" column="ZAPI"
         length="30" />
      <property name="datug" type="java.sql.Timestamp" column="DATUG"
         length="7" />
      <property name="bizv" type="java.lang.String" column="BIZV"
         length="20" />
      <property name="datizv" type="java.sql.Date" column="DATIZV"
         length="7" />
      <property name="kif" type="java.lang.String" column="KIF"
         length="10" />
      <property name="datkif" type="java.sql.Timestamp"
         column="DATKIF" length="7" />
      <property name="dpo" type="java.math.BigDecimal" column="DPO"
         length="22" />
      <property name="kift" type="java.lang.String" column="KIFT"
         length="10" />
      <property name="rabat" type="java.math.BigDecimal"
         column="RABAT" length="22" />
      <property name="rabat1" type="java.math.BigDecimal"
         column="RABAT1" length="22" />
      <property name="rabat2" type="java.math.BigDecimal"
         column="RABAT2" length="22" />
      <property name="vrsta" type="java.lang.String" column="VRSTA"
         length="1" />
      <property name="stopa" type="java.math.BigDecimal"
         column="STOPA" length="22" />
      <property name="rabat3" type="java.math.BigDecimal"
         column="RABAT3" length="22" />
      <property name="rabat13" type="java.math.BigDecimal"
         column="RABAT13" length="22" />
      <property name="rabat29" type="java.math.BigDecimal"
         column="RABAT29" length="22" />
      <property name="rabatBg" type="java.math.BigDecimal"
         column="RABAT_BG" length="22" />
      <property name="datpov" type="java.sql.Timestamp"
         column="DATPOV" length="7" />

      <!-- bi-directional many-to-one association to FinVal -->
      <many-to-one name="finVal"
         class="FinVal" not-null="true">
         <column name="VAL" />
      </many-to-one>
      <!-- bi-directional many-to-one association to OrgZap -->
      <many-to-one name="orgZapZap" class="OrgZap" not-null="true">
         <column name="ZAP" />
      </many-to-one>
      <!-- bi-directional many-to-one association to OrgZap -->
      <many-to-one name="orgZapOdg" class="OrgZap" not-null="true">
         <column name="ODG" />
      </many-to-one>
      <!-- bi-directional many-to-one association to FinPar -->
      <many-to-one name="finParPar" class="FinPar" not-null="true">
         <column name="PAR" />
      </many-to-one>
      <!-- bi-directional many-to-one association to FinPar -->
      <many-to-one name="finParIdt" class="FinPar" not-null="true">
         <column name="IDT" />
      </many-to-one>
      <!-- bi-directional many-to-one association to RobKalkTip -->
      <many-to-one name="robKalkTipOca" class="RobKalkTip"
         not-null="true">
         <column name="OCA" />
      </many-to-one>
      <!-- bi-directional many-to-one association to RobKalkTip -->
      <many-to-one name="robKalkTipOc" class="RobKalkTip"
         not-null="true">
         <column name="OC" />
      </many-to-one>
      <!-- bi-directional many-to-one association to RobKalkTip -->
      <many-to-one name="robKalkTipOc1" class="RobKalkTip"
         not-null="true">
         <column name="OC1" />
      </many-to-one>
      <!-- bi-directional many-to-one association to RobKalkTip -->
      <many-to-one name="robKalkTipOca1" class="RobKalkTip"
         not-null="true">
         <column name="OCA1" />
      </many-to-one>
      <!-- bi-directional many-to-one association to FinNk -->
      <many-to-one name="finNk" class="FinNk" not-null="true">
         <column name="BRN" />
      </many-to-one>

   </class>
</hibernate-mapping>


rob_dokrs

Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping default-lazy="false" package="yu.co.snpe.dbtable.model.hibernate">
   <!--
      Created by the Middlegen Hibernate plugin 2.1
      
      http://boss.bekk.no/boss/middlegen/
      http://www.hibernate.org/
   -->

   <class name="RobDokrs" table="ROB_DOKRS">
      <meta attribute="extends" inherit="false">BasePersister</meta>

      <composite-id>
         <key-many-to-one name="robDokr">
            <column name="BD" />
            <column name="MT" />
            <column name="TIP" />
         </key-many-to-one>
         <key-property name="red" column="RED"
            type="java.math.BigDecimal" length="22" />
      </composite-id>

      <property name="kod" type="java.math.BigDecimal" column="KOD"
         not-null="true" length="22" />
      <property name="kol" type="java.math.BigDecimal" column="KOL"
         length="22" />
      <property name="kolamb" type="java.math.BigDecimal"
         column="KOLAMB" length="22" />
      <property name="kolpak" type="java.math.BigDecimal"
         column="KOLPAK" length="22" />
      <property name="kolpal" type="java.math.BigDecimal"
         column="KOLPAL" length="22" />
      <property name="kolp" type="java.math.BigDecimal" column="KOLP"
         length="22" />
      <property name="kolambp" type="java.math.BigDecimal"
         column="KOLAMBP" length="22" />
      <property name="kolpakp" type="java.math.BigDecimal"
         column="KOLPAKP" length="22" />
      <property name="kolpalp" type="java.math.BigDecimal"
         column="KOLPALP" length="22" />
      <property name="cij" type="java.math.BigDecimal" column="CIJ"
         length="22" />
      <property name="cijamb" type="java.math.BigDecimal"
         column="CIJAMB" length="22" />
      <property name="cijpak" type="java.math.BigDecimal"
         column="CIJPAK" length="22" />
      <property name="cijpal" type="java.math.BigDecimal"
         column="CIJPAL" length="22" />
      <property name="rabbg" type="java.math.BigDecimal"
         column="RABBG" length="22" />


      <many-to-one name="robRobaRoba" class="RobRoba">
         <column name="ROBA" />
      </many-to-one>
      <many-to-one name="robRobaAmb" class="RobRoba">
         <column name="AMB" />
      </many-to-one>
      <many-to-one name="robRobaPak" class="RobRoba">
         <column name="PAK" />
      </many-to-one>
      <many-to-one name="robRobaPal" class="RobRoba">
         <column name="PAL" />
      </many-to-one>
      
      <many-to-one name="robKalkIdk" class="RobKalk">
         <column name="IDK" />
      </many-to-one>
      <many-to-one name="robKalkIdamb" class="RobKalk">
         <column name="IDAMB" />
      </many-to-one>
      <many-to-one name="robKalkIdpak" class="RobKalk">
         <column name="IDPAK" />
      </many-to-one>
      <many-to-one name="robKalkIdpal" class="RobKalk">
         <column name="IDPAL" />
      </many-to-one>
   </class>
</hibernate-mapping>


rob_dokrso

Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping default-lazy="false"  package="yu.co.snpe.dbtable.model.hibernate">
   <!--
      Created by the Middlegen Hibernate plugin 2.1
      
      http://boss.bekk.no/boss/middlegen/
      http://www.hibernate.org/
   -->

   <class name="RobDokrso" table="ROB_DOKRSO">
      <meta attribute="extends" inherit="false">BasePersister</meta>

      <composite-id>
         <key-many-to-one name="robDokrs">
            <column name="BD" />
            <column name="MT" />
            <column name="TIP" />
            <column name="RED" />
         </key-many-to-one>

         <key-property name="tipo" column="TIPO"
            type="java.lang.String" length="3" />
      </composite-id>

      <property name="kol" type="java.math.BigDecimal" column="KOL"
         length="22" />
      <property name="kolamb" type="java.math.BigDecimal"
         column="KOLAMB" length="22" />
      <property name="kolpak" type="java.math.BigDecimal"
         column="KOLPAK" length="22" />
      <property name="kolpal" type="java.math.BigDecimal"
         column="KOLPAL" length="22" />

   </class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 05, 2005 6:07 pm 
Beginner
Beginner

Joined: Tue May 31, 2005 1:16 pm
Posts: 35
Location: Bogota, Colombia
This is very helpful, I'll take a look and see if it works.....
Thanks

_________________
Julian Garcia


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 15 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.