-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: JPA + JTA and multiple databases
PostPosted: Tue Sep 18, 2007 11:48 am 
Newbie

Joined: Sun Jul 17, 2005 12:25 pm
Posts: 5
I have a problem getting my EntityManagers correctly.
I'm using Hibernate for JPA and JTA (Atomikos) but without application server.
This all does work as expected until I tried to send a query to a second database.
I've setup two persistence units with different datasources in JNDI (the setup and log looks good).
But when I create a new entity manager, the database connection always points to the database first queried. Just to mention: I have two EntityManagerFactories (as expected... :)).

Code:
Connection c = ((HibernateEntityManager) em1).getSession().connection();
DatabaseMetaData dmd = c.getMetaData();
System.out.println("*** *** *** EM URL: " + dmd.getURL());

Connection c = ((HibernateEntityManager) em2).getSession().connection();
DatabaseMetaData dmd = c.getMetaData();
System.out.println("*** *** *** EM URL: " + dmd.getURL());

Both urls are the same... Can anybody give me a hint on how to setup hibernate JPA to use two databases correctly? It does look to me like the EntityManagerFactory both work on the same underlying Session.

Thanks for any help.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 18, 2007 10:26 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Can you post your persistence.xml files?

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 19, 2007 4:02 am 
Newbie

Joined: Sun Jul 17, 2005 12:25 pm
Posts: 5
Code:
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0"
   xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
   <persistence-unit name="emarketing" transaction-type="JTA">
      <jta-data-source>java:comp/env/emarketing</jta-data-source>
      <non-jta-data-source>
         java:comp/env/emarketing
      </non-jta-data-source>
      <class>first.jpa.EntityClass</class>
      <class>first.jpa.OtherEntityClass</class>
      <exclude-unlisted-classes>true</exclude-unlisted-classes>
      <properties>
         <property name="hibernate.transaction.manager_lookup_class"
            value="com.atomikos.icatch.jta.hibernate3.TransactionManagerLookup" />
      </properties>
   </persistence-unit>

   <persistence-unit name="asp" transaction-type="JTA">
      <jta-data-source>java:comp/env/asp</jta-data-source>
      <non-jta-data-source>java:comp/env/asp</non-jta-data-source>
      <class>second.jpa.Class1</class>
      <class>second.jpa.Class2</class>
      <exclude-unlisted-classes>true</exclude-unlisted-classes>
      <properties>
         <property name="hibernate.transaction.manager_lookup_class"
            value="com.atomikos.icatch.jta.hibernate3.TransactionManagerLookup" />
      </properties>
   </persistence-unit>
</persistence>


The datasources are configured in the Tomcat JNDI and are Atomikos non-XA-Datasources.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 19, 2007 4:47 am 
Newbie

Joined: Sun Jul 17, 2005 12:25 pm
Posts: 5
Ok, I found my problem.
I create two different datasources, but both return the same connection.
So there is no problem with hibernate.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.