我有两个persistenceUnits映射到两个不同的Oracle模式,模式类似但具有不同的表名。当我尝试部署我的应用程序时,我得到了一个Hibernate Exception" Missing Table",似乎Hibernate在错误的persistenceUnit中寻找表。
.ear#POIPersistenceUnit \":org.hibernate.HibernateException:缺少表:POI_SERVICE 引起:org.hibernate.HibernateException:缺少表:POI_SERVICE"}}
表" POI_SERVICE"属于" POIExtractorPersistenceUnit" persistenceUnit not" POIPersistenceUnit" persistenceUnit
我已尝试在persistence.xml文件中列出具有相应persistenceUnits的实体,如下所示,但没有运气,仍然得到相同的错误。
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="2.0">
<persistence-unit name="POIExtractorPersistenceUnit">
<jta-data-source>java:/XAPOIExtractorDS</jta-data-source>
<class>za.co.fnb.cii.poiextractor.persistence.model.IdentificationRequest</class>
<class>za.co.fnb.cii.poiextractor.persistence.model.IdentificationResponse</class>
<class>za.co.fnb.cii.poiextractor.persistence.model.POIService</class>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect" />
<property name="hibernate.archive.autodetection" value="class" />
<property name="hibernate.flushMode" value="FLUSH_AUTO" />
<property name="hibernate.hbm2ddl.auto" value="validate" />
<property name="hibernate.show_sql" value="true" />
</properties>
</persistence-unit>
<persistence-unit name="POIPersistenceUnit">
<jta-data-source>java:/XACompendiumDS</jta-data-source>
<class>za.co.fnb.cii.poiextractor.persistence.entities.IdentificationRequestIncoming</class>
<class>za.co.fnb.cii.poiextractor.persistence.entities.IdentificationResponseIncoming</class>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect" />
<property name="hibernate.archive.autodetection" value="class" />
<property name="hibernate.flushMode" value="FLUSH_AUTO" />
<property name="hibernate.hbm2ddl.auto" value="validate" />
<property name="hibernate.show_sql" value="false" />
</properties>
</persistence-unit>
我还尝试按如下方式注释实体@PersistenceUnit(unitName = "POIExtractorPersistenceUnit")
,但仍然没有运气,错误仍然存在。
/**
* Created by on 21-Dec-15.
*/
@Entity
@Table(name = "POI_SERVICE")
@PersistenceUnit(unitName = "POIExtractorPersistenceUnit")
@NamedQueries({
@NamedQuery(name="findServiceRecordByApplicationName",
query="SELECT pois FROM POIService pois WHERE pois.application = :applicationName")
})
public class POIService implements IEntity{
@Id
@GeneratedValue(generator="service_config_seq")
@SequenceGenerator(name="service_config_seq", sequenceName="service_config_seq", allocationSize=1)
private long id;
private String application;
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "last_update",nullable = false)
private Date lastUpdate;
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "last_date",nullable = true)
private Date lastDate;
@Column(name = "last_record",nullable = true)
private long lastRecord;
@Override
public long getId() {
return id;
}
public String getApplication() {
return application;
}
public void setApplication(String application) {
this.application = application;
}
public Date getLastUpdate() {
return lastUpdate;
}
public void setLastUpdate(Date lastUpdate) {
this.lastUpdate = lastUpdate;
}
public Date getLastDate() {
return lastDate;
}
public void setLastDate(Date lastDate) {
this.lastDate = lastDate;
}
public long getLastRecord() {
return lastRecord;
}
public void setLastRecord(long lastRecord) {
this.lastRecord = lastRecord;
}
}
更新
堆栈跟踪
2016-01-08 12:24:52,587 INFO [java.sql.DatabaseMetaData] (ServerService线程池 - 58)HHH000262:找不到表: POI_SERVICE 2016-01-08 12:24:52,590错误[org.jboss.msc.service.fail] (ServerService线程池 - 58)MSC000001:无法启动服务 jboss.persistenceunit&#34; poiextractor耳-1.0.0-SNAPSHOT.ear#POIPersistenceUnit&#34 ;: 服务中的org.jboss.msc.service.StartException jboss.persistenceunit&#34; poiextractor耳-1.0.0-SNAPSHOT.ear#POIPersistenceUnit&#34 ;: org.hibernate.HibernateException:缺少表:POI_SERVICE at org.jboss.as.jpa.service.PersistenceUnitServiceImpl $ 1 $ 1.run(PersistenceUnitServiceImpl.java:172) [wildfly-jpa-8.2.0.Final.jar:8.2.0.Final] at org.jboss.as.jpa.service.PersistenceUnitServiceImpl $ 1 $ 1.run(PersistenceUnitServiceImpl.java:117) [wildfly-jpa-8.2.0.Final.jar:8.2.0.Final] at java.security.AccessController.doPrivileged(本机方法) [rt.jar:1.8.0_60] at org.wildfly.security.manager.WildFlySecurityManager.doChecked(WildFlySecurityManager.java:474) [wildfly-security-manager-1.0.0.Final.jar:1.0.0.Final] at org.jboss.as.jpa.service.PersistenceUnitServiceImpl $ 1.run(PersistenceUnitServiceImpl.java:182) [wildfly-jpa-8.2.0.Final.jar:8.2.0.Final] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [rt.jar:1.8.0_60] at java.util.concurrent.ThreadPoolExecutor中的$ Worker.run(ThreadPoolExecutor.java:617) [rt.jar:1.8.0_60]在java.lang.Thread.run(Thread.java:745) [rt.jar:1.8.0_60] at org.jboss.threads.JBossThread.run(JBossThread.java:122) [jboss-threads-2.1.1.Final.jar:2.1.1.Final]引起: org.hibernate.HibernateException:缺少表:POI_SERVICE at org.hibernate.cfg.Configuration.validateSchema(Configuration.java:1335) [hibernate-core-4.3.7.Final.jar:4.3.7.Final] at org.hibernate.tool.hbm2ddl.SchemaValidator.validate(SchemaValidator.java:155) [hibernate-core-4.3.7.Final.jar:4.3.7.Final] at org.hibernate.internal.SessionFactoryImpl。(SessionFactoryImpl.java:525) [hibernate-core-4.3.7.Final.jar:4.3.7.Final] at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1859) [hibernate-core-4.3.7.Final.jar:4.3.7.Final] at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl $ 4.perform(EntityManagerFactoryBuilderImpl.java:852) [hibernate-entitymanager-4.3.7.Final.jar:4.3.7.Final] at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl $ 4.perform(EntityManagerFactoryBuilderImpl.java:845) [hibernate-entitymanager-4.3.7.Final.jar:4.3.7.Final] at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.withTccl(ClassLoaderServiceImpl.java:398) [hibernate-core-4.3.7.Final.jar:4.3.7.Final] at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:844) [hibernate-entitymanager-4.3.7.Final.jar:4.3.7.Final] at org.jboss.as.jpa.hibernate4.TwoPhaseBootstrapImpl.build(TwoPhaseBootstrapImpl.java:44) [jipijapa-hibernate4-3-1.0.1.Final.jar:] at org.jboss.as.jpa.service.PersistenceUnitServiceImpl $ 1 $ 1.run(PersistenceUnitServiceImpl.java:154) [wildfly-jpa-8.2.0.Final.jar:8.2.0.Final] ... 8更多
2016-01-08 12:24:58,786 INFO [org.hibernate.tool.hbm2ddl.TableMetadata](ServerService线程池 - 57)HHH000261:找到的表:POIOPS.POI_SERVICE 2016-01-08 12:24:58,788 INFO [org.hibernate.tool.hbm2ddl.TableMetadata] (ServerService线程池 - 57)HHH000037:列:[last_record, application,last_update,id,last_date] 2016-01-08 12:25:00,774 INFO [org.hibernate.tool.hbm2ddl.TableMetadata](ServerService线程池 - 57)HHH000261:找到的表:POIOPS.IDENTIFICATION_REQUEST 2016-01-08 12:25:00,775 INFO [org.hibernate.tool.hbm2ddl.TableMetadata](ServerService线程池 - 57)HHH000037:专栏:[sworkstationid,yafp2wsqimage,stransactiontime,created,stype,bretphoto,scardseqno,stranid, breturnname,smode,requesttype,ssiteid,identificationresponse_id, sidn,id,yafp1wsqimage,updated,ifpind1,ifpind2] 2016-01-08 12:25:05,385 INFO [org.hibernate.tool.hbm2ddl.TableMetadata] (ServerService线程池 - 57)HHH000261:找到的表: POIOPS.IDENTIFICATION_RESPONSE 2016-01-08 12:25:05,387信息 [org.hibernate.tool.hbm2ddl.TableMetadata](ServerService线程池 - 57)HHH000037:专栏:[bnameret,created,sfpind2,scallcentreno,ifp2score,stranid,sidissuedate,ierror,ifp1score,sfp1result,sidn, sname,serror,sfp2result,sfpind1,yaphoto,ssmartcardind,id, ssurname,updated] 2016-01-08 12:25:09,367 INFO [org.hibernate.tool.hbm2ddl.TableMetadata](ServerService线程池 - 57)HHH000261:找到的表:POIOPS.IDENTIFICATIONREQUEST 2016-01-08 12:25:09,369 INFO [org.hibernate.tool.hbm2ddl.TableMetadata] (ServerService线程池 - 57)HHH000037:列:[sworkstationid, responseerror,yafp2wsqimage,stransactiontime,created,stype, bretphoto,scardseqno,stranid,breturnname,smode,requesttype, ssiteid,sidn,id,yafp1wsqimage,updated,ifpind1,ifpind2] 2016-01-08 12:25:15,851 INFO [org.hibernate.tool.hbm2ddl.TableMetadata](ServerService线程池 - 57)HHH000261:找到的表:POIOPS.IDENTIFICATIONRESPONSE 2016-01-08 12:25:15,853 INFO [org.hibernate.tool.hbm2ddl.TableMetadata](ServerService线程池 - 57)HHH000037:专栏:[bnameret,created,sfpind2,scallcentreno,ifp2score,stranid,sidissuedate,ierror,ifp1score,sfp1result,sidn, sname,serror,sfp2result,sfpind1,yaphoto,ssmartcardind,id, ssurname,updated,request_id] 2016-01-08 12:25:15,994错误 [org.jboss.as.controller.management运算] (management-handler-thread-2)JBAS014613:操作(&#34; deploy&#34;) 失败 - 地址:([(&#34;部署&#34; =&gt; &#34; poiextractor-ear-1.0.0-SNAPSHOT.ear&#34;)]) - 失败描述: {&#34; JBAS014671:服务失败&#34; =&GT; {&#34; jboss.persistenceunit \&#34; poiextractor耳-1.0.0-SNAPSHOT.ear#POIPersistenceUnit \&#34;&#34; =&GT; &#34; org.jboss.msc.service.StartException in service jboss.persistenceunit。\&#34; poiextractor-ear-1.0.0-SNAPSHOT.ear#POIPersistenceUnit \&#34;: org.hibernate.HibernateException:缺少表:POI_SERVICE 引起:org.hibernate.HibernateException:缺少表:POI_SERVICE&#34;}} 2016-01-08 12:25:15,996 ERROR [org.jboss.as.server] (management-handler-thread-2)JBAS015870:部署部署 &#34; poiextractor耳-1.0.0-SNAPSHOT.ear&#34;被卷起来了 以下失败消息:{&#34; JBAS014671:服务失败&#34; =&GT; {&#34; jboss.persistenceunit \&#34; poiextractor耳-1.0.0-SNAPSHOT.ear#POIPersistenceUnit \&#34;&#34; =&GT; &#34; org.jboss.msc.service.StartException in service jboss.persistenceunit。\&#34; poiextractor-ear-1.0.0-SNAPSHOT.ear#POIPersistenceUnit \&#34;: org.hibernate.HibernateException:缺少表:POI_SERVICE 引起:org.hibernate.HibernateException:缺少表:POI_SERVICE&#34;}} 2016-01-08 12:25:15,997 INFO [org.jboss.as.connector.deployers.jdbc](MSC服务主题1-6) JBAS010418:使用driver-name =停止的驱动程序服务 poiextractor-ear-1.0.0-SNAPSHOT.ear_org.h2.Driver_1_4 2016-01-08 12:25:15,998 INFO [org.jboss.as.jpa](ServerService线程池 - 57)JBAS011410:停止持久性单元(第2阶段,共2阶段)服务 &#39; poiextractor耳-1.0.0-SNAPSHOT.ear#POIExtractorPersistenceUnit&#39; 2016-01-08 12:25:16,018 INFO [org.jboss.weld.deployer](MSC服务 线程1-9)JBAS016009:停止焊接服务以进行部署 poiextractor-ear-1.0.0-SNAPSHOT.ear 2016-01-08 12:25:16,043 INFO [org.jboss.as.jpa](ServerService线程池 - 57)JBAS011410: 停止持久性单元(第1阶段,第2阶段)服务 &#39; poiextractor耳-1.0.0-SNAPSHOT.ear#POIPersistenceUnit&#39; 2016年1月8日 12:25:16,043 INFO [org.jboss.as.jpa](ServerService线程池 - 59)JBAS011410:停止持久性单元(第1阶段,共2步)服务 &#39; poiextractor耳-1.0.0-SNAPSHOT.ear#POIExtractorPersistenceUnit&#39;
更新2: 当我从persistence.xml中删除这个属性时,一切正常。
<property name="hibernate.hbm2ddl.auto" value="validate" />
答案 0 :(得分:0)
JPA EntityManager
属于一个持久性单元,或EntityManagerFactory
,您无法将多个持久性单元与相同的EntityManager
混合。
但你不必这样做。
您可以拥有一个持久性单元,并在映射实体时使用schema
属性。
如果您使用多个持久性单元,则需要多个persistence.xml
,多个EntityManagerFactory
以及可能需要全局事务的JTA。