-->
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: Tuples in Criteria result. Is it bug or feature?
PostPosted: Thu Aug 04, 2005 6:35 pm 
Beginner
Beginner

Joined: Thu Feb 17, 2005 9:20 pm
Posts: 36
Location: Vancouver, WA
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:
3.0.5, 3.1b

I am getting tuples with Criteria API. I have two different classes mapped to the same table. They are not inherited from each other. Criteria was created to request one of them. I was very precise on what type of object I want.

Simplified mappings and code:

Map1:
Code:
<class name="Account" table="account">
        <id name="accountId" column="ACCOUNT_ID" type="java.lang.Integer">
            <generator class="native"/>
        </id>
        <property name="balance" column="BALANCE" />
</class>


Map2:
Code:
<class name="SearchAccount" table="account">

  <id name="accountId" column="ACCOUNT_ID" type="java.lang.Integer">
  <generator class="native"/>
</id>

  <property name="balance" column="BALANCE" />

  <one-to-one name="account" class="AjDataAccount" />

<set name="customers" lazy="true" order-by="ACCOUNT_ID">
  <key column="ACCOUNT_ID" />
  <one-to-many class="customer" />
</set>

</class>



I am trying to find account by ID and have built Criteria object for that:
Code:
search = session.createCriteria(SearchAccount.class).add(Expression.eq("accountId", accountId));

Collection accounts = search.list();


Collection accounts will contain one object and it will be Object[] with two elements Object[0] is Account object and Object[1] will be SearchAccount. Why I have array if I have requested specific type(class) of instance? Is it a bug?

This code was working in H2 and does not work in H3. I have tried that in H3.0.5 and H3.1b. Same result.

I much appreciate if somebody can point me on docs part related to that and how can I get homogeneous set of objects

Thank you

_________________
Vasyl Zhabko


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 05, 2005 5:58 pm 
Regular
Regular

Joined: Thu Dec 02, 2004 7:11 am
Posts: 85
Try to set polymorphism="explicit" :

http://www.hibernate.org/hib_docs/v3/re ... tion-class


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 08, 2005 5:29 pm 
Beginner
Beginner

Joined: Thu Feb 17, 2005 9:20 pm
Posts: 36
Location: Vancouver, WA
sergeya wrote:
Try to set polymorphism="explicit" :

http://www.hibernate.org/hib_docs/v3/re ... tion-class


Sergey,
Thank you for your response. It does not help. Result the same. But I would like to share what I found. Before this simple crietria will be executed we call small function (pagination) that will determine what part of result set will be loaded (page). In this function we are using the same criteria with Projection set. Something like that:

Code:
            int count = 0;
            criteria.setProjection(Projections.rowCount());
            count =((Integer) criteria.uniqueResult()).intValue();
            criteria.setProjection(null);


Result is: if you have not set projection for criteria (just skip this piece of code) you will have in result only SearchAccount objects. Once you have it set to anything, like in code above, you will have tuples in your result that will contain Acount and SearchAccount objects stored in Object[2] array. I think it can be considered as a bug because it leads to inconsistent behaviour.

Anyway, thank you one more time,
Regards

_________________
Vasyl Zhabko


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.