-->
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.  [ 7 posts ] 
Author Message
 Post subject: have same number of columns as the referenced primary key
PostPosted: Thu Dec 16, 2004 5:45 pm 
Newbie

Joined: Thu Dec 16, 2004 5:30 pm
Posts: 4
Hello all

Already I searched in several forums, Li the chapter .74 of the manual, but I did not manage to solve this situation, my level still belongs to beginner, because of this I ask for help from gentlemen.


Situation:
They are two tables, tbl_titulos and tbl_itulos_parcela.

tbl_titulos
(PK) tit_numero = numero
(PK) tit_tipo_doc = tipoDocumento

tbl_itulos_parcela
(PK) tpa_parcela = parcela
(PK) tit_tipo_doc = tipoDocumento
(PK) tit_numero = numero


According to that I understood is that the keys quantity of titulos table and different from quantity of títulos_parcela, soon do not know how to do this reference. I unfortunately ca not change BD's Structure, to finish with these keys.

Mappings:

tbl_titulos

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

<hibernate-mapping package="br.com.sblog.projeto.model">
<class name="Titulo" table="tbl_titulos">
<composite-id class="TituloPK" name="Id">
<key-property
column="tit_tipo_doc"
name="tipoDocumento"
type="string"
/>
<key-property
column="tit_numero"
name="numero"
type="integer"
/>
</composite-id>
.
<restante dos campos>
.
</class>
</hibernate-mapping>



tbl_titulos_parcela

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

<hibernate-mapping package="br.com.sblog.projeto.model">
<class name="TituloParcela" table="tbl_titulos_parcela">
<composite-id class="TituloParcelaPK" name="Id">
<key-property
column="tpa_parcela"
name="parcela"
type="string"
/>
<key-many-to-one name="tipoDocumento" class="Titulo" column="tit_tipo_doc"/>
<key-many-to-one name="numero" class="Titulo" column="tit_numero"/>
</composite-id>
.
<restante dos campos>
.
</class>
</hibernate-mapping>


OBS:.
That mapping is to to catch the information of the titulo table




sources

package br.com.sblog.projeto.model.dao;

import java.util.Iterator;

import net.sf.hibernate.HibernateException;
import net.sf.hibernate.Query;
import br.com.sblog.projeto.model.base.BaseTituloParcelaDAO;

public class TituloParcelaDAO extends BaseTituloParcelaDAO
{
public Iterator findByCliente(int aCliente) throws HibernateException
{
_RootDAO.initialize();
Query query = TituloDAO.createSession().createQuery("SELECT tit FROM TituloParcela as tit WHERE tit.Id.codigoCliente = "+aCliente);
return query.iterate();
}
}




package br.com.sblog.projeto.control;

import java.util.Iterator;

import net.sf.hibernate.HibernateException;
import br.com.sblog.projeto.model.TituloParcela;
import br.com.sblog.projeto.model.TituloParcelaPK;
import br.com.sblog.projeto.model.dao.TituloParcelaDAO;

public class ConsultaTitulo {

public static void main(String[] args) throws HibernateException
{
TituloParcelaDAO dao = new TituloParcelaDAO();
System.out.println("Cliente Titulo ");
Iterator it = dao.findByCliente(1131);
while (it.hasNext())
{
TituloParcela tit = (TituloParcela) it.next();
System.out.print(((TituloParcelaPK)tit.getId()).getNumero().getCodigoCliente()+" ");
System.out.println(tit.getDataVencimento() +" ");
}
}
}



Exception

Cliente Titulo
log4j:WARN No appenders could be found for logger (net.sf.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
net.sf.hibernate.MappingException: Foreign key (tbl_titulos_parcela [tit_tipo_doc])) must have same number of columns as the referenced primary key (tbl_titulos [tit_tipo_doc,tit_numero])
at net.sf.hibernate.mapping.ForeignKey.setReferencedTable(ForeignKey.java:60)
at net.sf.hibernate.cfg.Configuration.secondPassCompileForeignKeys(Configuration.java:691)
at net.sf.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:666)
at net.sf.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:784)
at br.com.sblog.projeto.model.base._BaseRootDAO.initialize(_BaseRootDAO.java:54)
at br.com.sblog.projeto.model.base._BaseRootDAO.initialize(_BaseRootDAO.java:38)
at br.com.sblog.projeto.model.dao.TituloParcelaDAO.findByCliente(TituloParcelaDAO.java:13)
at br.com.sblog.projeto.control.ConsultaTitulo.main(ConsultaTitulo.java:17)
Exception in thread "main"


Top
 Profile  
 
 Post subject: Will it be that anybody already saw something similar to tha
PostPosted: Fri Dec 17, 2004 8:56 am 
Newbie

Joined: Thu Dec 16, 2004 5:30 pm
Posts: 4
Will it be that anybody already saw something similar to that mistake? I know that there is solution, but I do not know where search more.... And it did not want have to change of technology soon now..
Very thankful...


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 17, 2004 9:09 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
you should list the columns of the key inside key-many-to-one instead of having two keys.

