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