【问题标题】:EclipseLink - No [EntityType] was found for the key class [CurriculumTree] in the metamodelEclipseLink - 在元模型中未找到关键类 [CurriculumTree] 的 [EntityType]
【发布时间】:2013-04-12 13:15:36
【问题描述】:

部署到 tomcat 后,我​​在我的axis2 Web 服务中得到以下信息。

java.lang.IllegalArgumentException: No [EntityType] was found for the key class [VOs.CurriculumTree] in the Metamodel - please verify that the [Entity] class was referenced in persistence.xml using a specific <class>VOs.CurriculumTree</class> property or a global <exclude-unlisted-classes>false</exclude-unlisted-classes> element.

当我从 Eclipse 运行时,JPA 工作正常。我在 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="NewAge-Test" transaction-type="RESOURCE_LOCAL">
        <class>VOs.CurriculumTree</class>
        <properties>
            <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/contentserver_development"/>
            <property name="javax.persistence.jdbc.user" value="root"/>
            <property name="javax.persistence.jdbc.password" value="quadfusion"/>
            <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
        </properties>
    </persistence-unit>
</persistence>

这是我的实体类:

@Entity
@Table(name="curriculum_trees")
public class CurriculumTree implements NodeInfo, Serializable {
    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    private int id;

    @LevelColumn
    @Column(name="depth",updatable=false)
    private int level;

    @Lob
    private String description;

    @LeftColumn
    @Column(updatable=false)
    private int lft;

    private String name;

    @Column(name="node_type")
    private String nodeType;

    @Column(name="parent_id")
    private int parentId;

    private int position;

    private boolean prassoTopicGroup;

    @RightColumn
    @Column(updatable=false)
    private int rgt;

    @RootColumn
    private int rootId;

    public CurriculumTree() {
    }

    public int getId() {
        return this.id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getDescription() {
        return this.description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public int getLft() {
        return this.lft;
    }

    public void setLft(int lft) {
        this.lft = lft;
    }

    public String getName() {
        return this.name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getNodeType() {
        return this.nodeType;
    }

    public void setNodeType(String nodeType) {
        this.nodeType = nodeType;
    }

    public int getParentId() {
        return this.parentId;
    }

    public void setParentId(int parentId) {
        this.parentId = parentId;
    }

    public int getPosition() {
        return this.position;
    }

    public void setPosition(int position) {
        this.position = position;
    }

    public boolean getPrassoTopicGroup() {
        return this.prassoTopicGroup;
    }

    public void setPrassoTopicGroup(boolean prassoTopicGroup) {
        this.prassoTopicGroup = prassoTopicGroup;
    }

    public int getRgt() {
        return this.rgt;
    }

    public void setRgt(int rgt) {
        this.rgt = rgt;
    }

    @Override
    public int getLeftValue() {
        return getLft();
    }

    @Override
    public int getRightValue() {
        return getRgt();
    }

    @Override
    public int getLevel() {
        return this.level;
    }

    @Override
    public int getRootValue() {
        return 0;
    }

    @Override
    public void setLeftValue(int value) {
        setLft(value);
    }

    @Override
    public void setRightValue(int value) {
        setRgt(value);
    }

    @Override
    public void setLevel(int level) {
        this.level = level;
    }

    @Override
    public void setRootValue(int value) {
        // TODO Auto-generated method stub
    }

    @Override public String toString() {
        return "[Curriculum Node: id=" + this.id + ", name=" + this.name + "-" + super.toString() + "]";
    }

}

我尝试了在persistence.xml 中包含标签&lt;exclude-unlisted-classes&gt;false&lt;/exclude-unlisted-classes&gt; 的替代方法,但它没有任何好处。

【问题讨论】:

    标签: java tomcat jpa-2.0 persistence.xml


    【解决方案1】:

    删除对&lt;class&gt;com.hm.newAge.VOs.CurriculumTree&lt;/class&gt;的引用

    并把属性&lt;exclude-unlisted-classes&gt;false&lt;/exclude-unlisted-classes&gt;

    【讨论】:

    • 你的数据库中是否有对应于 CurriculumTree 实体的表?
    • 该表当然存在。因为代码在从 Eclipse 运行时有效。当它作为服务部署在 tomcat 上时它不起作用。
    • 好的,确保您的 persistence.xml 在您的类路径中,并且您指的是正确的 PU 名称(这里是:“NewAge-Test”)
    • 我的 persistence.xml 文件位于axis2/WEB-INF/classes/META-INF。如果我没有提供正确的 PU 名称,我会收到一条错误消息:“没有为 NewAge-Test 找到持久提供程序。但事实并非如此。代码可以找到 xml,但我无法识别 @987654324 xml文件中的@标签。
    【解决方案2】:

    错误报告VOs.CurriculumTree,但在你的持久化xml中有com.hm.newAge.VOs.CurriculumTree存在包问题。

    【讨论】:

    • 不,那是我的错。从 cmd 提示符复制错误时,我没有输入完整的包名。
    【解决方案3】:

    如果不使用托管持久化单元,请尝试在使用后关闭实体管理器工厂。

    【讨论】:

    • 我想知道为什么要关闭 EMF?它不是关闭 EMF 的轻量级过程,它是如何完成的?请添加说明。
    猜你喜欢
    • 2012-02-03
    • 2019-03-21
    • 1970-01-01
    • 2015-05-20
    • 2015-06-03
    • 1970-01-01
    • 2021-11-18
    • 1970-01-01
    • 2022-01-01
    相关资源
    最近更新 更多