Hi experts, There are 2 different persistence unit in my project. PU_A: Application entities, that can execute all crud operations. PU_B: This one has some views which contains outside data. I can just read data from here
But i want to create foreign key in some entities which are in PU_A by using immutable-entity which managed by PU_B persistence-unit.
If you could view on following snippets. I have IncomingPaperwork entity which is driven by PU_A and ProjectView which is driven by PU_B. After i applied this issue; When deploy the application exception that is below occured :
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. ####
Is there a way to achieve this? Any suggestions? Thanks in advance
___persistence.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(); } }
|