-->
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.  [ 5 posts ] 
Author Message
 Post subject: API Criteria
PostPosted: Tue Oct 05, 2004 11:17 am 
Newbie

Joined: Wed Aug 25, 2004 4:31 am
Posts: 1
I would like to know how to retrive a specific column(for example the id column of the instance) using the method criteria.list()

Thanks for help
[/list]


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 05, 2004 7:03 pm 
Pro
Pro

Joined: Tue Aug 26, 2003 8:07 pm
Posts: 229
Location: Brisbane, Australia
Projection is not yet supported for the Criteria API, only HQL.

I believe it is expected sometime around the 3.1 timeframe (see the roadmap on the web site).

_________________
Cheers,
Shorn.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 06, 2004 3:28 am 
Newbie

Joined: Thu Dec 18, 2003 4:13 am
Posts: 19
Ok, but what about the ResultTransformer interface ? We heard about this feature but could not get much information ? Is it possible to use it in order to retrieve specific columns ?

Has anyone any code sample ?

Thank you in advance.

Xavier.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 06, 2004 6:03 am 
Newbie

Joined: Thu Dec 18, 2003 4:13 am
Posts: 19
I just found a way to use the ResultTransformer. Here is a sample of the class that implement this interface:

Code:
public class IDResultTransformer implements ResultTransformer {

  public Object transformTuple(Object[] tuple, String[] aliases) {
    Object object = tuple[tuple.length - 1];
    if(object instanceof MyEntityClass) {
      return ((MyEntityClass)object).getID();
    }
    return object;
  }

  public List transformList(List collection) {
    return collection;
  }


Then, instead of invoking the
Code:
criteria.list()
method, there just needs to call
Code:
criteria.setResultTransformer(new IDResultTransformer ()).list();


Xavier.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 03, 2005 4:42 am 
Newbie

Joined: Wed Nov 05, 2003 6:05 am
Posts: 6
Hello,

Is it really possible to implement projection using the ResultTransformer API?

It seems to me that the properties of the objects passed to the transformTuple() method are not initialized except for the identifier properties.

In the above example this means that the property getter methods on the MyEntityClass instances other than the getID() return null.

After all, what is this interace good for?

Best regards,

Peter


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