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";
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.