给出IllegalArgumentException的Hibernate和playframework ...不匹配类型java.util.Map

时间:2013-03-07 12:12:01

标签: java hibernate jpa playframework-2.1

当我将我的应用程序从2.0.4迁移到2.1.0时,会抛出此异常:

play.api.Application$$anon$1: Execution exception[[IllegalArgumentException: Parameter value [shared.models.Restaurant@f59fc] was not matching type [java.util.Map]]]
    at play.api.Application$class.handleError(Application.scala:289) ~[play_2.10-2.1.0.jar:2.1.0]
    at play.api.DefaultApplication.handleError(Application.scala:383) [play_2.10-2.1.0.jar:2.1.0]
    at play.core.server.netty.PlayDefaultUpstreamHandler$$anon$2$$anonfun$handle$1.apply(PlayDefaultUpstreamHandler.scala:132) [play_2.10-2.1.0.jar:2.1.0]
    at play.core.server.netty.PlayDefaultUpstreamHandler$$anon$2$$anonfun$handle$1.apply(PlayDefaultUpstreamHandler.scala:128) [play_2.10-2.1.0.jar:2.1.0]
    at play.api.libs.concurrent.PlayPromise$$anonfun$extend1$1.apply(Promise.scala:113) [play_2.10-2.1.0.jar:2.1.0]
    at play.api.libs.concurrent.PlayPromise$$anonfun$extend1$1.apply(Promise.scala:113) [play_2.10-2.1.0.jar:2.1.0]
java.lang.IllegalArgumentException: Parameter value [shared.models.Restaurant@f59fc] was not matching type [java.util.Map]
    at org.hibernate.ejb.AbstractQueryImpl.registerParameterBinding(AbstractQueryImpl.java:360) ~[hibernate-entitymanager-3.6.9.Final.jar:3.6.9.Final]
    at org.hibernate.ejb.QueryImpl.setParameter(QueryImpl.java:364) ~[hibernate-entitymanager-3.6.9.Final.jar:3.6.9.Final]
    at org.hibernate.ejb.criteria.CriteriaQueryCompiler$1$1.bind(CriteriaQueryCompiler.java:194) ~[hibernate-entitymanager-3.6.9.Final.jar:3.6.9.Final]
    at org.hibernate.ejb.criteria.CriteriaQueryCompiler.compile(CriteriaQueryCompiler.java:247) ~[hibernate-entitymanager-3.6.9.Final.jar:3.6.9.Final]
    at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:603) ~[hibernate-entitymanager-3.6.9.Final.jar:3.6.9.Final]
    at shared.dao.impl.GenericDAOImpl$QueryQuery.selectCount(GenericDAOImpl.java:273) ~[na:na]

所有modelDao都扩展了这个GenericDAOImpl。方法广告第273行是:

    Long selectCount(){
        CriteriaBuilder builder = JPA.em().getCriteriaBuilder();
        CriteriaQuery<Long> criteria = builder.createQuery(Long.class);
        Root<T> root = criteria.from( clazz );
        criteria.select(builder.count(root));
        criteria.where(buildWhere(builder, root));
        //buildSelectWhere(builder, root, criteria);
        return JPA.em().createQuery(criteria).getSingleResult();
    }

clazz变量是扩展DAO模型的.class。 在实际问题上,我有点迷茫。 在2.0.4中,这种方法很顺利。

1 个答案:

答案 0 :(得分:0)

由于Play开发人员的出色工作,这个版本已在2.1.2版中修复:

https://github.com/playframework/playframework/pull/851