JPA Entity - Specify Persistence Unit?

前端 未结 3 2094
长发绾君心
长发绾君心 2020-12-30 08:33

I have a JavaEE project that makes use of multiple persistence units. Is there any way to specify which persistence unit a particular JPA Entity belongs to? Some entities

3条回答
  •  梦谈多话
    2020-12-30 09:00

    The @PersistenceUnit should be usable as well (I haven't tried it, yet, though)

    e.g.

    @PersistenceUnit(unitName="persistenceUnit2")
    @Entity
    class XPTO {
    }
    

    From the Javadoc (http://docs.oracle.com/javaee/6/api/javax/persistence/PersistenceUnit.html)

    "Expresses a dependency on an EntityManagerFactory and its associated persistence unit."

    unitName (Optional) The name of the persistence unit as defined in the persistence.xml file.

提交回复
热议问题