您可以在中指定多个JPA配置
application.conf
:
db.default.jndiName=DefaultDS
... // other configuration for db.default
jpa.default=defaultPersistenceUnit
db.another.jndiName=AnotherDS
... // other configuration for db.another
jpa.another=anotherPersistenceUnit
JPAApi
就像你现在做的那样。使用
JPAApi#em(String)
获得
EntityManager
class MyDAO @Inject() (jpaApi: JPAApi) {
def someMethodWithDefault = {
val em = jpaApi.em("default") // em is an EntityManager
jpaApi.withTransaction {
...
}
}
def someMethodWithAnother = {
val em = jpaApi.em("another") // em is an EntityManager
jpaApi.withTransaction {
...
}
}
@Transactional
如果您正在使用
JPAApi#withTransaction