私の質問は、このスレッドでほとんど答えられています。
2 つの永続性ユニットが必要な EclipseLink、EntityManager
しかし、私は1つのpersistence.xmlファイルを使用して3つの永続ユニットを宣言していましたが、うまくいきました。しかし、今は複合永続化ユニットが必要ですが、永続化ユニットごとに個別の jar ファイルを作成する必要がありません。<jar-file>
タグなしでこれを行う方法はありますか。いいえの場合、単一の永続ユニットでjarファイルを作成する方法の例を誰か教えてもらえますか?
編集1: この構成は最終的には機能しましたが、それでも機能しません-この出力だけが得られ、em.createNamedQueryを使用しようとすると(以前は個別の永続ユニットがあったときに魔女が機能していました)、何も起こりませんコードが停止しますcreateEntity 行とそれだけです。
persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="persistenceUnit" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<properties>
<property name="eclipselink.composite-unit" value="true"/>
</properties>
</persistence-unit>
<persistence-unit name="Minutis" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>database.entity.Entity1</class>
<class>database.entity.Entity2</class>
...
<properties>
<property name="eclipselink.composite-unit.member" value="true"/>
</properties>
</persistence-unit>
<persistence-unit name="Minutis2" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>database.entity.EEntity1</class>
<class>database.entity.EEntity2</class>
...
<properties>
<property name="eclipselink.composite-unit.member" value="true"/>
</properties>
</persistence-unit>
<persistence-unit name="Minutis3" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>database.entity.EEEntity1</class>
<class>database.entity.EEEntity2</class>
...
<properties>
<property name="eclipselink.composite-unit.member" value="true"/>
</properties>
</persistence-unit>
</persistence>
EntityManager
の作成方法は次のとおりです。
Map minutis = new HashMap();
minutis.put("javax.persistence.jdbc.user", "user");
minutis.put("javax.persistence.jdbc.password", "password");
minutis.put("javax.persistence.jdbc.driver", "driver");
minutis.put("javax.persistence.jdbc.url", "url");
Map minutis2= new HashMap();
minutis2.put("javax.persistence.jdbc.user", "user");
minutis2.put("javax.persistence.jdbc.password", "password");
minutis2.put("javax.persistence.jdbc.driver", "driver");
minutis2.put("javax.persistence.jdbc.url", "url");
Map minutis3= new HashMap();
minutis3.put("javax.persistence.jdbc.user", "user");
minutis3.put("javax.persistence.jdbc.password", "password");
minutis3.put("javax.persistence.jdbc.driver", "driver");
minutis3.put("javax.persistence.jdbc.url", "url");
Map persistanceUnitsProps = new HashMap();
persistanceUnitsProps.put("Minutis", minutis);
persistanceUnitsProps.put("Minutis2", minutis2);
persistanceUnitsProps.put("Minutis3", minutis3);
Map props = new HashMap();
props.put("eclipselink.logging.level", "FINEST");
props.put("eclipselink.composite-unit.properties", persistanceUnitsProps);
EntityManagerFactory emf = Persistence.createEntityManagerFactory("persistenceUnit", props);
em = emf.createEntityManager();
そして、ここに私が得る出力があります:
run:
[EL Finest]: 2012-10-09 09:04:43.071--SessionBroker(2079047885)--Thread(Thread[SwingWorker-pool-1-thread-1,5,main])--Begin predeploying Persistence Unit persistenceUnit; session file:/C:/Users/Minutis/Documents/NetBeansProjects/JavaApplication4/build/classes/_persistenceUnit; state Initial; factoryCount 0
[EL Finest]: 2012-10-09 09:04:43.099--SessionBroker(2079047885)--Thread(Thread[SwingWorker-pool-1-thread-1,5,main])--property=eclipselink.orm.throw.exceptions; default value=true
[EL Finest]: 2012-10-09 09:04:43.116--SessionBroker(2079047885)--Thread(Thread[SwingWorker-pool-1-thread-1,5,main])--End predeploying Persistence Unit persistenceUnit; session file:/C:/Users/Minutis/Documents/NetBeansProjects/JavaApplication4/build/classes/_persistenceUnit; state Predeployed; factoryCount 0
[EL Finer]: 2012-10-09 09:04:43.117--Thread(Thread[SwingWorker-pool-1-thread-1,5,main])--JavaSECMPInitializer - transformer is null.
[EL Finest]: 2012-10-09 09:04:43.117--SessionBroker(2079047885)--Thread(Thread[SwingWorker-pool-1-thread-1,5,main])--Begin predeploying Persistence Unit persistenceUnit; session file:/C:/Users/Minutis/Documents/NetBeansProjects/JavaApplication4/build/classes/_persistenceUnit; state Predeployed; factoryCount 0
[EL Finest]: 2012-10-09 09:04:43.117--SessionBroker(2079047885)--Thread(Thread[SwingWorker-pool-1-thread-1,5,main])--End predeploying Persistence Unit persistenceUnit; session file:/C:/Users/Minutis/Documents/NetBeansProjects/JavaApplication4/build/classes/_persistenceUnit; state Predeployed; factoryCount 1
[EL Finest]: 2012-10-09 09:04:43.125--SessionBroker(2079047885)--Thread(Thread[SwingWorker-pool-1-thread-1,5,main])--Begin deploying Persistence Unit persistenceUnit; session file:/C:/Users/Minutis/Documents/NetBeansProjects/JavaApplication4/build/classes/_persistenceUnit; state Predeployed; factoryCount 1
[EL Finest]: 2012-10-09 09:04:43.128--SessionBroker(2079047885)--Thread(Thread[SwingWorker-pool-1-thread-1,5,main])--property=eclipselink.logging.level; value=FINEST
[EL Finest]: 2012-10-09 09:04:43.128--SessionBroker(2079047885)--Thread(Thread[SwingWorker-pool-1-thread-1,5,main])--property=eclipselink.logging.level; value=FINEST
[EL Info]: 2012-10-09 09:04:43.13--SessionBroker(2079047885)--Thread(Thread[SwingWorker-pool-1-thread-1,5,main])--EclipseLink, version: Eclipse Persistence Services - 2.3.0.v20110604-r9504
[EL Info]: 2012-10-09 09:04:43.138--SessionBroker(2079047885)--Thread(Thread[SwingWorker-pool-1-thread-1,5,main])--file:/C:/Users/Minutis/Documents/NetBeansProjects/JavaApplication4/build/classes/_persistenceUnit login successful
[EL Warning]: 2012-10-09 09:04:43.146--Thread(Thread[SwingWorker-pool-1-thread-1,5,main])--The collection of metamodel types is empty. Model classes may not have been found during entity search for Java SE and some Java EE container managed persistence units. Please verify that your entity classes are referenced in persistence.xml using either <class> elements or a global <exclude-unlisted-classes>false</exclude-unlisted-classes> element
[EL Finer]: 2012-10-09 09:04:43.146--SessionBroker(2079047885)--Thread(Thread[SwingWorker-pool-1-thread-1,5,main])--The collection of metamodel types is empty. Model classes may not have been found during entity search for Java SE and some Java EE container managed persistence units. Please verify that your entity classes are referenced in persistence.xml using either <class> elements or a global <exclude-unlisted-classes>false</exclude-unlisted-classes> element
[EL Finest]: 2012-10-09 09:04:43.147--SessionBroker(2079047885)--Thread(Thread[SwingWorker-pool-1-thread-1,5,main])--End deploying Persistence Unit persistenceUnit; session file:/C:/Users/Minutis/Documents/NetBeansProjects/JavaApplication4/build/classes/_persistenceUnit; state Deployed; factoryCount 1
編集2:
問題は、クラスタグを使用してエンティティを宣言しているにもかかわらず、永続ユニットがエンティティを認識しないことであると考えました...これに関するヘルプはありますか?