错误“由于<myclass>不是实体,因此无法将其选择为条件的根”

时间:2019-05-13 14:58:18

标签: jpa ejb entity

我遇到以下错误:

“由于类不是实体,因此不能将其选择为条件查询的根。”

我用@ Entity,@ Table注释了该类,并将该实体注册在persistence.xml中。

从Entity类创建Root对象时出现错误:

Root<ConfigurazioniEntity> root = cq.from(ConfigurazioniEntity.class);

实体类:

package it.convalida.nazionale.core.entity;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name = ConfigurazioniEntity.TABLE_NAME)
public class ConfigurazioniEntity implements BaseEntity {

    private static final long serialVersionUID = 6651666466423423207L;

    public static final String TABLE_NAME = "PRA_CONFIG_DL98";

    @Id
    @Column(name = "ID_PRA_CONFIG", nullable = false, updatable = false)
    private Long idPraConfig;

    @Column(name = "NOME_PARAM")
    private String nomeParam;

    @Column(name = "VALORE_PARAM")
    private String valoreParam;

    /**
     * 1 = ATTIVO, 0 = NON ATTIVO
     */
    @Column(name = "ATTIVO")
    private String attivo;

    public Long getIdPraConfig() {
        return idPraConfig;
    }

    public void setIdPraConfig(Long idPraConfig) {
        this.idPraConfig = idPraConfig;
    }

    public String getNomeParam() {
        return nomeParam;
    }

    public void setNomeParam(String nomeParam) {
        this.nomeParam = nomeParam;
    }

    public String getValoreParam() {
        return valoreParam;
    }

    public void setValoreParam(String valoreParam) {
        this.valoreParam = valoreParam;
    }

    public String getAttivo() {
        return attivo;
    }

    public void setAttivo(String attivo) {
        this.attivo = attivo;
    }

}

persistence.xml

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0"
    xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
    <persistence-unit name="convalidaNazionalePersistentUnit" transaction-type="JTA">
        <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
        <jta-data-source>jdbc/convalidaNazionale</jta-data-source>
        <class>it.convalida.nazionale.core.entity.AssociaPratica</class>
        <class>it.convalida.nazionale.core.entity.Fascicolo</class>
        <class>it.convalida.nazionale.core.entity.Note</class>
        <class>it.convalida.nazionale.core.entity.LogAssociaPratica</class>
        <class>it.convalida.nazionale.core.entity.ConfigurazioniEntity</class>
        <exclude-unlisted-classes>true</exclude-unlisted-classes>
        <shared-cache-mode>NONE</shared-cache-mode>
        <validation-mode>NONE</validation-mode>
        <properties>
            <property name="javax.persistence.sharedCache.mode" value="NONE" />
            <property name="openjpa.DataCache" value="false" />
            <property name="openjpa.QueryCache" value="false" />
            <property name="openjpa.Log" value="DefaultLevel=INFO,Tool=INFO" />
            <property name="openjpa.jdbc.DBDictionary" value="DisableAlterSeqenceIncrementBy=true" />
            <property name="openjpa.jdbc.MappingDefaults"
                value="ForeignKeyDeleteAction=restrict,JoinForeignKeyDeleteAction=restrict" />
        </properties>
    </persistence-unit>
</persistence>

Dao:


package it.convalida.nazionale.core.dao.impl;

import java.util.List;

import javax.persistence.TypedQuery;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import it.convalida.nazionale.core.dao.ConfigurazioniDao;
import it.convalida.nazionale.core.eccezioni.ConvalidaNazionaleCoreException;
import it.convalida.nazionale.core.entity.ConfigurazioniEntity;

public class ConfigurazioniDaoImpl extends GenericDaoImpl<ConfigurazioniEntity> implements ConfigurazioniDao {

    private static final Logger LOGGER = LoggerFactory.getLogger(ConfigurazioniDaoImpl.class);

    public ConfigurazioniDaoImpl() {
        super(ConfigurazioniEntity.class);
    }

    /**
     * @param startFrom
     * @param pageSize
     * @return
     * @throws ConvalidaNazionaleCoreException
     */
    public List<ConfigurazioniEntity> findConfigurazioni(int startFrom, int pageSize)
            throws ConvalidaNazionaleCoreException {
        try {
            CriteriaBuilder cb = em.getCriteriaBuilder();
            CriteriaQuery<ConfigurazioniEntity> cq = cb.createQuery(ConfigurazioniEntity.class);
            Root<ConfigurazioniEntity> root = cq.from(ConfigurazioniEntity.class);
            cq.select(root);
            TypedQuery<ConfigurazioniEntity> query = em.createQuery(cq).setFirstResult(startFrom).setMaxResults(pageSize);
            return getResultList(query);
        } catch (Exception e) {
            LOGGER.error("Errore nel findConfigurazioni", e);
            throw new ConvalidaNazionaleCoreException(e); 
        }
    }

}

所有其他实体都以相同的方式完成,并且被识别为实体,但不是我的。 我只有我的实体有错误。

1 个答案:

答案 0 :(得分:0)

由于某种原因,它无法识别实体。

启动“ Maven全新安装”后,一切正常工作