Maksym Kreshchyshyn
Maksym Kreshchyshyn

Reputation: 354

Why do I get java.lang.NoSuchMethodError when using Hibernate 5.2.8 with JasperReports 6.4.0

I'm developing web-application project which is using Apache Tomcat, Spring and Hibernate. It also uses JasperReports v.6.4.0 to generate pdf-reports. Recently, the versions of Spring and Hibernate were updated from 3.1.2 to 4.3.6 for Spring and from 3.3.1 to 5.2.8 for Hibernate.

Every problem that came after migration was solved except one. When reports with hql-queries are generated the following exception is thrown:

java.lang.NoSuchMethodError: org.hibernate.Session.createQuery(Ljava/lang/String;)Lorg/hibernate/Query;
at net.sf.jasperreports.engine.query.JRHibernateQueryExecuter.createQuery(JRHibernateQueryExecuter.java:279)
at net.sf.jasperreports.engine.query.JRHibernateQueryExecuter.createDatasource(JRHibernateQueryExecuter.java:195)
at net.sf.jasperreports.engine.fill.JRFillDataset.createQueryDatasource(JRFillDataset.java:1245)
at net.sf.jasperreports.engine.fill.JRFillDataset.initDatasource(JRFillDataset.java:723)
at net.sf.jasperreports.engine.fill.BaseReportFiller.setParameters(BaseReportFiller.java:438)
at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:550)
at net.sf.jasperreports.engine.fill.BaseReportFiller.fill(BaseReportFiller.java:396)
at net.sf.jasperreports.engine.fill.JRFiller.fill(JRFiller.java:90)
at net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java:456)
at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:863)

Before upgrading, JasperReports v.6.4.0 was working fine with Hibernate v.3.3.1. Can anybody help me to avoid this problem?

Upvotes: 1

Views: 1211

Answers (3)

James Clayton
James Clayton

Reputation: 243

Once you have created your own version of JRHibernateQueryExecuter & JRHibernateQueryExecuterFactory you can register them to be used by invoking

JasperReportsContext jasperReportsContext = DefaultJasperReportsContext.getInstance();
JRPropertiesUtil jrPropertiesUtil = JRPropertiesUtil.getInstance(jasperReportsContext);
jrPropertiesUtil.setProperty("net.sf.jasperreports.query.executer.factory.hql", "net.sf.jasperreports.engine.query.h5.JRHibernateQueryExecuterFactory");
jrPropertiesUtil.setProperty("net.sf.jasperreports.query.executer.factory.HQL", "net.sf.jasperreports.engine.query.h5.JRHibernateQueryExecuterFactory");

I am not sure why Jaspersoft have not implemented a fix themselves. It really is a simple change to start supporting the later version of hibernate correctly.

Upvotes: 0

Maksym Kreshchyshyn
Maksym Kreshchyshyn

Reputation: 354

I had followed the advice given by @PetterFriberg and had written a little library that makes possible using Hibernate 5 with JasperReports 6.

Sources and instructions can be found here: JasperReports6-Hibernate5

Upvotes: 2

Petter Friberg
Petter Friberg

Reputation: 21710

The JRHibernateQueryExecuter in jasper-reports v.6.4.0 is depending on hibernate v. 3.3.2.GA.

The difference is that in Hibernate 5.2, the Query class moved from org.hibernate to org.hibernate.query

So what is the solution?

To use JRHibernateQueryExecuter you need hibernate v. 3.3.2 in classpath, so either you revert back or you develop your own JRHibernateQueryExecuter and JRHibernateQueryExecuterFactory that depends on Hibernate 5.2.8.

Developing your own JRHibernateQueryExecuter is probably not as difficult as it may sound since the source code is available, you would probably just need to tweak the imports.

To register your "new" QueryFactory see: How I can associate a query language with my executer in Jaspersoft studio?

Upvotes: 4

Related Questions