You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@geronimo.apache.org by Billy Vandory <bi...@yahoo.com> on 2010/06/06 23:39:43 UTC

Geronimo 2.2 + Spring + Hibernate and a Geronimo managed DB Pool with XA driver

This is the 2nd last piece to my puzzle and I will have our app fully ported
to Geronimo.  This piece is kinda critical to the sucess. It's a long
message.

- I have Geronimo 2.2 and Hibernate working great with a container managed
DB POOL
- When I add Spring Support to allow the injection of an Entity Manager, the
process breaks down
- In short, I get a stack trace that says Caused by:
javax.naming.NotContextException: jdbc/wakapeek
- jdbc/wakapeek is the jndi name to my geronimo managed datasource which is
connecting to an external postgres database
- again, every thing works without spring, even the injection of the Entity
Manager in a SLSB 3
- I've tried many different configs, all configs lead to the same exception.
- Seems that Spring is looking for jdbc/wakapeek using InitialContext() and
cannot resolve the JNDI name of the datasource

Here's the config and code.  I was hoping that someone out there is using
Spring + Hibernate + Geronimo with a CM database and could help me solve
this puzzle.
- note, I do not put a ref-resource in web.xml because a) I'm not running
any servlets (bootstrapping spring is done with a singleton spring factory)
and b) I dont think ref-resource is required with Geronimo with a container
managed DB Pool (but i could be wrong)

btw, please let me know if i am breaking rules with posting all my code and
configs.  honestly, i have not had time to read the lists etiquette rules
yet. apologies.

Here's my persistence.xml (it works without SPRING)

[code]
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0"
	xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
	
	<persistence-unit name="wakapeek-jpa" transaction-type="JTA">
		<provider>org.hibernate.ejb.HibernatePersistence</provider>
		<jta-data-source>jdbc/wakapeek</jta-data-source>
		<non-jta-data-source>jdbc/wakapeek</non-jta-data-source>
		<exclude-unlisted-classes>false</exclude-unlisted-classes>
		<properties>			
			<property name="hibernate.transaction.manager_lookup_class"
				value="org.hibernate.transaction.GeronimoTransactionManagerLookup" />
		</properties>
	</persistence-unit>
</persistence>
[/code]

spring config:
[code]
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
	xmlns:tx="http://www.springframework.org/schema/tx"
	xmlns:jee="http://www.springframework.org/schema/jee"
	xsi:schemaLocation="http://www.springframework.org/schema/beans 
	http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
	http://www.springframework.org/schema/tx
	http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
	http://www.springframework.org/schema/aop
	http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
	http://www.springframework.org/schema/jee
	http://www.springframework.org/schema/jee/spring-jee-3.0.xsd">

	<jee:jndi-lookup id="datasource" jndi-name="jdbc/wakapeek" />

	<bean id="persistenceUnitManager"
	
class="org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager">
		<property name="persistenceXmlLocations">
			<list>
				<value>classpath*:META-INF/persistence.xml
				</value>
			</list>
		</property>
		<property name="defaultDataSource" ref="datasource" />
	</bean>

	<bean id="jpaVendorAdapter"
		class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
		<property name="databasePlatform"
value="org.hibernate.dialect.PostgreSQLDialect" />
	</bean>

	<bean id="entityManagerFactory"
	
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
		<property name="persistenceUnitName" value="wakapeek-jpa" />
		<property name="jpaVendorAdapter" ref="jpaVendorAdapter" />
		<property name="persistenceUnitManager" ref="persistenceUnitManager" />
	</bean>

	<bean
	
class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"
/>

	<bean id="transactionManager"
class="org.springframework.orm.jpa.JpaTransactionManager">
		<property name="entityManagerFactory" ref="entityManagerFactory" />
		<property name="datasource" ref="datasource" />
	</bean>

	<tx:annotation-driven transaction-manager="transactionManager" />

</beans>
[/code]

this awesome RA!
[code]
<resourceadapter>
        <outbound-resourceadapter>
            <connection-definition>
               
<connectionfactory-interface>javax.sql.DataSource</connectionfactory-interface>
                <connectiondefinition-instance>
                    <name>jdbc/wakapeek</name>
                    <config-property-setting
name="DatabaseName">wakapeek</config-property-setting>
                    <config-property-setting
name="Password">pass</config-property-setting>
                    <config-property-setting
