JPA - Unknown entity bean class

前端 未结 5 1767
不知归路
不知归路 2020-12-19 13:59

Hopefully, I can explain this issue properly. I have 3 classes that deals with my entities.

@MappedSuperclass
public abstract class Swab implements ISwab {
         


        
相关标签:
5条回答
  • 2020-12-19 14:21

    I solved this issue creating a ContextListener in to my Web App, invoking the close of the entity manager factory at destroy context, :

    public void contextDestroyed(ServletContextEvent servletContextEvent) {
        try {
            logger.info("contextDestroyed...");
            LifeCycleManager lifeCycleManager = ServiceLocator.getLifeCycleManager();
            lifeCycleManager.closeEntityManagerFactory();
    
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
        }
    }
    

    I also create a bean with name LifeCycleManager and inside them invoke a DAO method to close the entity manager factory:

    public void closeEntityManagerFactory() throws BusinessException {
            logger.info("closeEntityManager");
            try {
                logger.info("closing entity manager factory...");
                genericDAO.closeEntityManagerFactory();
                logger.info("Entity manager factiry closed");
            } catch (Exception e) {
                throw new BusinessException(BusinessErrorCode.CODIGO_EJEMPLO_01, Severity.ERROR);
            }
        }
    

    Inside the DAO:

    ...

    @Autowired
    private EntityManagerFactory entityManagerFactory;
    

    ...

    public void closeEntityManagerFactory() {
            logger.info("closing entity manager factory");
            getEntityManagerFactory().close();
            logger.info("entity manager factory closed");   
        }
    

    Using this each time I deploy a change from my eclipse environment the destroy context is invoked. I hope could help you guys, my environment is WebLogic Server 11gR1 and JPA 1.0.

    0 讨论(0)
  • 2020-12-19 14:27

    According to the error message and what I figure from your code, the error seems to be in the persistence.xml file, can you be a bit more verbose ?

    0 讨论(0)
  • 2020-12-19 14:32

    define this entity in class tag inside the persistence.xml

    0 讨论(0)
  • 2020-12-19 14:35

    I had the same error and, complementing the information above, my case was a ClassLoader issue. My app has three files. A ejb-module.jar which depends on app-lib.jar (library that contains pojo and database entities) and a web-module.war which depends on app-lib.jar.

    In the deployment, the app-lib.jar was loaded twice by the glassfish. Googling, I found out that I should copy the app-lib.jar to a "shared" lib in the glassfish domain. I've copied the postgresql.jar to "domain-dir/lib" and my app-lib.jar to "domain-dir/lib/applibs". Have it done, the app worked like a charm.

    The used explanation can be found here: http://docs.oracle.com/cd/E19798-01/821-1752/beade/index.html

    0 讨论(0)
  • 2020-12-19 14:42

    Mario was right when he mentions EntityManagerFactory here.

    Both:

    java.lang.IllegalArgumentException: Unknown entity bean class...

    and

    java.lang.IllegalStateException: This web container has not yet been started...

    These exceptions occur when you redeploy a web application multiple times but didn't close EntityManagerFactory properly.

    follow this instruction to register ServletContextListener and this instruction to close EntityManagerFactory properly.

    0 讨论(0)
提交回复
热议问题