我的问题几乎在这个线程中得到了回答:
EclipseLink,EntityManager 需要两个持久性单元
但是我使用了一个 persistence.xml 文件来声明 3 个持久性单元,它运行良好。但是现在我需要一个复合持久性单元,我不知道也不想为每个持久性单元构建单独的 jar。有没有办法做到这一点没有<jar-file>
标签。如果没有,谁能给我一个如何使用单个持久性单元制作 jar 文件的示例?
编辑1: 这个配置我结束了,但它仍然不起作用 - 我得到的只是这个输出,当我尝试使用 em.createNamedQuery (当我有单独的持久性单元时,女巫工作之前)没有任何反应代码停止createEntity 线就是这样。
持久性.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:
我认为问题在于持久性单元没有看到任何实体,尽管我使用类标签声明它们......对此有什么帮助吗?