jasperreports 5.6.0和Hibernate 4 NoSuchFieldError:BOOLEAN [英] jasperreports 5.6.0 and Hibernate 4 NoSuchFieldError: BOOLEAN

查看:90
本文介绍了jasperreports 5.6.0和Hibernate 4 NoSuchFieldError:BOOLEAN的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



这里是applicationContext.xml文件

 < bean id =myDataSourceclass =org.springframework.jdbc.datasource.DriverManagerDataSource> 
< property name =driverClassNamevalue =$ {driverBinder}/>
< property name =urlvalue =$ {urlBinder}/>
< property name =usernamevalue =$ {usernameBinder}/>
< property name =passwordvalue =$ {passwordBinder}/>
< / bean>

< bean id =mySessionFactoryclass =org.springframework.orm.hibernate4.LocalSessionFactoryBean>
< property name =dataSourceref =myDataSource/>

< property name =annotatedClasses>
< list>
...
< / list>
< / property>

< property name =hibernateProperties>
<道具>
< prop key =hibernate.dialect> $ {dialectBinder}< / prop>
< prop key =hibernate.show_sql> true< / prop>
< prop key =hibernate.hbm2ddl.auto> update< / prop>
< /道具>
< / property>
< / bean>

生成报表的Java类

  @Controller 
public class DefaultGenerator extends AbstractView {
$ b $ @Autowired
@Qualifier(mySessionFactory)
protected SessionFactory sessionFactory;
私有静态会话会话;
私有静态事务事务;

private static OutputStream outputStream;
私有静态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参数=(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();
}
}

不会发生任何事情。我正在成为一个错误 - java.lang.NoSuchFieldError:BOOLEAN。
这里也有描述 - http:// community.jaspersoft.com/questions/536345/jasperreports-376-and-hibernate-36-errors
看起来从Hibernate 3.6开始,就有了BOOLEAN类。但jasperreports尝试使用它...



任何人都可以帮助我,并告诉如何尽可能简单地做到这一点?我正在使用Maven,因此我的团队成员可能会更新一次库,因此我不想重新编译jasperreports库等。



谢谢。

解决方案

从jasperreports 5.6.0 pom

  ... 
< dependency>
< groupId> org.hibernate< / groupId>
< artifactId> hibernate< / artifactId>
< version> 3.0.5< / version>
< scope>编译< / scope>
<排除项>
<排除>
< groupId> javax.transaction< / groupId>
< artifactId> jta< / artifactId>
< /排除>
< /排除>
<可选> true< /可选>
< /依赖关系>
...

它引入了hibernate 3.



这是JasperReports 5.6.0中类的一个片段,其中jasperreports试图找到hibernate.BOOLEAN类。

  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;
$ b / **
*使用Hibernate的HQL查询执行器3.
*
* @author Lucian Chirita(lucianc@users.sourceforge.net)
* @version $ Id:JRHibernateQueryExecuter.java 7199 2014-08-27 13:58:10Z teodord $
* /
公共类JRHibernateQueryExecuter扩展JRAbstractQueryExecuter
{
private static final日志日志= LogFactory.getLog(JRHibernateQueryExecuter.class);

保护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);
...

只要您尝试使用该版本的JRHibernateQueryExecutor,您就是将被限制在Hibernate 3.0中。



在这里你可以看到 JRHibernateQueryExecutor的历史



我相信您需要此更改为了支持更新的hibernate版本。



该更改已于2015年6月提交。



在mvnrepository.com上的 jasperreports发行版的历史记录,您将看到6.1。 1是fi首先发布到maven,其中可能包括使用更新版本的hibernate所需的更改。



我只是在Hibernate 4中使用5.6.0(也是6.1.0)并重复你的错误。然后我尝试使用6.1.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.

解决方案

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 (lucianc@users.sourceforge.net)
 * @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.

这篇关于jasperreports 5.6.0和Hibernate 4 NoSuchFieldError:BOOLEAN的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