-->
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.  [ 6 posts ] 
Author Message
 Post subject: Same object returns from a view.
PostPosted: Thu Sep 11, 2008 10:36 am 
Newbie

Joined: Thu Apr 03, 2008 9:19 am
Posts: 4
Hibernate version: 3.2.5

Name and version of the database you are using: Oracle 10g
Hi,

I have a problem when I perform HQL requests against a view.

More precisely, when I perform a SQL request and then the equivalent HQL request, I find the same number of objects. But, in the case of the HQL request, all objets are the same one !

Here are the sample of my SQL and my HQL requests :


--- SQL Request ---
String query = "from MYVIEW as myview where myview .id = 18 and myview .anpNum = 19 and myview.ageRefagl = 20";

result = getSession().createQuery(query).list();

--- HQL Request ---
getSession().createSQLQuery("select * from MYVIEW where ID = 18 ANP_NUM = 19 and AGE_REFAGL = 20").list();

I hope that someone could help me.

Best regards

PS : Below, you can find my mapping hbm.xml file :

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 9 sept. 2008 17:11:44 by Hibernate Tools 3.2.0.b9 -->
<hibernate-mapping>
<class name="fr.projet.MYVIEW" table="MYVIEW">
<id name="id" type="java.lang.Long">
<column name="ID" precision="10" scale="0" />
<generator class="native"></generator>
</id>
<property name="cmcNom" type="string">
<column name="CMC_NOM" length="20" not-null="true" />
</property>
<property name="anpNum" type="long">
<column name="ANP_NUM" precision="10" scale="0" not-null="true" />
</property>
<property name="anfFreq" type="big_decimal">
<column name="ANF_FREQ" precision="8" />
</property>
<property name="sipNum" type="long">
<column name="SIP_NUM" precision="10" scale="0" not-null="true" />
</property>
<property name="sicNom" type="string">
<column name="SIC_NOM" length="50" not-null="true" />
</property>
<property name="aepNum" type="long">
<column name="AEP_NUM" precision="10" scale="0" not-null="true" />
</property>
<property name="ageRefagl" type="java.lang.Long">
<column name="AGE_REFAGL" precision="10" scale="0" />
</property>
<property name="valeur" type="string">
<column name="VALEUR" length="50" />
</property>
<property name="agpNum" type="long">
<column name="AGP_NUM" precision="10" scale="0" not-null="true" />
</property>
<property name="agcNom" type="string">
<column name="AGC_NOM" length="50" />
</property>
<property name="nbrValNiv" type="big_decimal">
<column name="NBR_VAL_NIV" precision="22" scale="0" />
</property>
<property name="nivMinAno" type="big_decimal">
<column name="NIV_MIN_ANO" precision="22" scale="0" />
</property>
<property name="nivMaxAno" type="big_decimal">
<column name="NIV_MAX_ANO" precision="22" scale="0" />
</property>
<property name="nivMoyAno" type="big_decimal">
<column name="NIV_MOY_ANO" precision="22" scale="0" />
</property>
<property name="nivEcaAno" type="big_decimal">
<column name="NIV_ECA_ANO" precision="22" scale="0" />
</property>
</class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 12, 2008 6:11 pm 
Expert
Expert

Joined: Mon Nov 26, 2007 2:29 pm
Posts: 443
For the information you are giving, it looks more like a programming issue.
How are you iterating your results?

_________________
Gonzalo Díaz


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 15, 2008 4:46 pm 
Newbie

Joined: Mon Sep 15, 2008 4:33 pm
Posts: 3
I'm having exactly the same problem. When I look at the result list in a watch window just after the query.list() has run (I break on the next instruction), I can see that the object id's are the same for all the results.... The number of results is correct, the content is n times the first result....

I'm really interested if someone has got the solution...


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 15, 2008 5:59 pm 
Expert
Expert

Joined: Mon Nov 26, 2007 2:29 pm
Posts: 443
delamotte,

I would not trust the contents of the watch list on this.
Likely, the content of the following children is evaluated only as it is needed.
Again, how are you traversing the children collection?

_________________
Gonzalo Díaz


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 16, 2008 4:28 am 
Newbie

Joined: Mon Sep 15, 2008 4:33 pm
Posts: 3
To iterate through the results:

List oList = <the result of my query.list()>

Iterator it = oList.iterator();
while (it.hasNext())
{
MyClass oMyClass = (MyClass)it.next();
...
}

In the watch window, the result List is an ArrayList; I can deploy it and see all its children (of type MyClass). This way, I can see that all the entries are actually the same java object.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 16, 2008 4:48 pm 
Newbie

Joined: Mon Sep 15, 2008 4:33 pm
Posts: 3
At last, I found the solution...
I use annotations, and the field I have choosed as @id was not a Pk. For a view, it makes no sense, but hibernate doesn't like that. So, I arranged to add a really unique field in my view, and declared it as @id.


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