name="UserName">user</config-property-setting>
                    <config-property-setting
name="ServerName">192.168.0.193</config-property-setting>
                    <config-property-setting name="PrepareThreshold"/>
                    <connectionmanager>
                        <xa-transaction>
                            <transaction-caching/>
                        </xa-transaction>
                        <single-pool>
                            <max-size>10</max-size>
                            <min-size>0</min-size>
                            <match-one/>
                        </single-pool>
                    </connectionmanager>
                </connectiondefinition-instance>
            </connection-definition>
        </outbound-resourceadapter>
    </resourceadapter>
[/code]

and the dump
[code]
Caused by: javax.naming.NotContextException: jdbc/wakapeek
	at
org.apache.xbean.naming.context.AbstractContext.lookup(AbstractContext.java:165)
	at
org.apache.xbean.naming.context.AbstractContext.lookup(AbstractContext.java:605)
	at javax.naming.InitialContext.lookup(InitialContext.java:392)
	at
org.springframework.jndi.JndiTemplate$1.doInContext(JndiTemplate.java:154)
	at org.springframework.jndi.JndiTemplate.execute(JndiTemplate.java:87)
	at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:152)
	at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:178)
	at
org.springframework.jndi.JndiLocatorSupport.lookup(JndiLocatorSupport.java:104)
	at
org.springframework.jndi.JndiObjectLocator.lookup(JndiObjectLocator.java:105)
	at
org.springframework.jndi.JndiObjectFactoryBean.lookupWithFallback(JndiObjectFactoryBean.java:201)
	at
org.springframework.jndi.JndiObjectFactoryBean.afterPropertiesSet(JndiObjectFactoryBean.java:187)
	at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1460)
	at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1400)
	... 57 more
[/code]




-- 
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-tp874759p874759.html
Sent from the Users mailing list archive at Nabble.com.

Re: Geronimo 2.2 + Spring + Hibernate and a Geronimo managed DB Pool with XA driver

Posted by Billy Vandory <bi...@yahoo.com>.
Hi David, thanks very much for that detailed reply.  Yes, I have a dependency
configured in openejb-jar.xml.  I also tried the lookup using the jca: but
it still fails.  

the db is deployed:
jdbc/testmydb  	 default/wakapeek-persist-ear/1.0/ear  	running  	 Edit 
Usage  Delete


this is in openejb-jar which reflects the module name 

[openejb-jar]
<dep:dependency>
            	<dep:groupId>console.dbpool</dep:groupId>
            	<dep:artifactId>jdbc_testmydb</dep:artifactId>
            	<dep:version>1.0</dep:version>
            	<dep:type>car</dep:type>
        	</dep:dependency>   

in the geronimo-application.xml for the ear file i have

<app:module>
		<app:connector>tranql-connector-postgresql-local-1.2.rar</app:connector>
		<app:alt-dd>testmydb.xml</app:alt-dd>
	</app:module>

the testmydb.xml configures the connector, as in my previous post, but
here's the module config from the file:

 <dep:moduleId>
            <dep:groupId>console.dbpool</dep:groupId>
            <dep:artifactId>jdbc_testmydb</dep:artifactId>
            <dep:version>1.0</dep:version>
            <dep:type>car</dep:type>
        </dep:moduleId>

in application.xml for the ear file i have

  <module>
    <ejb>wakapeek-persist-ejb.jar</ejb>
  </module>
  <module>
    <connector>tranql-connector-postgresql-local-1.2.rar</connector>
  </module>

- my ejb project references the tranql connector

- i can have a @PersistenceContext inject the PU in my EJB and it works with
the entity manager

but i still can't do a lookup

here's my lookup now:

try {
	        InitialContext ctx = new InitialContext();
	        DataSource ds = (DataSource)
ctx.lookup("jca:/default/wakapeek-persist-ear/JCAManagedConnectionFactory/testmydb");
	        Connection con = ds.getConnection();
		}
		catch (Exception e) {
			logger.error(e);
		}

using the above jca:/ i get the following:

ERROR [CategoryEJB] javax.naming.NameNotFoundException: testmydb

in geronimo console, jndi viewer->resource adapter module:
*  console.dbpool/jdbc_testmydb_14/1.0/car  

can you give me any other options?



-- 
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-tp874759p974234.html
Sent from the Users mailing list archive at Nabble.com.

