【发布时间】:2017-09-12 01:14:17
【问题描述】:
以下 sn-p 适用于 Play for Scala:
class MyDAO @Inject() (jpaApi: JPAApi) {
@Transactional
def someMethod = {
jpaApi.withTransaction { // ....
在application.conf 中我定义了db.default.jndiName=DefaultDS 和jpa.default=defaultPersistenceUnit。
现在,我还需要用jpa.another=anotherPersistenceUnit 定义另一个JNDI 连接db.another.jndiName=AnotherDS。
persistence.xml 在哪里:
<persistence 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"
version="2.1">
<persistence-unit name="defaultPersistenceUnit" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<non-jta-data-source>DefaultDS</non-jta-data-source>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.HANAColumnStoreDialect"/>
</properties>
</persistence-unit>
<persistence-unit name="anotherPersistenceUnit" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<non-jta-data-source>AnotherDS</non-jta-data-source>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.HANAColumnStoreDialect"/>
</properties>
</persistence-unit>
</persistence>
如何在应用程序中注入AnotherDS以便与JPAApi一起使用?
【问题讨论】:
标签: scala playframework playframework-2.5