简体   繁体   English

将 Hibernate 连接与 JasperReports 结合使用

[英]Using Hibernate connection with JasperReports

I'm making now a new module into a big one web application.我现在正在将一个新模块制作成一个大型 Web 应用程序。 I've created in iReport a report with Hibernate Connection.我在iReport 中创建了一个带有 Hibernate Connection 的报告。 All Hibernate classes were already made by my teammates, hql query also.我的队友已经制作了所有 Hibernate 课程,hql 查询也已完成。 So, we can say, I've made only "visual" part in designer.所以,我们可以说,我在设计师中只制作了“视觉”部分。

In iReport all works great, like I wanted.iReport 中,一切都很好,就像我想要的那样。 I'm using hibernate.cfg.xml file where session factory is defined.我正在使用 hibernate.cfg.xml 文件,其中定义了会话工厂。

My problem began when I wanted to integrate my *.jrxml file with java web app.当我想将 *.jrxml 文件与 java web 应用程序集成时,我的问题就开始了。 Web application is made on maven using Spring Framework. Web 应用程序是使用 Spring Framework 在 Maven 上制作的。 So I have additional file applicationContext.xml where hibernate session factory is also defined like in hibernate.cfg.xml.所以我有额外的文件 applicationContext.xml,其中也像 hibernate.cfg.xml 一样定义了休眠会话工厂。

The question is, is it possible to make it's working, using @autowired on bean from applicationContext.xml?问题是,是否可以在 applicationContext.xml 中的 bean 上使用 @autowired 使其正常工作?

@Autowired
@Qualifier("binderSessionFactory")
protected SessionFactory sessionFactory;

If yes, how could I give this connection so it work's with my *.jrxml file?如果是,我怎么能提供这个连接,以便它与我的 *.jrxml 文件一起工作?

Java code:爪哇代码:

OutputStream outputStream = response.getOutputStream();

Map parameters = (Map) model.get("parameters");

URL reportTemplate = getClass().getClassLoader().getResource("pathToFile/file.jrxml");
JasperReport jasperReport = JasperCompileManager.compileReport(reportTemplate.getPath());
jasperPrint = JasperFillManager.fillReport(jasperReport, parameters);

JasperExportManager.exportReportToPdfStream(jasperPrint, outputStream);

How should I make a hibernate db connection visible for my report?我应该如何使我的报告可见的休眠数据库连接?

To answer you first question, yes it is possible.要回答你的第一个问题,是的,这是可能的。 Please refer to this links for the required configuration needed for the JasperReports-Hibernate integration: JasperReports 5.6.0 - Hibernate Sample and有关 JasperReports-Hibernate 集成所需的配置,请参阅此链接: JasperReports 5.6.0 - Hibernate Sample
Using Hibernate queries in JasperReports在 JasperReports 中使用 Hibernate 查询
While this last link is shows the specific requirement for Spring: JasperReports - Spring MVC虽然最后一个链接显示了 Spring 的具体要求: JasperReports - Spring MVC
Hope these helps.希望这些有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM