Reputation: 1
I'm building web app based on maven, using spring, hibernate and jasperreports.
Here is applicationContext.xml file
<bean id="myDataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="${driverBinder}" />
<property name="url" value="${urlBinder}" />
<property name="username" value="${usernameBinder}" />
<property name="password" value="${passwordBinder}" />
</bean>
<bean id="mySessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="myDataSource"/>
<property name="annotatedClasses">
<list>
...
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${dialectBinder}</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
</props>
</property>
</bean>
Java class that generates report
@Controller
public class DefaultGenerator extends AbstractView {
@Autowired
@Qualifier("mySessionFactory")
protected SessionFactory sessionFactory;
private static Session session;
private static Transaction transaction;
private static OutputStream outputStream;
private static JasperPrint jasperPrint;
@Override
protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws Exception {
session = sessionFactory.openSession();
transaction = session.beginTransaction();
outputStream = response.getOutputStream();
HashMap parameters = (HashMap) model.get("parameters");
parameters.put(JRHibernateQueryExecuterFactory.PARAMETER_HIBERNATE_SESSION, session);
URL reportTemplate = getClass().getClassLoader().getResource("someFile.jrxml");
JasperReport jasperReport = JasperCompileManager.compileReport(reportTemplate.getPath());
jasperPrint = JasperFillManager.fillReport(jasperReport, parameters);
transaction.rollback();
session.close();
render(new JRPdfExporter());
}
private void render(Exporter exporter) throws JRException {
List<JasperPrint> jasperPrintList = new ArrayList<>();
jasperPrintList.add(jasperPrint);
exporter.setExporterInput(SimpleExporterInput.getInstance(jasperPrintList));
exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(outputStream));
exporter.exportReport();
}
}
And happens nothing. I'm becoming an error - java.lang.NoSuchFieldError: BOOLEAN. It's also described here - http://community.jaspersoft.com/questions/536345/jasperreports-376-and-hibernate-36-errors Looks like since version 3.6 of Hibernate there is class BOOLEAN anymore there. But jasperreports try to use it...
Can any one help me please and tell how to do it as much as possible simply? I'm using Maven so it's possible that my team mates will update libraries once so I don't want to recompile jasperreports library or so.
Thank.
Upvotes: 0
Views: 1444
Reputation: 2091
From the jasperreports 5.6.0 pom
...
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate</artifactId>
<version>3.0.5</version>
<scope>compile</scope>
<exclusions>
<exclusion>
<groupId>javax.transaction</groupId>
<artifactId>jta</artifactId>
</exclusion>
</exclusions>
<optional>true</optional>
</dependency>
...
It does bring in hibernate 3.
This is a snippet from a class in JasperReports 5.6.0 where jasperreports is trying to find that hibernate.BOOLEAN class.
import org.hibernate.Hibernate;
import org.hibernate.Query;
import org.hibernate.ScrollMode;
import org.hibernate.ScrollableResults;
import org.hibernate.Session;
import org.hibernate.type.Type;
/**
* HQL query executer that uses Hibernate 3.
*
* @author Lucian Chirita ([email protected])
* @version $Id: JRHibernateQueryExecuter.java 7199 2014-08-27 13:58:10Z teodord $
*/
public class JRHibernateQueryExecuter extends JRAbstractQueryExecuter
{
private static final Log log = LogFactory.getLog(JRHibernateQueryExecuter.class);
protected static final String CANONICAL_LANGUAGE = "HQL";
private static final Map<Class<?>,Type> hibernateTypeMap;
static
{
hibernateTypeMap = new HashMap<Class<?>,Type>();
hibernateTypeMap.put(Boolean.class, Hibernate.BOOLEAN);
hibernateTypeMap.put(Byte.class, Hibernate.BYTE);
hibernateTypeMap.put(Double.class, Hibernate.DOUBLE);
hibernateTypeMap.put(Float.class, Hibernate.FLOAT);
hibernateTypeMap.put(Integer.class, Hibernate.INTEGER);
...
As long as you are trying to use that version of JRHibernateQueryExecutor you are going to be limited to Hibernate 3.0.
Here you can see the history of JRHibernateQueryExecutor in JasperReports development tree.
I believe you would need this change in order to support newer hibernate versions.
That change was submitted in June of 2015.
If you look at the history of the jasperreports releases at mvnrepository.com you'll see that 6.1.1 is the first release to maven that could include the change you need to use newer versions of hibernate.
I just tried using 5.6.0 (and also 6.1.0) with Hibernate 4 and duplicated your error. I then tried using 6.1.1 and that error disappeared.
Upvotes: 0
Reputation: 1
Like is written here http://jasperreports.sourceforge.net/sample.reference/hibernate/
One of these middle-tier tools dedicated to data access is Hibernate (today: Hibernate 3.3) (...)
... is it possible that newest jasperreports 5.6 believes that actual version of hibernate is 3.3 and not 4.3? oO
Two weeks working on a solution and nothing :/
Upvotes: 0