Jump to content
Changes to the Jaspersoft community edition download ×

Subreport JavaBeans ClassCastException


james.kranz
Go to solution Solved by daniel_61,

Recommended Posts

Hello all,

TL;DR: I want to have the names of all participants of an event. I create reports using JavaBeans and Jaspersoft Studio. The structure of my objects looks like this:
Event.allSubevents (java.util.List)
Subevent.allRegistrations (java.util.List)
Registration.Participant (DataModel.Participant)

I'm using the list component to display all subevents and a subreport to display a list of registrations. During report generation I get a ClassCast Excpetion with the following form:

Caused by: java.lang.ClassCastException: DataModel.Participant cannot be cast to DataModel.Participant[/code]

I suspect it's a problem involving classloaders. What can I do? I have already tried setting the classloader of the subreport by using the REPORT_CLASS_LOADER and REPORT_CONTEXT parameters.

Long version:

I'm having problems generating a report using a collection of JavaBeans. I want to display properties of objects which are inside of a java.util.List, which is nested inside a JavaBean which is also nested inside another java.util.List. I can access the first list and it's elements using the "list" component without problems. But I've found out, that it's not possible to generate a datasource from elements inside a list component in order to display the second nested list. As a workoaround I thought of using a subreport inside the list component which displays the list elements. This subreport would get the list as datasource by using the datasource expression:

"new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{listProperty})"[/code]

So far, so good. The targeted property is itself a list containing registrations which are associated with the participants. The ultimate goal is to get the names of them. When I try to fill the report a ClassCast Exception occurs. The stack trace is as follows:

net.sf.jasperreports.engine.JRException: net.sf.jasperreports.engine.JRRuntimeException: net.sf.jasperreports.engine.fill.JRExpressionEvalException: Error evaluating expression for source text: $F{participant}    at com.jaspersoft.studio.editor.preview.view.control.ReportControler.fillReport(ReportControler.java:548)    at com.jaspersoft.studio.editor.preview.view.control.ReportControler.access$20(ReportControler.java:523)    at com.jaspersoft.studio.editor.preview.view.control.ReportControler$5.run(ReportControler.java:404)    at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)[...]Caused by: java.lang.ClassCastException: DataModel.Participant cannot be cast to DataModel.Participant    at ClassLoading_sub_ListOfRegistrations_1488207711822_474221.evaluate(ClassLoading_sub_ListOfRegistrations_1488207711822_474221:171)    at net.sf.jasperreports.engine.fill.JREvaluator.evaluate(JREvaluator.java:276)    ... 27 more[/code]

I suspect that this a sign that two different classloaders are used. I have already tried setting the classloader of the subreport excplicitly with the help of the REPORT_CLASS_LOADER and REPORT_CONTEXT parameters but not luck so far. What can I do?

Link to comment
Share on other sites

  • 3 years later...
  • Replies 1
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...