-->
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.  [ 1 post ] 
Author Message
 Post subject: Mapping exception in use of join-table
PostPosted: Tue Oct 17, 2006 8:11 pm 
Newbie

Joined: Fri Mar 05, 2004 3:22 pm
Posts: 8
Hi.

I'm having a problem Mapping a property, here is what I'm trying to do:

I have one table, with a composite id: documento_faltante:

4 attr in the key, one of them is a FK to the table TIPO_CONTRATO, with con_id property. But in the proyect, I can't made the classic object ORM relation, between tables, 'cause the TIPO_CONTRATO table is gonna be in another JAR in my app. So... by architect conditions, I need to use join table and get only the property I need from the other table tipo_contrato, by the con_id FK, but I only need the tcon_descripcion table field.

I've tried to use the property-ref, the column, foreigin-key and doesn't seems to work.

--------------------------
My mapping:

<class name="documentos.model.DocumentoFaltante" table="i00documento_faltante">

<composite-id name="id" class="com.intercam.corporativo.documentos.model.DocumentoFaltanteId">
<key-many-to-one name="tipoDocumento" class="com.intercam.corporativo.documentos.model.TipoDocumento">
<column name="tdo_id" />
</key-many-to-one>
<key-property name="contratoId" type="java.lang.Integer">
<column name="con_id" />
</key-property>
<key-property name="personaId" type="java.lang.Integer">
<column name="per_id" />
</key-property>
<key-property name="perfil" type="java.lang.Integer">
<column name="perf_id" />
</key-property>
</composite-id>

<property name="fechaInicio" type="java.util.Date">
<column name="dfa_finicio" />
</property>

<property name="numAvisosInterno" type="java.lang.Integer">
<column name="dfa_num_avisos_interno" />
</property>

<property name="numAvisosExterno" type="java.lang.Integer">
<column name="dfa_num_avisos_externo" />
</property>

<!-- descripcion contrato, atributo solo lectura -->
<join table="i00tipo_contrato" inverse="true">
<key property-ref="contratoId" on-delete="noaction" update="false"/>
<property name="descripcionContrato" column="tcon_descripcion" />
</join>

</class>

----------------------------------------------------
My ID Pojo:

public class DocumentoFaltanteId implements java.io.Serializable {

private TipoDocumento tipoDocumento;
private Integer contratoId;
private Integer personaId;
private Integer perfil;

/**
* @return Returns the contratoId.
*/
public Integer getContratoId() {
return contratoId;
}

/**
* @param contratoId
* The contratoId to set.
*/
public void setContratoId(Integer contratoId) {
this.contratoId = contratoId;
}

/**
* @return Returns the perfil.
*/
public Integer getPerfil() {
return perfil;
}

/**
* @param perfil
* The perfil to set.
*/
public void setPerfil(Integer perfil) {
this.perfil = perfil;
}

/**
* @return Returns the personaId.
*/
public Integer getPersonaId() {
return personaId;
}

/**
* @param personaId
* The personaId to set.
*/
public void setPersonaId(Integer personaId) {
this.personaId = personaId;
}

/**
* @return Returns the tipoDocumento.
*/
public TipoDocumento getTipoDocumento() {
return tipoDocumento;
}

/**
* @param tipoDocumento
* The tipoDocumento to set.
*/
public void setTipoDocumento(TipoDocumento tipoDocumento) {
this.tipoDocumento = tipoDocumento;

-----------------------------------------
My complete Pojo:

public class DocumentoFaltante implements java.io.Serializable {

// Fields
private DocumentoFaltanteId id;
private Date fechaInicio;
private Integer numAvisosInterno;
private Integer numAvisosExterno;

// FK con TipoContrato, join-table: Solo lectura, Setter protected
private String descripcionContrato;


public Date getFechaInicio() {
return fechaInicio;
}

public void setFechaInicio(Date fechaInicio) {
this.fechaInicio = fechaInicio;
}

public DocumentoFaltanteId getId() {
return id;
}

public void setId(DocumentoFaltanteId id) {
this.id = id;
}

public Integer getNumAvisosExterno() {
return numAvisosExterno;
}

public void setNumAvisosExterno(Integer numAvisosExterno) {
this.numAvisosExterno = numAvisosExterno;
}

public Integer getNumAvisosInterno() {
return numAvisosInterno;
}

public void setNumAvisosInterno(Integer numAvisosInterno) {
this.numAvisosInterno = numAvisosInterno;
}

// Proteccion, solo hibernate
protected void setDescripcionContrato(String descripcionContrato) {
this.descripcionContrato = descripcionContrato;
}

/**
* @return Returns the descripcionContrato.
*/
public String getDescripcionContrato() {
return descripcionContrato;
}

----------------------------------
The Exception when try to do the Join-Table to get the description of the Tipo_contrato table:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'DocumentacionSessionFactory' defined in class path resource [com/intercam/corporativo/documentos/dao/daoTestApplicationContext.xml]: Initialization of bean failed; nested exception is org.hibernate.MappingException: Foreign key (FKE64A063E345DACF0:i00tipo_contrato [DocumentoFaltante])) must have same number of columns as the referenced primary key (i00documento_faltante [tdo_id,con_id,per_id,perf_id])
org.hibernate.MappingException: Foreign key (FKE64A063E345DACF0:i00tipo_contrato [DocumentoFaltante])) must have same number of columns as the referenced primary key (i00documento_faltante [tdo_id,con_id,per_id,perf_id])
at org.hibernate.mapping.ForeignKey.alignColumns(ForeignKey.java:90)
at org.hibernate.mapping.ForeignKey.alignColumns(ForeignKey.java:73)
at org.hibernate.cfg.Configuration.secondPassCompileForeignKeys(Configuration.java:1145)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1052)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1168)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.newSessionFactory(LocalSessionFactoryBean.java:825)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:751)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1091)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:396)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:233)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:145)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:277)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:313)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:87)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:72)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:63)
at com.intercam.corporativo.documentos.dao.DocRequeridoDAOTest.setUp(DocRequeridoDAOTest.java:44)
at junit.framework.TestCase.runBare(TestCase.java:125)
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 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)

-------------------------------------------
Help is needed. Regards.

Luis Mendoza


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.