未知实体类错误消息,即使该实体已标有@Entity批注 [英] Unknown entity class error message even though the entity is marked with @Entity annotation

查看:116
本文介绍了未知实体类错误消息,即使该实体已标有@Entity批注的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Netbean6.9.1和JPA EclipseLink构建REST Web应用程序.

I am building REST web app using Netbean6.9.1 and JPA EclipseLink.

我面临的问题是即使我的实体类MasatoTable标记有Entity批注,我也会收到错误消息:

The issue I'm facing is even though my entity class MasatoTable is marked with Entity annotation, I get error:

    (java.lang.IllegalArgumentException: Unknown entity bean class:
     class entity.MasatoTable, please verify that this class
 has been marked with the @Entity annotation.)

问题是当我从NetbeanIDE重新启动GlassFish3服务器时,它工作了一段时间,并在某种程度上以某种方式出现了错误.我曾经使用Toplink Essential,但没有任何问题,但是我已更改为EclipseLink并重新定义persistence.xml(如下所示),此问题开始了.但是我看不到任何可以想到的代码错误.

The thing is when I restart the GlassFish3 server from NetbeanIDE, it works for a while and somehow at some point, the error start showing up. I used to use Toplink Essential and had no issue but I've changed to EclipseLink and re-defiend persistence.xml (shown below) and this problem started. But I don't see any code error that I can think of..

MasatoTable.java

@Entity
@Table(name = "MasatoTable")
public class MasatoTable implements Serializable {
...continue code...

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="kojoPU">
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <non-jta-data-source>jdbc/koga_kojo</non-jta-data-source>
    <class>entity.MasatoTable</class>
    <properties>
      <property name="eclipselink.logging.logger" value="JavaLogger"/>
      <property name="eclipselink.logging.level.sql" value="FINEST"/>
      <property name="javax.persistence.jdbc.url" value="jdbc:sqlserver://KOGADBSERVER;databaseName=MasatoDB"/>
      <property name="javax.persistence.jdbc.password" value="foobar"/>
      <property name="javax.persistence.jdbc.driver" value="com.microsoft.sqlserver.jdbc.SQLServerDriver"/>
      <property name="javax.persistence.jdbc.user" value="koga"/>
    </properties>
  </persistence-unit>
</persistence>

类似的问题,但该票证的解决方案是从Eclipselink回滚到Toplink.有没有人可以解决该问题而无需回滚到toplink?

Looks like same issue but that ticket's solution is to rollback to Toplink from Eclipselink. Has anyone solve the issue without rolling back to toplink?

未知热部署后的实体bean类:netbeans 6.9 + glassfish 2.1 + eclipselink jpa 2.0

更新

就我在这种情况下的研究而言,该错误似乎已得到解决并已解决?

As far as my research goes in terms of this case, look like the bug has been addressed and fixed?

https://bugs.eclipse.org/bugs/show_bug.cgi ?id = 288141

我不了解整个事情,但是我发现的事实很少:

I'm not knowledgeable enough to understand the whole thing but there are few facts I found:

Netbean6.9.1提供EclipseLink 2.0.1,而最新版本是2.2.0

Netbean6.9.1 provides EclipseLink 2.0.1 whereas newest version is 2.2.0

我下载了最新版本,并将其放入lib目录中,然后重新部署,但没有运气,问题仍然存在.不知道我是否以错误的方式做事.

I downloaded newest version and put them into the lib dir then re-deployed but no luck, the issue still persists. Not sure if I did things in wrong way.

詹姆斯评论后更新

下面是我用来创建单例EntityManagerFactory及其使用方式的类.

Below is the class I use to create singleton EntityManagerFactory and how it is being used.

package common;

import java.util.Date;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

public class EmProvider {

    private static final String DB_PU = "kojoPU"; //工場DB

    public static final boolean DEBUG = false;

    private static final EmProvider singleton = new EmProvider();

    private EntityManagerFactory emf;

    private EmProvider() {}

    public static EmProvider getInstance() {
        return singleton;
    }


    public EntityManagerFactory getEntityManagerFactory() {
        if(emf == null) {
            emf = Persistence.createEntityManagerFactory(DB_PU);
        }
        if(DEBUG) {
            System.out.println("factory created on: " + new Date());
        }
        return emf;
    }

    public void closeEmf() {
        if(emf.isOpen() || emf != null) {
            emf.close();
        }
        emf = null;
        if(DEBUG) {
            System.out.println("EMF closed at: " + new Date());
        }
    }

}//end class

用法:

EntityManager em = null;
   Object out = null;
   try {
       em = EmProvider.getInstance().getEntityManagerFactory().createEntityManager();
       Query query = em.createNativeQuery(sql);

       ....some code here
   }
   finally {
       if(em != null) {
           em.close();
       }
   }

通过查看我的代码,我认为... 我没有关闭EntityManagerFactory (虽然我最终还是在关闭EntityManager)

By looking at my code, I think... I'm not closing EntityManagerFactory (i'm closing EntityManager in finally though)

我还发现,通过以下操作肯定会显示主题中的"unknown entity bean class"错误.

I also I found the "unknown entity bean class" error in topic shows up for sure with following action.

  1. 通过Netbean部署Web应用程序(这将打开浏览器)

  1. Deploy web app through Netbean (This will open the browser)

在Netbean IDE中更改一些代码并保存.然后,一旦按下保存按钮,Netbean将自动重新部署(这称为热部署"?)

Change some code in Netbean IDE and save it. Then Netbean will auto-re-deploy as soon as you press the save button (is this called "hot deploy" ???)

返回浏览器并执行一些操作,例如添加一些涉及EntityManager的数据.

Go back to browser and take some action like add some data which involves EntityManager.

看起来像发生错误,因为在热部署时我没有关闭实体管理器工厂?我必须调查.

Looks like the error occurs because I'm not closing entity manager factory when hot-deploy? I have to investigate.

推荐答案

如何创建EntityManager/Factory,它是托管的还是非托管的?

How are you creating your EntityManager/Factory, is it managed or non-managed?

如果不进行管理,那么我相信不会以任何方式通知EclipseLink,因此仍将缓存旧的EntityManagerFactory,因为它永远不会关闭.您可以确保在热部署后关闭EntityManagerFactory吗?

If it is not managed, then I believe that EclipseLink will not be notified in any way of a redeployment, so will still have the old EntityManagerFactory cached as it is never closed. Can you ensure that you close the EntityManagerFactory after the hot deploy?

您可以将持久性单元设置为托管的持久性单元,这可以解决问题.

You can make the persistence unit a managed persistence unit, that may resolve the issue.

无论哪种方式,都应在EclipseLink和Glassfish中记录有关此问题的错误,因为应该跟踪此问题.

Either way, please log a bug for this with details in EclipseLink and Glassfish, as this issue should be tracked.

我认为这可能是错误 https://bugs.eclipse. org/bugs/show_bug.cgi?id = 326552

请对该错误进行投票,并在其中添加您的信息.

Please vote for this bug, and include your information in it.

这篇关于未知实体类错误消息,即使该实体已标有@Entity批注的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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