简体   繁体   中英

Hibernate link between 2 persistence units?

my question is a bit tricky so I will try to make it as simple as possible:

I have two maven projects: ProjetA and ProjectB.

ProjectA has the following persistence.xml file:

<persistence-unit name="ProjectAUnit" transaction-type="RESOURCE_LOCAL">
        <class>com.projectA.Client</class>
        <class>com.projectA.InterventionA</class>
    </persistence-unit>

InterventionA has a OneToOne relationship with the Client entity.

ProjectB has the following persistence.xml file:

<persistence-unit name="projectBUnit" transaction-type="RESOURCE_LOCAL">
        <class>com.projectB.InterventionB</class>
        <class>com.projectB.InterventionOrder</class>
</persistence-unit>

InterventionB extends the InterventionA class (contained in a .jar dependency):

All 3 classes InterventionA, InterventionB and Client are defined in the same MySQL schema (schema1).

BUT InterventionB also has a @OneToOne relationship with the InterventionOrder entity defined in another MySQL schema (schema2). private InterventionOrder interventionOrder;

I am getting the following exception:

org.hibernate.AnnotationException: @OneToOne or @ManyToOne on com.projectA.InterventionA.client references an unknown entity: com.projectA.Client

So here is my question: Is why I am trying to achieve even possible with Hibernate/Spring? if yes how? :-) thanks in advance for your help.

InterventionB has inherited the one-to-one relationship between itself and Client (from InterventionA). To be able to define a relationship the target entity must be mapped, in Project B Client is not mapped, hence the error. As Project B depends on Project A you can simply add the target entity to Project B's persistence.xml:

<persistence-unit name="projectBUnit" transaction-type="RESOURCE_LOCAL">
    <class>com.projectB.InterventionB</class>
    <class>com.projectB.InterventionOrder</class>

    <class>com.projectA.Client</class>
</persistence-unit>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM