简体   繁体   English

引起:java.lang.IllegalArgumentException:不是实体:

[英]Caused by: java.lang.IllegalArgumentException: Not an entity:

I am working on an app with Hibernate 5.6, Spring 5.3 and we use xml-based configuration + Hibernate mapping files.hbm.xml for each entity. I am working on an app with Hibernate 5.6, Spring 5.3 and we use xml-based configuration + Hibernate mapping files.hbm.xml for each entity. We did not annotate model classes.我们没有注释 model 类。

After migrating from Hibernate 3 to 5.6, we had to use the Springs transactionManager, which workes fine so far.从 Hibernate 3 迁移到 5.6 后,我们不得不使用 Springs 事务管理器,它目前运行良好。 But since the Hibernate Criteria API is deprecated, I tried to migrate some of the Criteria API request to CriteriaBuilder and set up some boilerplate code.但由于 Hibernate 标准 API 已被弃用,我尝试将一些标准 API 请求迁移到 CriteriaBuilder 并设置一些样板代码。

public List<ENTITY> findByCriteria(final Map<String, Object> criteriaMap, final List<String> fields, final Class<ENTITY> entityClass) {
    CriteriaBuilder cb = this.getSession().getCriteriaBuilder();
    CriteriaQuery<ENTITY> cq = cb.createQuery(entityClass);
    Root<ENTITY> root = cq.from(entityClass);
...

But when I execute the code, the last line throws me this error:但是当我执行代码时,最后一行向我抛出了这个错误:

Caused by: java.lang.IllegalArgumentException: Not an entity: interface com.myapp.pm.common.business.PmPropertyVO
        at deployment.myapp-clienta.war//org.hibernate.metamodel.internal.MetamodelImpl.entity(MetamodelImpl.java:567)
        at deployment.myapp-clienta.war//org.hibernate.query.criteria.internal.QueryStructure.from(QueryStructure.java:128)
        at deployment.myapp-clienta.war//org.hibernate.query.criteria.internal.CriteriaQueryImpl.from(CriteriaQueryImpl.java:158)
        at deployment.myapp-clienta.war//com.myapp.integration.dao.impl.CommonHibernateDAOImpl.findByCriteria(CommonHibernateDAOImpl.java:554)
        ...

My configuration looks like this:我的配置如下所示:

<bean id="sessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
        <property name="mappingLocations" value="classpath*:/com/*/*/**/integration/hbm/*.hbm.xml" />       
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">${hibernate.dialect}</prop>
                <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
                <prop key="hibernate.format_sql">${hibernate.format_sql}</prop>
                <prop key="hibernate.cglib.use_reflection_optimizer">${hibernate.cglib.use_reflection_optimizer}</prop>             
                <prop key="hibernate.jdbc.batch_size">${hibernate.jdbc.batch_size}</prop>
                <prop key="hibernate.connection.release_mode">${hibernate.connection.release_mode}</prop>                       
            </props>
        </property>
        <property name="dataSource" ref="dataSource"/>
    </bean>

I tried to add another property, but that did not help:我试图添加另一个属性,但这没有帮助:

<property name="packagesToScan" value="classpath*:/com/*/*/**/integration/hbm/*.hbm.xml" />

The mapping file for the Entity:实体的映射文件:

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
    <class name="com.myapp.business.impl.PmPropertyVOImpl" table="pm_t_property" proxy="com.myapp.pm.common.business.PmPropertyVO">
        <id name="rowguid" column="rowguid" type="java.lang.Long">
            <generator class="sequence">
                <param name="sequence_name">pm_t_property_rowguid_seq</param>
            </generator>
        </id>               
        <property name="key" type="java.lang.String" column="py_key" not-null="true" /> 
        <property name="value" type="java.lang.String" column="py_value" not-null="true" /> 
        <property name="description" type="java.lang.String" column="py_description" not-null="false" /> 
        <property name="owner" type="java.lang.String" column="py_owner" not-null="true" />
        <property name="type" type="java.lang.String" column="py_type" not-null="false" />       
        
        <property name="creationDate" type="timestamp" column="py_creation_date" /> 
        <property name="creationUser" type="java.lang.String" column="py_creation_user" />  
        <property name="modificationDate" type="timestamp" column="py_modification_date" /> 
        <property name="modificationUser" type="java.lang.String" column="py_modification_user" />                                
    </class>    
</hibernate-mapping>

My question: is it mandatory to use the persistence.xml file when using the CriteriaBuilder?我的问题:使用 CriteriaBuilder 时是否必须使用 persistence.xml 文件? We did not use this kind of configuration before, just plain Hibernate configs.我们之前没有使用过这种配置,只是简单的 Hibernate 配置。

Edit: After comment from Alexander Kashpirovsky I tried to change this line to get the implementation instead of interface class.编辑:在 Alexander Kashpirovsky 发表评论后,我尝试更改此行以获取实现而不是接口 class。 But all I get is a reference to java.lang.class但我得到的只是对 java.lang.class 的引用

CriteriaQuery cq = cb.createQuery(entityClass.getClass());

在此处输入图像描述

Variable entityClass equals to com.myapp.business.impl.PmPropertyVOImpl or com.myapp.pm.common.business.PmPropertyVO ?变量entityClass等于com.myapp.business.impl.PmPropertyVOImplcom.myapp.pm.common.business.PmPropertyVO

Must be com.myapp.business.impl.PmPropertyVOImpl必须是com.myapp.business.impl.PmPropertyVOImpl

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 引起:java.lang.illegalArgumentException - Caused by: java.lang.illegalArgumentException 引起:java.lang.IllegalArgumentException: Entity must have id - Caused by: java.lang.IllegalArgumentException: Entity must has id 计时器计划由:java.lang.IllegalArgumentException - Timer schedule Caused by: java.lang.IllegalArgumentException 原因:java.lang.IllegalArgumentException:不是托管类型:&原因:org.hibernate.AnnotationException:未为实体指定标识符: - Caused by: java.lang.IllegalArgumentException: Not a managed type: & Caused by: org.hibernate.AnnotationException: No identifier specified for entity: java.lang.IllegalArgumentException:未知实体:Jpa - java.lang.IllegalArgumentException: Unknown entity: Jpa JPA - java.lang.IllegalArgumentException:不是实体:类 - JPA - java.lang.IllegalArgumentException: Not an entity: class JPA:java.lang.IllegalArgumentException:不是实体 - JPA: java.lang.IllegalArgumentException: Not an entity 引发的Java weblogic错误:java.lang.IllegalArgumentException - Java weblogic error with Caused by: java.lang.IllegalArgumentException 原因:java.lang.IllegalArgumentException: error at::0 切入点中的正式未绑定 - Caused by: java.lang.IllegalArgumentException: error at ::0 formal unbound in pointcut 引起:java.lang.IllegalArgumentException:索引 120 处查询中的非法字符 - Caused by: java.lang.IllegalArgumentException: Illegal character in query at index 120
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM