geronimo-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Billy Vandory <billy_vand...@yahoo.com>
Subject Re: Geronimo 2.2 + Spring + Hibernate and a Geronimo managed DB Pool with XA driver
Date Sat, 17 Jul 2010 12:57:31 GMT

Hi David, thanks again for your reply. Reading over my emails I can see how
it could be cryptic, as I assume everyone knows everything about what I am
doing :) 

We are  using JPA with hibernate as the provider on geronimo.  We want the
EntityManager injected directly in the DAO via spring, but it seems the
container will not do that, it will only inject inside an EE component, so
we want Spring to handle the injection. This is something that spring
offers, the ability to use the @PersistenceContext in any object
(apparently).  However using the @PersistenceContext annotation in the DAO
results in:

Caused by: javax.naming.NotContextException: jdbc/walmart0192

So then I decided to see if we could inject the entity manager into our EJB
using @PersistenceContext without spring as a test, and that worked fine. 
The next test was to see if we could use a JNDI lookup on the dbpool, in the
EJB directly, and that failed, and then we tried using @Resource in the EJB
and that failed as well.  This was the motivation for doing a lookup inside
the EJB using JNDI - just a test.

This takes me right up to my last msg.

On your advise I added the dependency to my dbpool in my geronimo dd, and
added the following to ejb-jar.xml

<ejb-name>CategoryEJB</ejb-name>
           
<business-remote>com.wakapeek.common.bean.RemoteCategory</business-remote>
            <ejb-class>com.wakapeek.ejb.CategoryEJB</ejb-class> 
            <session-type>Stateless</session-type> 
            <transaction-type>Container</transaction-type> 
            
            <resource-ref>
                <res-ref-name>jdbc/testmydb</res-ref-name>
                <res-type>javax.sql.DataSource</res-type>
                <res-auth>Container</res-auth>
                <res-sharing-scope>Shareable</res-sharing-scope>
            </resource-ref>


Well that worked!  The @Resource injection and JNDI lookup in the EJB now
locate the datasource just great!

I then took all that lookup / resource stuff out of the EJB and reverted to
our earlier config, where the Entity Manager is to be injected into the DAO
via the @PersistenceContext annotation and it fails with the Caused by:
javax.naming.NotContextException: jdbc/walmart0192

(I'm using different db's. Sometimes it's testmydb, the other ones are dev
db's.)

As to the flow of this thing, it's as follows:

This is just a backend EJB layer.  No web server, no servlets, no web.xml,
etc.  Just EJB and JPA on geronimo bundled and deployed as an ear file

So now what is happening is, in a standalone test we lookup a stateless EJB
and invoke a method - A service object is injected into the EJB via spring,
then the DAO is injected into the service object and the entity manager is
(supposed to be) injected into the DAO via the @PersistenceContext
annotation.  This is where it generates the stack trace throwing a
NotContextException.  

In the EJB, this is the method we invoke:

	@Override
	public CategoryDTO getCategoriesTree() {
		// test jndi lookup from this ejb	(THIS NOW WORKS !!) 	
		try {
			InitialContext ctx = new InitialContext();
			DataSource ds = (DataSource) ctx.lookup("java:jdbc/testmydb");
			Connection con = ds.getConnection(); 
		}
		catch (Exception e) {			
			logger.error(e);
		}
		
		// call the service layer
		return categoryService.getCategoriesTree();
	}	


The CategoryService object has the DAO injected via spring.  This service
object is marked as a spring @Service

public void setCategoryDao(CategoryDao dao) {			
    this.categoryDao = dao;
}

And the DAO has the EntityManager injected via spring.  The DAO is marked as
@Transactional

@Required
@PersistenceContext(name = "wakapeek-jpa")	
public void setEntityManager(EntityManager entityManager) {		
	this.em = entityManager;  
}

and again, the same problem: Caused by: javax.naming.NotContextException:
jdbc/walmart0192

So Im not sure why this all works but Spring can't handle it.

I'm going to cross post this into the Spring forum now, as it's behaving
correctly in the EJB.  Thanks very much for all your help and having the
patience to sift through my messages.  If I ever find the solution, I will
definately put up a faq somewhere on dbpool + spring + geronimo + jpa.  It's
been interesting configuring geronimo with hibernate.  If you have any
thoughts, I'd love to hear them! :)

- billworth vandory
-- 
View this message in context: http://apache-geronimo.328035.n3.nabble.com/Geronimo-2-2-Spring-Hibernate-and-a-Geronimo-managed-DB-Pool-with-XA-driver-tp874759p974846.html
Sent from the Users mailing list archive at Nabble.com.

Mime
View raw message