Code:
<key-many-to-one name="tipoDocumento" class="Titulo">
   <column="tit_tipo_doc"/>
   <column="tit_numero"/>
</key-many-to-one>


does that solve your problem ?

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: Você pode me ajudar novamente exception---Element type &q
PostPosted: Fri Dec 17, 2004 10:29 am 
Newbie

Joined: Thu Dec 16, 2004 5:30 pm
Posts: 4
I changed the mapping, the main key is tit_numero (number)
I understood what you said:

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
<hibernate-mapping package="br.com.sblog.projeto.model">
<class name="TituloParcela" table="tbl_titulos_parcela">
<composite-id class="TituloParcelaPK" name="Id">
<key-property
column="tpa_parcela"
name="parcela"
type="string"
/>
<key-many-to-one name="numero" class="Titulo">
<column="tit_numero"/>
<column="tit_tipo_doc"/>
</key-many-to-one>
</composite-id>


In DAO, I changed for:
public Iterator findByCliente(int aCliente) throws HibernateException
{
_RootDAO.initialize();
Query query = TituloDAO.createSession().createQuery("SELECT tit FROM TituloParcela as tit WHERE tit.Id.codigoCliente = "+aCliente);
return query.iterate();
}


In VIEW:
public static void main(String[] args) throws HibernateException
{
TituloParcelaDAO dao = new TituloParcelaDAO();
System.out.println("Titulo Documento Parcela Vencimento");
Iterator it = dao.findByCliente(1131);
while (it.hasNext())
{
TituloParcela tit = (TituloParcela) it.next();
System.out.print(((TituloParcelaPK)tit.getId()).getNumero().getId().getNumero()+" ");
System.out.print(((TituloParcelaPK)tit.getId()).getNumero().getId().getTipoDocumento()+" ");
System.out.print(((TituloParcelaPK)tit.getId()).getParcela()+" ");
System.out.println(tit.getDataVencimento());
}
}


However the generated exception was:
Titulo Documento Parcela Vencimento
log4j:WARN No appenders could be found for logger (net.sf.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
net.sf.hibernate.MappingException: Error reading resource: TblTitulosParcela.hbm
at net.sf.hibernate.cfg.Configuration.addResource(Configuration.java:339)
at net.sf.hibernate.cfg.Configuration.doConfigure(Configuration.java:1013)
at net.sf.hibernate.cfg.Configuration.doConfigure(Configuration.java:969)
at net.sf.hibernate.cfg.Configuration.configure(Configuration.java:897)
at net.sf.hibernate.cfg.Configuration.configure(Configuration.java:883)
at br.com.sblog.projeto.model.base._BaseRootDAO.initialize(_BaseRootDAO.java:51)
at br.com.sblog.projeto.model.base._BaseRootDAO.initialize(_BaseRootDAO.java:38)
at br.com.sblog.projeto.model.dao.TituloParcelaDAO.findByCliente(TituloParcelaDAO.java:13)
at br.com.sblog.projeto.control.ConsultaTitulo.main(ConsultaTitulo.java:17)
Caused by: net.sf.hibernate.MappingException: org.dom4j.DocumentException: Error on line 14 of document : Element type "null" must be followed by either attribute specifications, ">" or "/>". Nested exception: Element type "null" must be followed by either attribute specifications, ">" or "/>".
at net.sf.hibernate.cfg.Configuration.addInputStream(Configuration.java:296)
at net.sf.hibernate.cfg.Configuration.addResource(Configuration.java:336)
... 8 more
Caused by: org.dom4j.DocumentException: Error on line 14 of document : Element type "null" must be followed by either attribute specifications, ">" or "/>". Nested exception: Element type "null" must be followed by either attribute specifications, ">" or "/>".
at org.dom4j.io.SAXReader.read(SAXReader.java:355)
at net.sf.hibernate.cfg.Configuration.addInputStream(Configuration.java:286)
... 9 more
Exception in thread "main"

Thanks again


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 17, 2004 10:40 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
that is an xml parser error (that you should be able to fix your self, right? ;)

but since i started with writing the bad xml i'll fix it:

Code:
<key-many-to-one name="tipoDocumento" class="Titulo">
   <column name="tit_tipo_doc"/>
   <column name="tit_numero"/>
</key-many-to-one>

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: Thank you very much
PostPosted: Fri Dec 17, 2004 11:04 am 
Newbie

Joined: Thu Dec 16, 2004 5:30 pm
Posts: 4
Thank you very much
My main key, I had to be I number, only that the order there in tbl_titulos, it was tipoDocumento in first, then changed the order and came out right

Once again thank you very much, and I am going to continue with this technology.


Top
 Profile  
 
 Post subject:
PostPosted: Sun May 11, 2008 6:48 am 
Newbie

Joined: Sun May 11, 2008 6:45 am
Posts: 1
how to annotate this in POJO? please help

max wrote:
that is an xml parser error (that you should be able to fix your self, right? ;)

but since i started with writing the bad xml i'll fix it:

Code:
<key-many-to-one name="tipoDocumento" class="Titulo">
   <column name="tit_tipo_doc"/>
   <column name="tit_numero"/>
</key-many-to-one>


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