Search code examples
javajpanetbeanseclipselinkjax-rs

Netbeans, JPA Entity Beans in seperate projects. Unknown entity bean class


I am working in Netbeans and have my entity beans and web services in separate projects. I include the entity beans in the web services project however the ApplicaitonConfig.java file keeps getting over written and removing the entries I make for the entity beans in the associated jar file.

My question is: is it required to have both the EntityBeans and the WebServices share the same project/jar file? If not what is the appropriate way to include the entity beans which are in the jar file?


<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1"
             xmlns="http://xmlns.jcp.org/xml/ns/persistence"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
  <persistence-unit name="jdbc/emrPool" transaction-type="JTA">
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <jta-data-source>jdbc/emrPool</jta-data-source>
    <exclude-unlisted-classes>false</exclude-unlisted-classes>
    <properties>
      <property name="eclipselink.ddl-generation" value="none"/>
      <property name="eclipselink.cache.shared.default" value="false"/>
    </properties>
  </persistence-unit>
</persistence>

Based on Melc's input i verified that that the transaction type is set to JTA and the jta-data-source is set to the value for the Glassfish JDBC Resource. Unfortunately the problem still persists. I have opened the WAR file and validated that the EntityBean.jar file is the latest version and is located in the WEB-INF/lib directory of the War file. I think it is tied to the fact that the entities are not being "registered" with the entity manager. However i do not know why they are not being registered.


Solution

  • No it is not necessary to be within the same war. You can have a project (I think it is called class library project) with your jpa entities and add that project from the libraries of your web project that contains the web services. The ApplicationConfig is related to the web services and it does not affect the entities. I advise you to check the functionality of the jpa project from a simple servlet of a web project. If it works then it will also work with your jax-rs code. However take care to properly modify the persistence.xml to not use resource-local,which is the default generation by netbeans for non web projects, but jta along with the proper server data source.

    EDIT

    Make another test by editing persistence.xml from netbeans and uncheck "Include All Entity Classes in .." , then choose the "Add Class..." option and select all entity classes. Along the entity classes you should also find the one you try to access.

    Also it is the contents of the web project's build folder that gf is working on not the war,when running from netbeans. Unless you go to gf's admin console, deploy application and choose your war file. So you better check the contents of that folder as well or simply delete it and let nb recreate it.

    The "unknown entity bean class" pops up pretty often with netbeans and glassfish, for example you may also get it while the system is working after redeployment. In that case it gets fixed by restarting the server. Unfortunately it is one of those errors that don't always really mean what they say.