Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #10181

Re: JPA OneToOne annotation across two different jdbc drivers

From "Jeffrey H. Coffield" <jeffrey@digitalsynergyinc.com>
Newsgroups comp.lang.java.programmer
Subject Re: JPA OneToOne annotation across two different jdbc drivers
Date 2011-11-22 16:26 -0800
Organization A noiseless patient Spider
Message-ID <jaheje$34l$1@dont-email.me> (permalink)
References <jaes5h$8bo$1@dont-email.me> <26839074.317.1321974960424.JavaMail.geo-discussion-forums@prdy11>

Show all headers | View raw



On 11/22/2011 07:16 AM, Lew wrote:
> Jeffrey H. Coffield wrote:
>> We have data in two different databases types (MySQL and OpenVMS). Both
>> have JDBC drivers. Does someone have an example of using the JPA
>> annotations to connect across two different persistence units?
>
> What, precisely, do you mean by "connect across two different persistence units"?
>
> You can connect to two persistence units by defining two 'EntityManager' instances, one for each PU.
>
> Is that what you're asking for?
>
> Which annotations did you have in mind?  Certainly '@Entity' and '@EntityManager' will work with multiple persistence units.  Of course, annotations like '@OneToMany' will not, AFAIK, since they map to foreign-key relationships in the DBMS.
>
I had in mind specifically the annotation in the subject. OneToOne. With 
that, I think I could get the rest to work or understand the problems 
better.

Although the OneToOne and OneToMany use foreign key information when you 
generate entity classes from a database,in my testing, they do not 
generate SQL joins. The JDBC driver for OpenVMS is one I wrote myself 
and I have spent a considerable amount of time in the last three months 
debugging and testing it to get it to work correctly with NetBeans and 
JPA. The driver is currently in beta testing at a customer site and the 
question about annotations came up.

If you have a class A with a OneToOne or a OneToMany relation to class 
B, you get a query to load class A and then a separate query to load a 
either class B or collection of class B. This works with either driver 
as long as the foreign keys information is available. This could work 
across two different persistence units as long as the right query gets 
sent to the right driver and that information is in the persistence.xml 
file.

So, to be precise, I have two different databases, both with JDBC 
drivers. The persistence.xml file defines two persistence units and from 
each I can create an EntityManagerFactory and get an EntityManager and 
then do queries on each. Now there is the problem of annotations. Which 
annotations to be precise? Well, how about the one in the subject, 
OneToOne. Now I ask (quite precisely):

"Does someone have an example of using the JPA annotations to connect 
across two different persistence units?"

But perhaps someone has an example of an annotation other that OneToOne. 
That could also be helpful as I would like to understand more about how 
the annotations work, so I left out of the question which annotation.

Since there is no way to define in either database a foreign key that 
crossed the two databases, if an annotation could work, it would have to 
be added manually. We know how to change the entity classes directly to 
do this without using annotations, but would prefer the annotation 
approach as it should be more clear, more consistent and (hopefully) 
less code to debug.

Jeff Coffield




Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

JPA OneToOne annotation across two different jdbc drivers "Jeffrey H. Coffield" <jeffrey@digitalsynergyinc.com> - 2011-11-21 16:59 -0800
  Re: JPA OneToOne annotation across two different jdbc drivers Robert Klemme <shortcutter@googlemail.com> - 2011-11-22 07:02 -0800
  Re: JPA OneToOne annotation across two different jdbc drivers Lew <lewbloch@gmail.com> - 2011-11-22 07:16 -0800
    Re: JPA OneToOne annotation across two different jdbc drivers jlp <jlp@jlp.com> - 2011-11-22 19:14 +0100
    Re: JPA OneToOne annotation across two different jdbc drivers "Jeffrey H. Coffield" <jeffrey@digitalsynergyinc.com> - 2011-11-22 16:26 -0800
      Re: JPA OneToOne annotation across two different jdbc drivers "Jeffrey H. Coffield" <jeffrey@digitalsynergyinc.com> - 2011-11-22 18:34 -0800
        Re: JPA OneToOne annotation across two different jdbc drivers Arved Sandstrom <asandstrom3minus1@eastlink.ca> - 2011-11-23 07:32 -0400
          Re: JPA OneToOne annotation across two different jdbc drivers Arne Vajhøj <arne@vajhoej.dk> - 2011-11-25 21:41 -0500
        Re: JPA OneToOne annotation across two different jdbc drivers "Jeffrey H. Coffield" <jeffrey@digitalsynergyinc.com> - 2011-11-27 16:07 -0800
          Re: JPA OneToOne annotation across two different jdbc drivers Arved Sandstrom <asandstrom3minus1@eastlink.ca> - 2011-11-28 06:42 -0400
      Re: JPA OneToOne annotation across two different jdbc drivers Lew <lewbloch@gmail.com> - 2011-11-23 12:38 -0800
        Re: JPA OneToOne annotation across two different jdbc drivers Gene Wirchenko <genew@ocis.net> - 2011-11-23 14:52 -0800
          Re: JPA OneToOne annotation across two different jdbc drivers Arne Vajhøj <arne@vajhoej.dk> - 2011-11-25 21:37 -0500
            Re: JPA OneToOne annotation across two different jdbc drivers Gene Wirchenko <genew@ocis.net> - 2011-11-26 21:22 -0800
              Re: JPA OneToOne annotation across two different jdbc drivers Arne Vajhøj <arne@vajhoej.dk> - 2011-12-02 21:03 -0500
  Re: JPA OneToOne annotation across two different jdbc drivers Arne Vajhøj <arne@vajhoej.dk> - 2011-11-25 21:38 -0500

csiph-web