Reputation: 487
I am generating the reports using ireport-4.5.0. I am using JRBeanCollectionDatasource
. To this datasource I am sending the list of objects. I am using JPA query to get the result list.
In this query if I give SELECT m from mobile m
it is working fine and generating the report, but if I give SELECT m.title,m.gender from mobile m
then it is giving exception. It is not able to find the attribute.
What to do to resolve this issue? Can any one tell me how to resolve this? I am strucked up here from so many days. Sorry for my poor English.
Thanks In Advance.
Upvotes: 1
Views: 853
Reputation: 12495
Your second query does not return a collection of beans, but rather a collection of arrays (Object[]), that all have two elements: title and gender. The array does not have properties (you cannot call getGender
of getTitle
on it), and hence the exception.
You have a vast array of solutions:
write a simple bean (eg. TitleGener) that only has two properties: gender and title. It should also have a constructor that initializes both of them. Then change your JPA query to: SELECT new my.utils.TitleGender(m.title,m.gender) from mobile m
. This way you will get a collection of beans that actually do have the required properties. This is the quickest fix.
do not JRBeanCollectionDataSource
at all, just use the standard JDBC data source. You do not seem to understand how JPA works anyway, so it is doubtful if you need it. This is - in my opinion - the best choice.
write a simple, specialized JRDataSource
that wraps Object[]. The interface only has two methods and is simple to implement - the main point will be translation from the name of the property to its index int Object[], in your case the translation will be hard-coded. This is what I would do.
Upvotes: 2