我的项目中有 2 个不同的持久性单元。PU_A:应用实体,可以执行所有的 crud 操作。PU_B:这个有一些包含外部数据的视图。我可以从这里读取数据
但是我想通过使用由 PU_B 持久性单元管理的不可变实体在 PU_A 中的某些实体中创建外键。
如果您可以查看以下片段。我有由 PU_A 驱动的 IncomingPaperwork 实体和由 PU_B 驱动的 ProjectView。在我应用了这个问题之后;部署应用程序时发生以下异常:
30-Jan-2013 15:13:05 o'clock EET> <Warning> <Deployer> <BEA-149078> <Stack trace for message 149004
weblogic.application.ModuleException:
at weblogic.ejb.container.deployer.EJBModule$1.execute(EJBModule.java:326)
at weblogic.deployment.PersistenceUnitRegistryInitializer.setupPersistenceUnitRegistries(PersistenceUnitRegistryInitializer.java:62)
at weblogic.servlet.internal.WebAppModule.initPersistenceUnitRegistry(WebAppModule.java:411)
at weblogic.servlet.internal.WebAppModule.prepare(WebAppModule.java:365)
at weblogic.application.internal.flow.ScopedModuleDriver.prepare(ScopedModuleDriver.java:176)
Truncated. see log file for complete stacktrace
Caused By: org.hibernate.AnnotationException: @OneToOne or @ManyToOne on com.acme.model.entity.IncomingPaperwork.projectView references an unknown entity: com.acme.integrationmodel.entity.ProjectView
at org.hibernate.cfg.ToOneFkSecondPass.doSecondPass(ToOneFkSecondPass.java:81)
at org.hibernate.cfg.AnnotationConfiguration.processEndOfQueue(AnnotationConfiguration.java:456)
at org.hibernate.cfg.AnnotationConfiguration.processFkSecondPassInOrder(AnnotationConfiguration.java:438)
at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:309)
at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1162)
Truncated. see log file for complete stacktrace
>
[03:13:05 PM] #### Deployment incomplete. ####
有没有办法做到这一点?有什么建议么?提前致谢
持久性.xml
<persistence 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"
version="2.0">
<persistence-unit name="PU_A" transaction-type="JTA">
<description>This unit manages all application entities</description>
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>jdbc/A_DS</jta-data-source>
<class>com.acme.model.entity.IncomingPaperwork</class>
<properties>
<property name="hibernate.jndi.url" value="t3://localhost:7101"/>
<!--DataSource-->
<property name="hibernate.connection.datasource"
value="jdbc/A_DS"/>
<property name="hibernate.transaction.manager_lookup_class"
value="org.hibernate.transaction.WeblogicTransactionManagerLookup"/>
<property name="hibernate.dialect"
value="org.hibernate.dialect.Oracle10gDialect"/>
<property name="hibernate.hbm2ddl.auto" value="update"/>
<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.format_sql" value="true"/>
<property name="hibernate.use_sql_comments" value="true"/>
<property name="hibernate.current_session_context_class" value="jta"/>
<property name="hibernate.archive.autodetection" value="jar,class"/>
</properties>
</persistence-unit>
<persistence-unit name="PU_B" transaction-type="JTA">
<description>This unit manages all integration entities</description>
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>jdbc/B_DS</jta-data-source>
<class>com.acme.integrationmodel.entity.ProjectView</class>
<properties>
<property name="hibernate.jndi.url" value="t3://localhost:7101"/>
<!--DataSource-->
<property name="hibernate.connection.datasource"
value="jdbc/B_DS"/>
<property name="hibernate.transaction.manager_lookup_class"
value="org.hibernate.transaction.WeblogicTransactionManagerLookup"/>
<property name="hibernate.dialect"
value="org.hibernate.dialect.Oracle10gDialect"/>
<property name="hibernate.hbm2ddl.auto" value="validate"/>
<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.format_sql" value="true"/>
<property name="hibernate.use_sql_comments" value="true"/>
<property name="hibernate.current_session_context_class" value="jta"/>
</properties>
</persistence-unit>
</persistence>
IncomingPaperwork.class
import com.arsivist.structure.BaseEntity;
import com.acme.integrationmodel.entity.ProjectView;
import com.acme.model.entity.listener.EntityListener;
import com.acme.model.entity.listener.IncomingPaperworkListener;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EntityListeners;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
@Entity(name = "IncomingPaperwork")
@Table(name = "INCOMINGPAPERWORKS")
@SequenceGenerator(name = "INCOMINGPAPERWORK_SEQ", sequenceName = "INCOMINGPAPERWORK_SEQ", allocationSize = 1)
@EntityListeners( { EntityListener.class, IncomingPaperworkListener.class })
public class IncomingPaperwork extends BaseEntity
{
private Company company;
private ProjectView projectView;
public IncomingPaperwork()
{
entityName = "IncomingPaperwork";
}
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "INCOMINGPAPERWORK_SEQ")
@Column(name = "ID")
public int getId()
{
return id;
}
public void setId(int id)
{
this.id = id;
}
public void setCompany(Company company)
{
this.company = company;
}
@ManyToOne(targetEntity = com.acme.model.entity.Company.class, cascade = { })
@JoinColumn(name = "COMPANYID", nullable = false)
public Company getCompany()
{
return company;
}
public void setProjectView(ProjectView projectView)
{
this.projectView = projectView;
}
@ManyToOne(targetEntity = com.acme.integrationmodel.entity.ProjectView.class, cascade = { })
@JoinColumn(name = "PROJECTVIEWID")
public ProjectView getProjectView()
{
return projectView;
}
}
ProjectView.class
import com.arsivist.structure.BaseEntityView;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import org.hibernate.annotations.Immutable;
import org.hibernate.annotations.Subselect;
@Entity(name = "ProjectView")
@Immutable
@Subselect("SELECT * FROM ProjectView")
public class ProjectView extends BaseEntityView
{
private String code;
private String name;
public ProjectView()
{
entityName = "ProjectView";
}
public ProjectView(int id, String name)
{
entityName = "ProjectView";
this.id = id;
this.name = name;
}
@Id
@Column(name = "ID")
public int getId()
{
return id;
}
public void setId(int id)
{
this.id = id;
}
public void setCode(String code)
{
this.code = code;
}
@Column(name = "CODE")
public String getCode()
{
return code;
}
public void setName(String name)
{
this.name = name;
}
@Column(name = "NAME")
public String getName()
{
return name;
}
@Override
public String toString()
{
return "" + getName();
}
}