-->
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: Projections group, rowCount & Transformers.aliasToBean
PostPosted: Wed May 05, 2010 11:35 pm 
Newbie

Joined: Wed May 05, 2010 11:24 pm
Posts: 1
Hi.

Excuse my English.

I have a list of books and I group theese books by author.

And, sure, I would like to have a way to read how many authors per book exists in the same result.

So, I'm using Projections and the method rowCount().

That's fine, despite the fact I have to handle - there's more properties in the result - with "fields" by numbered indexes.

Like: obj[0] = title; obj[1] = editor; etc.

It sounds bad to me, it would be nice getting a result and read the values by name.

So, that's what Transformers.aliasToBean does.

But... If I use aliasToBean I start a problem:

I can't use Projections.rowCount() and give an alias to that propertie because I'll get an error:

Code:
PropertyNotFoundException: Could not find setter for total on class model.Book


And it's true, my Book doesn't has a property "total" just because "total" it's only important in my search.

So... What should I do?

Here's the code:

Code:
       Criteria crit = this.session.createCriteria(Book.class);
       ProjectionList proList = Projections.projectionList();
       proList.add(Projections.rowCount(), "total");
       proList.add(Projections.property("title"), "title");
       proList.add(Projections.property("author"), "author");
       proList.add(Projections.groupProperty("author"));
       crit.setProjection(proList).setResultTransformer(Transformers.aliasToBean((Book.class)));
       List results = crit.list();


Thanks for any help!
[]s
Alexander
Brazil


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.