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.  [ 3 posts ] 
Author Message
 Post subject: Multiple id fields
PostPosted: Tue Dec 07, 2004 8:43 pm 
Newbie

Joined: Tue Dec 07, 2004 8:24 pm
Posts: 2
I had a query, but this always return de same data. I do think that it is because in the seriesanio.hbm.xml file I defined a field ID. In fact the id of the table are three fields,.

How can i define the three flields as ID???

This is my code:

<id name="id_indicador" column="ID_INDICADOR" type="java.lang.String" unsaved-value="null">
<generator class="native"/>
</id>

but the id of the table are id_indicador,anio and id_combinacion.
Thanks in advance.


Top
 Profile  
 
 Post subject: Re: Multiple id fields
PostPosted: Wed Dec 08, 2004 3:53 am 
Senior
Senior

Joined: Sat Jul 17, 2004 5:16 pm
Posts: 143
fernandroide wrote:
I had a query, but this always return de same data. I do think that it is because in the seriesanio.hbm.xml file I defined a field ID. In fact the id of the table are three fields,.

How can i define the three flields as ID???

This is my code:

<id name="id_indicador" column="ID_INDICADOR" type="java.lang.String" unsaved-value="null">
<generator class="native"/>
</id>

but the id of the table are id_indicador,anio and id_combinacion.
Thanks in advance.


You need a composite key, and override the equals() and hashcode(). There is a good example in the hibernate docs. To be nice, I will even find you a link...

http://www.hibernate.org/hib_docs/refer ... ompositeid

Regards,
Chris


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 08, 2004 3:29 pm 
Newbie

Joined: Tue Dec 07, 2004 8:24 pm
Posts: 2
Thanks, I changed my code. My new seriesAnio.hbm.xml is:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>
<class name="com.siicyt.Modulos.Indicadores.seriesAnio" table="SERIESANIO" >
<composite-id name="key" class="com.siicyt.Modulos.Indicadores.seriesAnioId">
<key-property name="id_indicador" column="ID_INDICADOR" type="java.lang.String"/>
<key-property name="id_combinacion" column="ID_COMBINACION" type="int"/>
<key-property name="anio" column="ANIO" type="int"/>
</composite-id>
<property name="valor" column="VALOR" type="int"/>
</class>
</hibernate-mapping>

but, this get a problem:

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: net.sf.hibernate.MappingException: Error reading resource: com/siicyt/Modulos/Indicadores/seriesAnio.hbm.xml
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:358)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)


root cause

java.lang.RuntimeException: net.sf.hibernate.MappingException: Error reading resource: com/siicyt/Modulos/Indicadores/seriesAnio.hbm.xml
com.siicyt.comun.ConnectionFactory.<init>(ConnectionFactory.java:71)
com.siicyt.comun.ConnectionFactory.getInstance(ConnectionFactory.java:105)
com.siicyt.Modulos.Indicadores.ItemService.getItemList(ItemService.java:211)
org.apache.jsp.pages.AddItem_jsp._jspService(AddItem_jsp.java:112)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)

Can any body help me please???
Thanks in advance...


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