-->
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.  [ 3 posts ] 
Author Message
 Post subject: Using the same datasource for both Hibernate and CMP-EJBs
PostPosted: Tue Aug 10, 2004 9:11 am 
Newbie

Joined: Mon Aug 09, 2004 10:28 am
Posts: 4
Location: Sweden
Environment: Websphere 5, EJB 2.0, stateless EJBs for declarative transaction demarcation, DB2, Hibernate 2.1.3.


I have a single database with tables from a previous project using CMP-EJBs.
In my new project I would like to use Hibernate to access the database, but with completely new tables.
All old data in the old tables will still be access via the CMP-EJBs.


The new application may sometimes need to access the old tables in order to read old data.
After that data may be written to one of the new tables using Hibernate. Like this:

Code:
class EJBFacade {

   public void moveData {   // transaction declared as REQUIRED
      data = readOldDataWithCMP();   // (1)
      saveAsNewDataWithHibernate(data);  // (2)
   }

}


Since we have a known problem with our IBM JDBC-driver (it does not handle 2PC) I want to use the same
datasource for both CMPs and Hibernate.
If I comment out either of the statements (1) or (2) the other will function as expected in isolation.
But when I try to run them in sequence I cannot get this to work...

The first access to the database (1) goes fine, data is retrieved.
But when Hibernate (2) tries to associate with the transaction the following mewssage is output:

An illegal attempt to use multiple resources that have only one-phase capability has occurred within a global transaction.

But I am only using a single datasource!
Any ideas on how I may get this to work?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 11, 2004 11:55 pm 
Beginner
Beginner

Joined: Mon Aug 09, 2004 12:31 pm
Posts: 47
Location: New York, NY, USA
I suppose Hibernate creates its own connection, which tries to start a new transaction. What is the transaction control on the EJB?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 12, 2004 2:52 am 
Newbie

Joined: Mon Aug 09, 2004 10:28 am
Posts: 4
Location: Sweden
I finally got it to work.

The trick is to use the exact same settings for all references to the datasource. In the ejb-facade I have one reference with settings:

Code:
authentication: container
sharing scope: sharable


and then there is also another sneaky reference in the the deployment descriptor for the cmp-ejb-jar which details which datasource should be used for all cmp-db-access for that jar and I used the following settings for this one:

Code:
container authorization type: container


I had set this one to "per_connection_factory" before which made the container unable to resue the connection previously used by Hibernate and thus the container thought two different datasources were used.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.