Unknown object class error message even if the object is tagged with @Entity annotation

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

The problem I am facing, even if my MasatoTable object class is marked with Entity annotation, I get an error:

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

The thing is , when I restart the GlassFish3 server from NetBSIDE, it has been working for some time, and somehow at some point an error appears. I used Toplink Essential and had no problems, but I switched to EclipseLink and rethought persistence.xml (shown below) and this problem started. But I do not see a 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> 

Looks like the same problem, but this ticket solution is a rollback to Toplink from Eclipselink. Does anyone solve the problem without rolling back to toplink?

Unknown bean object class after hot deployment: netbeans 6.9 + glassfish 2.1 + eclipselink jpa 2.0

UPDATE

As far as my research concerns this case, it seems that the bug has been fixed and fixed?

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

I am not knowledgeable enough to understand all this, but there are a few facts that I have found:

Netbean6.9.1 provides EclipseLink 2.0.1, while the newest version is 2.2.0

I downloaded the new version and placed it in the lib directory and then redeployed, but with no luck, the problem still persists. Not sure if I did something wrong.

UPDATE after James comment

Below is the class that I use to create the Singleton EntityManagerFactory and how it is 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 

How is it used:

 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(); } } 

If you look at my code, I think ... I do not close EntityManagerFactory (in conclusion I close EntityManager)

I also found that a "unknown entity bean class" error in a topic is detected with a subsequent action.

  • Deploy the web application via Netbean (browser will open)

  • Change the code in the Netbean IDE and save it. Then Netbean will be automatically redeployed as soon as you click the save button (this is called a "hot deployment").

  • Return to the browser and perform some actions, for example, add some data that includes the EntityManager.

It seems like an error is occurring because I do not close the factory object manager during a hot deployment? I have to research.

+8
java rest jpa toplink eclipselink
source share
3 answers

How do you create your EntityManager / Factory, is it managed or not managed?

If it is not managed, I believe that EclipseLink will not be notified in any way about the redistribution, so that the old EntityManagerFactory file will still be saved, since it never closes. Can you make sure you close EntityManagerFactory after a hot deployment?

You can make the persistence block a managed persistence module that can solve the problem.

In any case, please report a bug for this with details in EclipseLink and Glassfish, as this issue should be monitored.

I think this may be a bug, https://bugs.eclipse.org/bugs/show_bug.cgi?id=326552

Please vote for this error and include your information in it.

+6
source share

The solution here is to use JPA 1.0 if 2.0 is not required.

+2
source share

Today I ran into the same pace, but fixed it in persistence.xml

  • Please check with the class name of the object and package that are correctly defined in the persistence.xml file.
-one
source share

All Articles