Jump to content
We've recently updated our Privacy Statement, available here ×

Can\'t configurate => Hibernate+iReport 3.5.2


altairon

Recommended Posts

hi , I don' t why it doesn't work this. when I try to setup a new conecction using hibernate  . before the I configured the classpath , pointing to the mapping field, java fields and the mysql JDB driver  , but when I try to establish the connection , it show "entity class not found: modelo.Personal" , what I know is that my hibernate configuration is ok , there are my classpath and my error like image , :S , sorry for my english , I'm just learning , thank you...

 

Link to comment
Share on other sites

  • Replies 6
  • Created
  • Last Reply

Top Posters In This Topic

I just put my model clasess fields in a jar , but I think I doesn´t work , by the way , do yo know what's the diferences  betewen a jrxml genereted from Database JDBC Connection and another genereted from Hibernate conncetion .

What I try to Do is no make a report using JasperReport and Hibernate , and I guess the the JRXML must be genereted from using a Hibernate Configuration in IReport , I don't know :S , thank you

 

 


Code:
List lista = new ArrayList();        session = HibernateUtil.getSessionFactory().getCurrentSession();        session.beginTransaction();        lista=session.createCriteria(Personal.class).list();        session.getTransaction().commit();        JasperReport jasperReport;        JasperPrint jasperPrint;        try {           jasperReport = JasperCompileManager.compileReport("C:/pruebas/report.j rxml");         JRBeanCollectionDataSource  ds = new JRBeanCollectionDataSource(lista);          jasperPrint = JasperFillManager.fillReport(jasperReport, new HashMap(), ds);         JasperExportManager.exportReportToPdfFile(jasperPrint, "C:/pruebas/simple_report.pdf");          }                  catch (Exception e) {           e.printStackTrace();           }
Link to comment
Share on other sites

I'm not sure I got what you are saying.

Anyway, there are several ways to use Hibernate. The sample code you posted just use a BeanCollection datasource which is not something strictly related to Hibernate. When you setup an Hibernate connection, you are supposed to use an HQL query (exactly like when you use a JDBC connection, you are supposed to get your data using an SQL query).

The difference is only in the way the mapping of the query result and the fields is performed, since an SQL query is pretty flat (it's just a list of fields), while an Hibernate query can return objects, and you may want to map as field of the report attributes of that objects.

This is a try you can do to check if your classpath is correctly set:  put in a textfield the expression:

modelo.Personal.class.getName()

If the class is found you should see the class name printed in the report.

What version of iReport are you using?

Giulio

Link to comment
Share on other sites

I don`t what's wrong , version of ireport 3.5.2 , maybe you can make one example using this version and post la correct classpath  XD using a hibernate configuration in ireport, because I was following several tutorials ,but nothing, thank you anyway, but the way , what dou you use instead of JRBeanCollectionDataSource ?

Link to comment
Share on other sites

In iReport I set the HQL query without executing my query outside iReport. JasperReports has built-in support for HQL.
I.e. you can set as report query:  "from Personal" to have what you need. iReport provides a powerful mapping tool to map the result of this query in the report fields (in that case is easy, since the query just return a java bean..., but for complex queries, you may want more sophisticated mapping).

In your application the report execution will look like:
 

SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
Session session = sessionFactory.openSession();
Map parameters = new HashMap();
parameters.put(JRHibernateQueryExecuterFactory.PARAMETER_HIBERNATE_SESSION, session);

JasperPrint print = JasperFillManager.fillReport("myreport.jasper", params);

In iReport you define the HQL query in the same place where you define an sQL query, just set the language to hql and be sure an Hibernate connection is active.

A sample is available inside the JasperReports distribution:

jasperreports\demo\samples\hibernate

Giulio

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...