JPA - multiple jars defining @Entity objects

后端 未结 5 1359
暖寄归人
暖寄归人 2020-12-03 07:31

We are developing a web application with Spring, Hibernate and Maven in a very modular fashion. There are core projects defining data access and view specific stuff, then th

5条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-03 07:39

    We use a similar module layout, but we place the persistence context in the war-part of our application and inject the entitymanager into the DAOs of the modules. Except for unit testing, the modules don't have a PU. We did this because we were afraid, that a transaction spanning multiple modules could cause trouble.

    In the DAO

    @PersistenceContext
    private EntityManager em;
    

    In the persistance.xml you need to enlist all entities with the elements.

    
        com.Entity1      
    com.Entity2
    

    etc.

提交回复
热议问题