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.  [ 1 post ] 
Author Message
 Post subject: Question about Criteria Queries and Projections
PostPosted: Thu Jun 19, 2008 3:52 pm 
Newbie

Joined: Thu Jun 19, 2008 3:44 pm
Posts: 1
Location: Belgium
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 1.2.1
Hi,

I have a problem with writing Criteria Query. To explain the problem I create a small model.
We have two entities Contract and ContractHistory.
- There is a many-to-one association defined on ContractHistory called Contract.
- On the Contract there is a bag defined called Histories.

Here the problem
I want to return an object array that contains a HistoryList and the Contract.

In hql you can do like this

Code:
select c, ch from Contract c join c.Histories ch


The query will return a new object[]{Contract, IList<ContractHistory>}

I don't know how that I can do this with Criteria Queries. What I can do is returning individual properties of the ContractHistory and Contract using the Criteria Query.

For example:

Code:
ICriteria c = session.CreateCriteria(typeof(Contract), "c")
.SetProjection(Projections.Property("c.Name"));


This Criteria Query translate in Hql is

Code:
select c.Name from Contract c join c.Histories ch


Is there no projection that you can say all properties of an entity?

Thx for your time


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.