Java 创建第三方JPA应用程序jar并将其作为库部署到Payara
我正在尝试构建一个第三方JPA模块(依赖于Payara 5运行时的Java9模块),并将其包装到一个jar中 定义了persistence.xml,并与一些实体一起放入META-INF/persistence.xml中 这些模块将访问服务器上下文中定义的payara域JDBC资源(通过JNDI数据源) my persistence.xml看起来像:Java 创建第三方JPA应用程序jar并将其作为库部署到Payara,java,jpa,lib,payara,Java,Jpa,Lib,Payara,我正在尝试构建一个第三方JPA模块(依赖于Payara 5运行时的Java9模块),并将其包装到一个jar中 定义了persistence.xml,并与一些实体一起放入META-INF/persistence.xml中 这些模块将访问服务器上下文中定义的payara域JDBC资源(通过JNDI数据源) my persistence.xml看起来像: <persistence version="2.2" xmlns="http://xmlns.
<persistence version="2.2"
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_2.xsd">
<persistence-unit name="PG12_JTAPU" transaction-type="JTA">
<jta-data-source>jdbc/PG12_ozssc_105</jta-data-source>
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>com.xxxx.Address</class>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
<properties>
</properties>
</persistence-unit>
</persistence>
@ApplicationScoped
public class AddressBean implements Serializable {
private static final ILogger ilogger = Logger.getLogger(AddressBean.class.getName());
private static EntityManager em = null;
private static Set<String> addressIds = null;
@PersistenceContext(unitName = "PG12_JTAPU")
private EntityManagerFactory emf;
public AddressBean(){
addressIds = new HashSet<>();
if(emf != null){
em = emf.createEntityManager();
}else{
ilogger.info("----------- Entity manager factory not found.");
}
}
public Set<String> getAddressIds(){
Set<String> stringSet = new HashSet<>();
if (!em.isJoinedToTransaction()) {
em.joinTransaction();
}
Query query = em.createNamedQuery("Address.findIDs", Address.class);
stringSet= new HashSet<String>(query.getResultList());
/*setKeysInDatabase(keys);*/
em.flush();
return stringSet;
}
}
这是AddressBean的外观:
<persistence version="2.2"
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_2.xsd">
<persistence-unit name="PG12_JTAPU" transaction-type="JTA">
<jta-data-source>jdbc/PG12_ozssc_105</jta-data-source>
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>com.xxxx.Address</class>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
<properties>
</properties>
</persistence-unit>
</persistence>
@ApplicationScoped
public class AddressBean implements Serializable {
private static final ILogger ilogger = Logger.getLogger(AddressBean.class.getName());
private static EntityManager em = null;
private static Set<String> addressIds = null;
@PersistenceContext(unitName = "PG12_JTAPU")
private EntityManagerFactory emf;
public AddressBean(){
addressIds = new HashSet<>();
if(emf != null){
em = emf.createEntityManager();
}else{
ilogger.info("----------- Entity manager factory not found.");
}
}
public Set<String> getAddressIds(){
Set<String> stringSet = new HashSet<>();
if (!em.isJoinedToTransaction()) {
em.joinTransaction();
}
Query query = em.createNamedQuery("Address.findIDs", Address.class);
stringSet= new HashSet<String>(query.getResultList());
/*setKeysInDatabase(keys);*/
em.flush();
return stringSet;
}
}
当我向下搜索时,我发现调用者或被调用者类(AddressBean)没有找到持久性提供程序。最有可能的是lib-jar内部类AddressBean没有在自己的jar上下文中读取persistence.xml
我的问题是:
有没有办法配置调用者类(其他服务器端类)或第三方Lib来访问包装在自己的jar包中的JPA
或者在调用被调用方类AddressBean时如何手动创建JPA上下文(PU、EntityManagerFactory或EntityManager)
或者这种方法根本不可用
欢迎任何建议