Jaspersoft Studio中的Hibernate会话数据适配器

时间:2017-09-28 04:22:29

标签: hibernate jasper-reports jaspersoft-studio

我在一个Hibernate配置文件(hibernate.cfg.xml)中在Jaspersoft Studio中创建了一个Hibernate Session数据适配器,该文件可以在一个非常简单的JSF应用程序上正常工作。

当我在Jaspersoft Studio中测试适配器时,我得到一个InvocationTargetException,因为找不到其中一个资源。

这些是配置文件的内容:

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

两个资源(Employee和Department)都存在于上述配置中指定的相对路径中,但Jaspersoft Studio找不到它们。我已经尝试在配置中指定资源的绝对路径,但它没有解决问题。我还尝试将所有文​​件移动到配置文件所在的同一路径,并从配置文件中删除路径,但它也没有帮助。

这是the official documentation about Hibernate data adapters所说的:

JasperReports提供了一种在报表中直接使用HQL的方法。为此,首先设置Hibernate连接。展开类路径以包含Hibernate映射使用的所有类,JAR和配置文件。换句话说,Jaspersoft Studio必须能够访问您计划使用的所有.hbm.xml文件,在这些文件中声明的JavaBeans,hibernate.cfg.xml文件以及使用的任何其他JAR(例如,访问的JAR) Hibernate下的数据库。

但是,数据适配器向导没有提供为Hibernate Session数据适配器添加类路径的方法,文档中使用的示例对我没有意义,因为它是一个hibernate数据适配器的示例但是图像实际上显示了一个创建JDBC数据适配器的向导(它有一个类路径选项)。

我已尝试手动将标记添加到适配器的XML文件以定义路径,但它没有任何区别。

有人可以对此有所了解吗?

这是我在测试适配器时得到的堆栈跟踪:

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

由于我没有将这项工作作为一个独立的适配器,我尝试创建一个项目,并创建适配器作为项目的一部分,希望为项目定义类路径的能力将帮助我解决问题,但是当这样做时,我现在得到一个与数据库驱动程序相关的不同异常。

资源,hibernate配置文件,映射类和Oracle JDBC驱动程序都在项目的类路径中,但Jaspersoft Studio抱怨没有合适的驱动程序连接到数据库。

如果在同一项目中使用相同的JDBC驱动程序创建JDBC适配器,则连接成功。

我正在使用:

  • Jaspersoft Studio Community ver 6.4.0.final
  • Oracle Database Express Edition版本11.2.0.2.0 - 64位
  • Oracle JDBC驱动程序版本11.2.0.2.0(ojdbc6.jar)

这是我得到的堆栈跟踪:

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

非常欢迎任何形式的评论或建议。

谢谢,

0 个答案:

没有答案