Jump to content
Changes to the Jaspersoft community edition download ×

Hibernate: SubDatasets, Crosstabs and Charts


Recommended Posts

By: ankr - ankr

Hibernate: SubDatasets, Crosstabs and Charts

2006-04-12 01:30

Hi.

Can anyone tell me what I have to specify as DataSourceExpression or ConnectionExpression when I want to use the data of a Sub Dataset in a Crosstab or Chart? When using JDBC, it works fine (setting the ConnectionExpression to $P{REPORT_CONNECTION}. But when using Hibernate, I get an Exception ("the supplied hibernate Session object is null").

 

Thanks

 

Andri

 

 

 

 

By: ankr - ankr

RE: Hibernate: SubDatasets, Crosstabs and Charts

2006-04-12 01:38

btw: Hibernate basically works fine if I use only a single main report query, but the problems arise as soon as I define a SubDataset with its own specific HQL-query and try to access this SubDataset in a chart element.

 

 

 

 

By: Lucian Chirita - lucianc

RE: Hibernate: SubDatasets, Crosstabs and Cha

2006-04-12 09:43

Hi

 

You need to pass a value for the HIBERNATE_SESSION parameter:

<datasetParameter name="HIBERNATE_SESSION">

<datasetParameterExpression>...</datasetParameterExpression>

</datasetParameter>

 

HTH,

Lucian

 

 

 

 

By: ankr - ankr

RE: Hibernate: SubDatasets, Crosstabs and Charts

2006-04-13 05:08

Thanks, Lucian, this works.

But my problem now is, that JasperReports uses its built-in Hibernate JRDatasource for SubDatasets/Charts. I have my own Hibernate-JRDatasource-Implementation which provides some additional features. I pass my datasource to the FillManager:

 

JasperFillManager.fillReport(jasperReport, parameters,getJRDataSource());

 

I would like JasperReports to use my implementation of JRDataSource not only for the main report-query, but for the SubDataset-Queries also. Is there a way to pass a DS-factory to JasperReports or to set the DS for each SubDataset at report creation time?

 

 

 

 

 

 

By: Lucian Chirita - lucianc

RE: Hibernate: SubDatasets, Crosstabs and Cha

2006-04-13 05:45

You can use dataSourceExpression to pass any datasource to the sub dataset. Therefore you can pass your datasource factory or your datasource as a parameter to the main report and use it inside dataSourceExpression.

 

HTH,

Lucian

 

 

 

 

By: ankr - ankr

RE: Hibernate: SubDatasets, Crosstabs and Charts

2006-04-19 00:31

Lucian, thanks. I have introduced a report parameter 'dsFactory' for my factory and I use $P{dsFactory}.createDataSource("SubDatasetName") as Data Source Expression in the Crosstab/Chart. It works, but with limitations (I cannot access the parameter values of the SubDataset, because they are instanceof JRBaseParameter, not FillParameter, so I cannot use dynamic parameters e.g. field values of the main query when my SubDataset chart is in the Details-Band and I pass the field value to the SubDataset as a DataSet Run Parameter).

 

I'd probably rather use your built-in HibernateDataSource for SubDatasets and use my own implementation only for simple reports or for the main report query.

 

Here's the reason I prefered my own Hibernate DataSource-Implementation (I don't see how I could achieve this goal without implementing an own extended Datasource):

I want to support optional parameters. Example: If an optional parameter is not set (i.e. 'null'), all related query clauses (WHERE or GROUP BY etc) are omitted at runtime.

Example:

select e.id

from Example e

where e.attribute1 = $P{attr1}

and e.attribute2 > $P{attr2Min}

and e.attribute2 < $P{attr2Max}

 

Now, depending on whether the parameters values are set, the query is modified (simplified). I don't want to create different reports for all kinds of parameter combinations. StillI want to keep the query inside the jrxml-file, so I can design and test the reports with iReport and deploy reports easily.

The distinction (which parameters are optional and which are mandatory) and which parts of the query are to be ignored if a certain optional parameter is null, is defined by indentation - so the query remains a syntactically correct hql query which also runs correctly with the default hql ds implementation (given in this case that none of the parameters are null).

 

Would there be another (easier) way to introduce optional parameters?

 

Anyway, thanks for your help and thanks for your work on JasperReports

 

 

Andri

Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

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...