-->
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: query on primary key returning more then one row
PostPosted: Thu Feb 12, 2004 11:36 am 
Beginner
Beginner

Joined: Thu Jan 01, 2004 11:36 am
Posts: 23
Location: Belgium
Hello,

I have a query which normally should return only one row; I noticed however that in some cases it returns the same row twice.

Did anyone run into this problem? when I copy/paste the query (constructed by hibernate) and execute it elsewhere, I get only one row; using P6spy I see the same query executed twice.

I am using hibernate 2.1.2;
cache not used for this table

Thanks for any help.

Jan

-----------------------------------------
for completeness, the class CrfPerson has a child class like this
public class CrfPersonAll extends CrfPerson
{
}

which is mapped to another view like this, returning the same columns

<class
name="eu.cec.admin.epes.services.person.CrfPersonAll"
table="EPES_CRF_PERSONNES_ALL"
mutable="false" >



this code is executed with a freshly restarted weblogic 6.1 sp3
---------------- code ------------------------------------------------
// new Hibernate session, nothing done yet
String sql = "select comref from CrfPerson as comref " +
"where comref.perId = :perId";

Query query = session.createQuery(sql);
// id is 3551
query.setParameter("perId", id, Hibernate.LONG);

List persons = query.list();
Iterator i = persons.iterator();

if (persons.size() > 1 ) {
AppLogger.warn("queryById: id " + id + " The query got more then one result, taking the first result ");
while (i.hasNext()) {
CrfPerson person = (CrfPerson) i.next();
AppLogger.warn("person " + person.getDisplayNameByNom());
}
Iterator j = persons.iterator();
return (CrfPerson) j.next();
}



---------------My hibernate.cfg.xml is configured like this ------------
<property name="dialect">net.sf.hibernate.dialect.OracleDialect</property>
<property name="cache.use_query_cache">true</property>
...
<mapping resource="catalogs/CrfPersonnes.hbm.xml"/>
<mapping resource="catalogs/CrfPersonnesAll.hbm.xml"/>
...


----------------- file CrfPersonnes.hbm.xml ------------------------------------
<hibernate-mapping>
<!--
Created by Middlegen Hibernate plugin

http://boss.bekk.no/boss/middlegen/
http://hibernate.sourceforge.net/
-->

<class
name="eu.cec.admin.epes.services.person.CrfPerson"
table="EPES_CRF_PERSONNES"
mutable="false" >

<!-- <cache usage="read-only"/> -->

<id name="perId" type="java.lang.Long" unsaved-value="null">
<column name="PER_ID" sql-type="NUMBER" not-null="true"/>
<generator class="sequence">
<param name="sequence">epes_sequence</param>
</generator>
</id>

<property
name="noSysper"
column="NO_SYSPER"
type="java.lang.Long"
length="6"
/>
<property
name="nomUsuel"
column="NOM_USUEL"
type="java.lang.String"
length="80"
/>
<property
name="prenom"
column="PRENOM"
type="java.lang.String"
length="70"
/>
<property
name="dtNaiss"
column="DT_NAISS"
type="java.sql.Timestamp"
length="7"
/>
<property
name="sexCd"
column="SEX_CD"
type="java.lang.String"
length="2"
/>
<property
name="userId"
column="USERID"
type="java.lang.String"
length="14"
/>
<property
name="cgrCd"
column="CGR_CD"
type="java.lang.String"
length="8"
/>
<property
name="affectation"
column="AFFECTATION"
type="java.lang.String"
length="120"
/>

<property name="telNo"
column="TEL_NO"
type="java.lang.String"
length="40" />

<property name="dtDebAff1"
column="DT_DEB_AFF_1"
type="java.sql.Timestamp"/>

<property name="dtFinAff1"
column="DT_FIN_AFF_1"
type="java.sql.Timestamp"/>

<property name="tojCd1"
column="TOJ_CD_1"
type="java.lang.String"
length="10" />

<property name="lstCd1"
column="LST_CD_1"
type="java.lang.String"
length="6"/>
<property name="email"
column="EMAIL"
type="java.lang.String"
length="120"/>

</class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 12, 2004 11:51 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Show the mapping of Person and PersonAll.

Hibernate use polymorphism when executing query (as expected in OO world).
Check polymorphism="explicit" in the ref guide.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 12, 2004 12:07 pm 
Beginner
Beginner

Joined: Thu Jan 01, 2004 11:36 am
Posts: 23
Location: Belgium
hello

I have added polymorphism="explicit" to both class definitions in the .hbm.xml files and it worked.

Thanks for your help, Jan


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.