Re: Geronimo 2.2 + Spring + Hibernate and a Geronimo managed DB Pool with XA driver

Posted by David Jencks <da...@yahoo.com>.
On Jul 15, 2010, at 9:17 PM, Ivan wrote:

> I think that you might need to define the resource reference in your ejb deployment plan, or server will not map the resource to the bean scope naming context. Or you could directly lookup it by the global naming if the portable application is not your concern.

There are several pieces in this picture that you don't indicate how they relate.  If you have code like:

new InitialContext().lookup("java:comp/env/foo")

in a javaee component such as ejb, servlet, or app client, then you have to indicate that geronimo should put something in the jndi context for that component: the ejb-jar.xml, web.xml, application-client.xml, or use a class-level @Resource annotation.  You can also use an @Resource annotation on a field and geronimo will do the lookup for you.

If you are looking up a datasource, then in the geronimo plan for your app you need to include a dependency on the deployed datasource module (in your example

           <dep:dependency>
           <dep:groupId>console.dbpool</dep:groupId>
           <dep:artifactId>jdbc_testmydb</dep:artifactId>
           <dep:version>1.0</dep:version>
           <dep:type>car</dep:type>
           </dep:dependency>

If the "jdbc/testmydb" part of the lookup matches the name element in the connector plan, then you don't need any other info.  If it doesn't, you also need a resource--ref in the geronimo plan to match up what you are looking up with what is defined.  I'd advise naming the datasource jdbc/testmydb so you don't need this mapping.

The jndi lookup will also work in any object reached in the same thread from a javaee component.  If you are trying to do this kind of lookup in a spring bean, and it is only called from a javaee comonent, and in the same thread, the lookup should work.

You can also directly look up the datasource in global jndi without any configuration using
new InitialContext().lookup("jca:/default/wakapeek-persist-ear/JCAManagedConnectionFactory/testmydb")

hope this helps
david jencks


> 
> 2010/7/16 Billy Vandory <bi...@yahoo.com>
> 
> I'm still having a problem with this.  I've determined it's not spring, it's
> most likely just a configuration issue.  The problem is trying to get a
> lookup to a global database pool in geronimo.  In an SL-EJB I have:
> 
> InitialContext ctx = new InitialContext();
> DataSource ds = (DataSource) ctx.lookup("java:comp/env/jdbc/testmydb");
> Connection con = ds.getConnection();
> 
> and my deployment plan for the db looks like (copied from geronimo's show
> plan button):
> 
> <connector xmlns="http://geronimo.apache.org/xml/ns/j2ee/connector-1.2">
>    <dep:environment
> xmlns:dep="http://geronimo.apache.org/xml/ns/deployment-1.2">
>        <dep:moduleId>
>            <dep:groupId>console.dbpool</dep:groupId>
>            <dep:artifactId>jdbc_testmydb</dep:artifactId>
>            <dep:version>1.0</dep:version>
>            <dep:type>car</dep:type>
>        </dep:moduleId>
>        <dep:dependencies>
>            <dep:dependency>
>                <dep:groupId>postgresql</dep:groupId>
>                <dep:artifactId>postgresql-8.2</dep:artifactId>
>                <dep:version>508.jdbc3</dep:version>
>                <dep:type>jar</dep:type>
>            </dep:dependency>
>        </dep:dependencies>
>    </dep:environment>
>    <resourceadapter>
>        <outbound-resourceadapter>
>            <connection-definition>
> 
> <connectionfactory-interface>javax.sql.DataSource</connectionfactory-interface>
>                <connectiondefinition-instance>
>                    <name>testmydb</name>
>                    <config-property-setting
> name="DatabaseName">walmart0192</config-property-setting>
>                    <config-property-setting
> name="Password"></config-property-setting>
>                    <config-property-setting
> name="UserName">itmgr</config-property-setting>
>                    <config-property-setting
> name="ServerName">192.168.0.10</config-property-setting>
>                    <config-property-setting name="PrepareThreshold"/>
>                    <connectionmanager>
>                        <local-transaction/>
>                        <single-pool>
>                            <max-size>10</max-size>
>                            <min-size>0</min-size>
>                            <match-one/>
>                        </single-pool>
>                    </connectionmanager>
>                </connectiondefinition-instance>
>            </connection-definition>
>        </outbound-resourceadapter>
>    </resourceadapter>
> </connector>
> 
> but i always get the exception:
> 
> 80041:  2010-07-15 21:30:06,442 ERROR [CategoryEJB]
> javax.naming.NotContextException: jdbc/testmydb
> 
> Note that I am not running a web app, just an EJB backend, so I am not
> configuring anything in web.xml.  is the configuration in web.xml required?
> I tried it and its the same result, but I would like to rule this out, that
> web.xml resource-ref config is not required if not running in a web app.
> 
> The JNDI name under geronimo's JNDI viewer is: (resource adapters)
> console.dbpool/testmydb/1.0/car
> 
> also shows:
> jca:/default/wakapeek-persist-ear/JCAManagedConnectionFactory/testmydb
> 
> In the geronimo deployment plan i have a connector defined:
> 
> <app:module>
>  <app:connector>tranql-connector-postgresql-local-1.2.rar</app:connector>
>  <app:alt-dd>testmydb.xml</app:alt-dd>
> </app:module>
> 
> Using dbpool in the geronimo console, i can query this database just fine.'
> 
> Any ideas?  Thanks alot.
> Billy
> 
> 
> 
> --
> 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-tp874759p971182.html
> Sent from the Users mailing list archive at Nabble.com.
> 
> 
> 
> -- 
> Ivan


Re: Geronimo 2.2 + Spring + Hibernate and a Geronimo managed DB Pool with XA driver

Posted by David Jencks <da...@yahoo.com>.
On Jul 17, 2010, at 5:57 AM, Billy Vandory wrote:

> 
> 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");

Really? it shouldn't: this should work:

			DataSource ds = (DataSource) ctx.lookup("java:comp/env/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.

Can you show the spring configuration for the PU?  Does it reuse the same persistence.xml as geronimo finds?  I think that for spring you need to specify jndi names for the jta-datasource and non-jta-datasource and for geronimo you definitely can't.  So you may need to turn off the jpa deployer in geronimo before deploying your ear to avoid conflicts.  I also don't know what triggers spring to actually try to get the datasource from jndi.  If it's done in a thread called from your ejb, then, if you keep the stuff so the jndi lookup works in the ejb, you can use the same jndi name in the configuration for spring, (the name I think should be "java:comp/env/jdbc/testmydb")  If it's called in some other thread you'll have to use the jca: name that doesn't seem to work yet.

The jca name should be printed out in the log... so please check that you are using the one that is printed, maybe some configuration changed and so did the name.

thanks
david jencks

> 
> 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.


Re: Geronimo 2.2 + Spring + Hibernate and a Geronimo managed DB Pool with XA driver

Posted by Billy Vandory <bi...@yahoo.com>.
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.

Re: Geronimo 2.2 + Spring + Hibernate and a Geronimo managed DB Pool with XA driver

Posted by David Jencks <da...@yahoo.com>.
Hi Billy,

We're having a little bit of a communication problem.  I know how geronimo works pretty well but I don't know anything about your app.  You know how your app is put together but are wondering how it relates to geronimo.   I can't give you very good advice unless I know more about what you are trying to do.

Maybe you could show the progress of a typical request through the components in your app, and indicate in each component what gets injected, what gets looked up in jndi, and what gets passed on to the next component,, where transaction boundaries are, and where the problem occurs?


On Jul 16, 2010, at 9:11 PM, Billy Vandory wrote:

> 
> Thanks for the answer, would you be able to tell me how I can identify the
> global name?

global name of what?

> Also, I've searched for how to configure this in the openejb
> config file, but i can't locate a configuration for a geronimo db pool. 
> normally, id keep looking, but i really need to get this going.. 

openejb config file == ??  openejb-jar.xml??

> 
> this project went into performance testing with a workaround (we inject the
> PU in the ejb using the @PersistenceContext annotation, then we pass the EM
> to the constructor of the DAO.

DAO == ?

> but of course, it caused massive threading
> issues on the entity manager.  
> 
> Btw, I'll have to note that the EntityManager is being injected into the EJB
> just fine and can use the DB - that's what's puzzling.  I can't do a JNDI
> lookup but the @PersistenceContext has no problems doing it.

In geronimo (2.x anyway) persistence units aren't configured using jndi.  the jta-datasource and non-jta-datasource are, directly, the name specified in the datasource configuration.  Just because the persistence unit can find them through non-jndi means does not mean that your app can access the datasource.  You need an @Resource injection or a resource-ref.
> 
> You might be asking, well, if the EM is being injected, why are you looking
> it up?  The answer is because we need to inject the PU directly into the DAO
> via spring, and spring does a JNDI lookup on the DBPool...  

What exactly do you mean by PU?  what does spring have to do with it?  If you have configured spring to set up a persistence unit through whatever means spring uses, it's not, AFAIK, going to share a cache with the one geronimo sets up.  So if you do some work on jpa entities in your ejb, and then in the same transaction do some more work on the same entities looked up in a spring bean, they probably won't see each others changes on the "same" object.  If all your jpa entity work is done in spring, you won't have this problem, but then you won't need the persistence context ref in your ejb.at y

If you want to share the cache then you should not define a persistence unit in spring but pass the EM or EMF from your ejb into your spring beans.

(it's possible that  your jpa provider somehow recognizes that both persistence units are referring to the same stuff and figures out how to share a cache, but I don't know how this would work)

> 
> I'd really appreciate it if you could send me some config examples, or how
> to look it up globally, as you mentioned, i'm really at a dead end with
> this.. I've assigned two guys to trace the code, 1 guy to trace why the PU
> is being injected and one guy to find out why the JNDI is failing.. but it's
> friday at midnight and they want to go home.. :(
> 

One of your previous emails showed the global jndi name for your datasource, so I thought you were aware of it.  It's printed out in the geronimo.log as the datasource is started.

jca:/default/wakapeek-persist-ear/JCAManagedConnectionFactory/testmydb

You should be able to use that in the spring configuration.

Alternatively if you include a resource-ref like

<resource-ref>
<resource-ref-name>testmydb</resource-ref-name>
<resource-ref-type>javax.sql.DataSource</resource-ref-type>
</resource-ref>

in your ejb-jar.xml for any ejbs that call spring then you can use the jndi name

java:comp/env/testmydb

either in your ejb or in spring.

Hope this helps and that I'm starting to understand what you are asking about...
david jencks

> 
> -- 
> 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-tp874759p974144.html
> Sent from the Users mailing list archive at Nabble.com.


Re: Geronimo 2.2 + Spring + Hibernate and a Geronimo managed DB Pool with XA driver

Posted by Billy Vandory <bi...@yahoo.com>.
Thanks for the answer, would you be able to tell me how I can identify the
global name? Also, I've searched for how to configure this in the openejb
config file, but i can't locate a configuration for a geronimo db pool. 
normally, id keep looking, but i really need to get this going.. 

this project went into performance testing with a workaround (we inject the
PU in the ejb using the @PersistenceContext annotation, then we pass the EM
to the constructor of the DAO. but of course, it caused massive threading
issues on the entity manager.  

Btw, I'll have to note that the EntityManager is being injected into the EJB
just fine and can use the DB - that's what's puzzling.  I can't do a JNDI
lookup but the @PersistenceContext has no problems doing it.

You might be asking, well, if the EM is being injected, why are you looking
it up?  The answer is because we need to inject the PU directly into the DAO
via spring, and spring does a JNDI lookup on the DBPool...  

I'd really appreciate it if you could send me some config examples, or how
to look it up globally, as you mentioned, i'm really at a dead end with
this.. I've assigned two guys to trace the code, 1 guy to trace why the PU
is being injected and one guy to find out why the JNDI is failing.. but it's
friday at midnight and they want to go home.. :(


-- 
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-tp874759p974144.html
Sent from the Users mailing list archive at Nabble.com.

Re: Geronimo 2.2 + Spring + Hibernate and a Geronimo managed DB Pool with XA driver

Posted by Ivan <xh...@gmail.com>.
I think that you might need to define the resource reference in your ejb
deployment plan, or server will not map the resource to the bean scope
naming context. Or you could directly lookup it by the global naming if the
portable application is not your concern.

2010/7/16 Billy Vandory <bi...@yahoo.com>

>
> I'm still having a problem with this.  I've determined it's not spring,
> it's
> most likely just a configuration issue.  The problem is trying to get a
> lookup to a global database pool in geronimo.  In an SL-EJB I have:
>
> InitialContext ctx = new InitialContext();
> DataSource ds = (DataSource) ctx.lookup("java:comp/env/jdbc/testmydb");
> Connection con = ds.getConnection();
>
> and my deployment plan for the db looks like (copied from geronimo's show
> plan button):
>
> <connector xmlns="http://geronimo.apache.org/xml/ns/j2ee/connector-1.2">
>    <dep:environment
> xmlns:dep="http://geronimo.apache.org/xml/ns/deployment-1.2">
>        <dep:moduleId>
>            <dep:groupId>console.dbpool</dep:groupId>
>            <dep:artifactId>jdbc_testmydb</dep:artifactId>
>            <dep:version>1.0</dep:version>
>            <dep:type>car</dep:type>
>        </dep:moduleId>
>        <dep:dependencies>
>            <dep:dependency>
>                <dep:groupId>postgresql</dep:groupId>
>                <dep:artifactId>postgresql-8.2</dep:artifactId>
>                <dep:version>508.jdbc3</dep:version>
>                <dep:type>jar</dep:type>
>            </dep:dependency>
>        </dep:dependencies>
>    </dep:environment>
>     <resourceadapter>
>        <outbound-resourceadapter>
>            <connection-definition>
>
>
> <connectionfactory-interface>javax.sql.DataSource</connectionfactory-interface>
>                <connectiondefinition-instance>
>                     <name>testmydb</name>
>                    <config-property-setting
> name="DatabaseName">walmart0192</config-property-setting>
>                    <config-property-setting
> name="Password"></config-property-setting>
>                    <config-property-setting
> name="UserName">itmgr</config-property-setting>
>                    <config-property-setting
> name="ServerName">192.168.0.10</config-property-setting>
>                     <config-property-setting name="PrepareThreshold"/>
>                    <connectionmanager>
>                         <local-transaction/>
>                         <single-pool>
>                            <max-size>10</max-size>
>                            <min-size>0</min-size>
>                            <match-one/>
>                        </single-pool>
>                    </connectionmanager>
>                </connectiondefinition-instance>
>            </connection-definition>
>        </outbound-resourceadapter>
>    </resourceadapter>
> </connector>
>
> but i always get the exception:
>
> 80041:  2010-07-15 21:30:06,442 ERROR [CategoryEJB]
> javax.naming.NotContextException: jdbc/testmydb
>
> Note that I am not running a web app, just an EJB backend, so I am not
> configuring anything in web.xml.  is the configuration in web.xml required?
> I tried it and its the same result, but I would like to rule this out, that
> web.xml resource-ref config is not required if not running in a web app.
>
> The JNDI name under geronimo's JNDI viewer is: (resource adapters)
> console.dbpool/testmydb/1.0/car
>
> also shows:
> jca:/default/wakapeek-persist-ear/JCAManagedConnectionFactory/testmydb
>
> In the geronimo deployment plan i have a connector defined:
>
> <app:module>
>  <app:connector>tranql-connector-postgresql-local-1.2.rar</app:connector>
>  <app:alt-dd>testmydb.xml</app:alt-dd>
> </app:module>
>
> Using dbpool in the geronimo console, i can query this database just fine.'
>
> Any ideas?  Thanks alot.
> Billy
>
>
>
> --
> 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-tp874759p971182.html
> Sent from the Users mailing list archive at Nabble.com.
>



-- 
Ivan

Re: Geronimo 2.2 + Spring + Hibernate and a Geronimo managed DB Pool with XA driver

Posted by Billy Vandory <bi...@yahoo.com>.
I'm still having a problem with this.  I've determined it's not spring, it's
most likely just a configuration issue.  The problem is trying to get a
lookup to a global database pool in geronimo.  In an SL-EJB I have:

InitialContext ctx = new InitialContext();
DataSource ds = (DataSource) ctx.lookup("java:comp/env/jdbc/testmydb");
Connection con = ds.getConnection();

and my deployment plan for the db looks like (copied from geronimo's show
plan button):

<connector xmlns="http://geronimo.apache.org/xml/ns/j2ee/connector-1.2">
    <dep:environment
xmlns:dep="http://geronimo.apache.org/xml/ns/deployment-1.2">
        <dep:moduleId>
            <dep:groupId>console.dbpool</dep:groupId>
            <dep:artifactId>jdbc_testmydb</dep:artifactId>
            <dep:version>1.0</dep:version>
            <dep:type>car</dep:type>
        </dep:moduleId>
        <dep:dependencies>
            <dep:dependency>
                <dep:groupId>postgresql</dep:groupId>
                <dep:artifactId>postgresql-8.2</dep:artifactId>
                <dep:version>508.jdbc3</dep:version>
                <dep:type>jar</dep:type>
            </dep:dependency>
        </dep:dependencies>
    </dep:environment>
    <resourceadapter>
        <outbound-resourceadapter>
            <connection-definition>
               
<connectionfactory-interface>javax.sql.DataSource</connectionfactory-interface>
                <connectiondefinition-instance>
                    <name>testmydb</name>
                    <config-property-setting
name="DatabaseName">walmart0192</config-property-setting>
                    <config-property-setting
name="Password"></config-property-setting>
                    <config-property-setting
name="UserName">itmgr</config-property-setting>
                    <config-property-setting
name="ServerName">192.168.0.10</config-property-setting>
                    <config-property-setting name="PrepareThreshold"/>
                    <connectionmanager>
                        <local-transaction/>
                        <single-pool>
                            <max-size>10</max-size>
                            <min-size>0</min-size>
                            <match-one/>
                        </single-pool>
                    </connectionmanager>                    
                </connectiondefinition-instance>                
            </connection-definition>
        </outbound-resourceadapter>
    </resourceadapter>
</connector>

but i always get the exception:

80041:  2010-07-15 21:30:06,442 ERROR [CategoryEJB]
javax.naming.NotContextException: jdbc/testmydb

Note that I am not running a web app, just an EJB backend, so I am not
configuring anything in web.xml.  is the configuration in web.xml required? 
I tried it and its the same result, but I would like to rule this out, that
web.xml resource-ref config is not required if not running in a web app.

The JNDI name under geronimo's JNDI viewer is: (resource adapters)
console.dbpool/testmydb/1.0/car  

also shows:
jca:/default/wakapeek-persist-ear/JCAManagedConnectionFactory/testmydb

In the geronimo deployment plan i have a connector defined:

<app:module>
  <app:connector>tranql-connector-postgresql-local-1.2.rar</app:connector>
  <app:alt-dd>testmydb.xml</app:alt-dd>
</app:module>

Using dbpool in the geronimo console, i can query this database just fine.'

Any ideas?  Thanks alot.
Billy



-- 
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-tp874759p971182.html
Sent from the Users mailing list archive at Nabble.com.

Re: Geronimo 2.2 + Spring + Hibernate and a Geronimo managed DB Pool with XA driver

Posted by Kevan Miller <ke...@gmail.com>.
On Jun 6, 2010, at 5:39 PM, Billy Vandory wrote:

> 
> This is the 2nd last piece to my puzzle and I will have our app fully ported
> to Geronimo.  This piece is kinda critical to the sucess. It's a long
> message.
> 
> - I have Geronimo 2.2 and Hibernate working great with a container managed
> DB POOL
> - When I add Spring Support to allow the injection of an Entity Manager, the
> process breaks down
> - In short, I get a stack trace that says Caused by:
> javax.naming.NotContextException: jdbc/wakapeek
> - jdbc/wakapeek is the jndi name to my geronimo managed datasource which is
> connecting to an external postgres database
> - again, every thing works without spring, even the injection of the Entity
> Manager in a SLSB 3
> - I've tried many different configs, all configs lead to the same exception.
> - Seems that Spring is looking for jdbc/wakapeek using InitialContext() and
> cannot resolve the JNDI name of the datasource
> 
> Here's the config and code.  I was hoping that someone out there is using
> Spring + Hibernate + Geronimo with a CM database and could help me solve
> this puzzle.
> - note, I do not put a ref-resource in web.xml because a) I'm not running
> any servlets (bootstrapping spring is done with a singleton spring factory)
> and b) I dont think ref-resource is required with Geronimo with a container
> managed DB Pool (but i could be wrong)
> 
> btw, please let me know if i am breaking rules with posting all my code and
> configs.  honestly, i have not had time to read the lists etiquette rules
> yet. apologies.

That's fine. I prefer inline text to attachments in dev/user list postings... As an alternative, you can create a Jira and upload files to a Jira issue.

You don't have your jndi name correct, I think. There's a JNDI Viewer in the admin console, which ought to be useful. Alternatively, post a Jira and somebody could have a look...

--kevan