title: Using Hibernate connection with JasperReports
body: <p>I'm making now a new module into a big one web application. I've created in <em>iReport</em> a report with Hibernate Connection. All Hibernate classes were already made by my teammates, hql query also. So, we can say, I've made only "visual" part in designer.</p>
  
  <p>In <em>iReport</em> all works great, like I wanted. I'm using hibernate.cfg.xml file where session factory is defined.</p>
  
  <p>My problem began when I wanted to integrate my *.jrxml file with java web app.
  Web application is made on maven using Spring Framework. So I have additional file applicationContext.xml where hibernate session factory is also defined like in hibernate.cfg.xml.</p>
  
  <p>The question is, is it possible to make it's working, using @autowired on bean from applicationContext.xml?</p>
  
  <pre><code>@Autowired
  @Qualifier("binderSessionFactory")
  protected SessionFactory sessionFactory;
  </code></pre>
  
  <p>If yes, how could I give this connection so it work's with my *.jrxml file?</p>
  
  <p>Java code:</p>
  
  <pre><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);
  </code></pre>
  
  <p>How should I make a hibernate db connection visible for my report?</p>