2

I created a Hibernate Session data adapter in Jaspersoft Studio from a Hibernate configuration file (hibernate.cfg.xml) that works correctly on a very simple JSF application.

When I test the adapter in Jaspersoft Studio I get an InvocationTargetException because one of the resources is not found.

These are the contents of the configuration file:

<hibernate-configuration>
  <session-factory>
    <property name="hibernate.dialect">org.hibernate.dialect.OracleDialect</property>
    <property name="hibernate.connection.driver_class">oracle.jdbc.OracleDriver</property>
    <property name="hibernate.connection.url">jdbc:oracle:thin:@localhost:1521:XE</property>
    <property name="hibernate.connection.username">course</property>
    <property name="hibernate.connection.password">course</property>
    <mapping resource="com/standoutdev/jasper/Employee.hbm.xml"/>
    <mapping resource="com/standoutdev/jasper/Department.hbm.xml"/>
  </session-factory>
</hibernate-configuration>

Both resources (Employee and Department) exist in the relative path specified in the above configuration, but Jaspersoft Studio doesn't find them. I have tried specifying the absolute path to the resouces in the configuration but it doesn't solve the problem. I have also tried moving all the files to the same path where the configuration file resides, and removing the path from the configuration file, but it didn't help either.

This is what the official documentation about Hibernate data adapters says:

" JasperReports provides a way to use HQL directly in your report. To do so, first set up a Hibernate connection. Expand your classpath to include all classes, JARs, and configuration files used by your Hibernate mapping. In other words, Jaspersoft Studio must be able to access all the .hbm.xml files you plan to use, the JavaBeans declared in those files, the hibernate.cfg.xml file, and any other JARs used (for example, JARs that access the database under Hibernate). "

But, the data adapter wizard doesn't provide a method to add a classpath for Hibernate Session data adapters, and the example used in the documentation doesn't make sense to me, as it is an example of an hibernate data adapter but the image actually shows a wizard where a JDBC data adapter is being created (which does have a classpath option).

I have tried manually adding a tag to the adapter's XML file to define the path, but it didn't make any difference.

Can someone shed some light on this?

This is the stacktrace I get when testing the adapter:

net.sf.jasperreports.engine.JRException: java.lang.reflect.InvocationTargetException
at net.sf.jasperreports.data.hibernate.HibernateDataAdapterService.contributeParameters(HibernateDataAdapterService.java:138)
at net.sf.jasperreports.data.AbstractDataAdapterService.test(AbstractDataAdapterService.java:122)
at com.jaspersoft.studio.data.DataAdapterEditorPart$1.widgetSelected(DataAdapterEditorPart.java:170)
at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:248)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4362)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1113)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4180)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3769)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$4.run(PartRenderingEngine.java:1127)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:337)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1018)
at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:156)
at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:694)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:337)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:606)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:150)
at com.jaspersoft.studio.rcp.intro.Application.start(Application.java:99)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:134)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:380)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:235)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:669)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:608)
at org.eclipse.equinox.launcher.Main.run(Main.java:1515)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.GeneratedMethodAccessor78.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at net.sf.jasperreports.data.hibernate.HibernateDataAdapterService.contributeParameters(HibernateDataAdapterService.java:94)
... 29 more
Caused by: org.hibernate.MappingNotFoundException: resource: com/standoutdev/jasper/Employee.hbm.xml not found
at org.hibernate.cfg.Configuration.addResource(Configuration.java:610)
at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1635)
at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1603)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1582)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1556)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1510)
... 33 more

Since I failed to make this work as a standalone adapter, I tried creating a project, and creating the adapter as part of the project, with the hope that the ability to define a classpath for the project would help me solve the problem, but when doing it this way, I now get a different exception, related to the databse driver.

The resources, hibernate configuration files, mapped classes and Oracle JDBC driver are all in the project's classpath, but Jaspersoft Studio complains that there is no suitable driver to connect to the database.

If a JDBC adapter is created in the same project, using the same JDBC driver, the connection is successful.

I'm using:

  • Jaspersoft Studio Community ver 6.4.0.final
  • Oracle Database Express Edition Version 11.2.0.2.0 - 64bit
  • Oracle JDBC Driver Version 11.2.0.2.0 (ojdbc6.jar)

And this is the stacktrace I get:

net.sf.jasperreports.engine.JRException: java.lang.reflect.InvocationTargetException
at net.sf.jasperreports.data.hibernate.HibernateDataAdapterService.contributeParameters(HibernateDataAdapterService.java:138)
at net.sf.jasperreports.data.AbstractDataAdapterService.test(AbstractDataAdapterService.java:122)
at com.jaspersoft.studio.data.DataAdapterEditorPart$1.widgetSelected(DataAdapterEditorPart.java:166)
at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:249)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4418)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1079)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4236)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3824)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$4.run(PartRenderingEngine.java:1121)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:336)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1022)
at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:150)
at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:693)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:336)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:610)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:148)
at com.jaspersoft.studio.rcp.intro.Application.start(Application.java:91)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:134)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:388)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:243)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:673)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:610)
at org.eclipse.equinox.launcher.Main.run(Main.java:1519)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at net.sf.jasperreports.data.hibernate.HibernateDataAdapterService.contributeParameters(HibernateDataAdapterService.java:119)
... 29 more
Caused by: org.hibernate.exception.JDBCConnectionException: Cannot open connection
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:97)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:52)
at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:449)
at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:167)
at org.hibernate.jdbc.JDBCContext.connection(JDBCContext.java:142)
at org.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:85)
at org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1354)
... 34 more
Caused by: java.sql.SQLException: No suitable driver found for jdbc:oracle:thin:@localhost:1521:XE
at java.sql.DriverManager.getConnection(DriverManager.java:689)
at java.sql.DriverManager.getConnection(DriverManager.java:208)
at org.hibernate.connection.DriverManagerConnectionProvider.getConnection(DriverManagerConnectionProvider.java:133)
at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:446)
... 38 more

Any kind of comment or suggestion would be very welcome.

Thanks,

Alex K
  • 22,315
  • 19
  • 108
  • 236

0 Answers0