This discussion is archived
4 Replies Latest reply: Jan 30, 2013 5:38 AM by webyildirim RSS

how to use composite entities which driven by different PU via hibernate

webyildirim Newbie
Currently Being Moderated
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();
}
}

Edited by: webyildirim on Jan 30, 2013 5:36 AM
  • 1. Re: how to use composite entities which driven by different persistence unit vi
    cdelahun Pro
    Currently Being Moderated
    With so many Hibernate specific settings I'd think you would want to try a hibernate specific forum, or at least try using TopLink/EclipseLink before posting in a TopLink product forum.

    That said, where and why are you getting the exception? If you are just merging or persisting a Topic entity into PU_A, it shouldn't matter that Topic references a detached IntegrationDepartment (any IntegrationDepartment instance read in through PU_B is detached from the PU_A perspective). I can only see this exception occurring if you are using getReference somehow and the entity gets removed or deleted. If that is the case, you might ensure it is fully loaded from PU_B and then detached before associating it to PU_A.
  • 2. Re: how to use composite entities which driven by different persistence unit vi
    webyildirim Newbie
    Currently Being Moderated
    Hello cdelahun,
    Thank you very much for your consideration. Yes it does matter, because after entityManager which driven by PU_A merge the Topic entity, it returns the refreshed version of Topic. But at that point it can not load the IntegrationDepartment topic cause of its mananagement of this entity belonged to another entityManager which driven by PU_B. even if you would be right about detached mentioning, as i understood that i should manual load IntegrationDepartment entiy by PU_BEntityManager just after PU_AEntityManager merge process. That means a manual interception and requires control every process because how can i know an entity that will be merged, has if any entity referenced exists which by driven foreign entityManager?
    brgds
    Sorry for my poor english and hope that you understand.
  • 3. Re: how to use composite entities which driven by different persistence unit vi
    cdelahun Pro
    Currently Being Moderated
    Not quite what I meant - I was suggesting you load the entity immediately after reading it from PU_B, or anytime before associating it into PU_A, so before the merge. What you have not shown though is any code on how you are obtaining IntegrationDepartment and integrating it into PU_A, or what you mean by it is returning a refreshed version of Topic. This problem could also be the result of how your provider works internally - this is a TopLink/EclipseLink forum post so I cannot really tell you why you get the exception other than it would be expected to work as described with EclipseLink as the JPA provider.

    So the best suggestions I can come up with are prefetch your entity, try posting in a hibernate forum, or try using EclipseLink/TopLink so someone here might be better able to help you with any problems that arise.

    Best Regards,
    Chris
  • 4. Re: how to use composite entities which driven by different PU via hibernat
    webyildirim Newbie
    Currently Being Moderated
    Thank you Chris,
    I wrote into hibernate-forum. If any answer arises i will be shared on this thread too

    Edited by: webyildirim on Jan 30, 2013 5:37 AM

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points