You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by Jon Carrera <jc...@quarksoft.net> on 2008/06/05 18:30:12 UTC

Help with OpenEJB3 and Spring IoC

I've been playing with OpenEJB for a few days now trying to make it work with
an application that uses an EJB facade that delegates to a spring-managed
service pojo that relies on an EAO to retrieve and persist data. So far
OpenEJB works fine as a container for the ejb, but i can't still figure out
how can I inject the PersistenceContext created by OpenEJB to the EAO via
Spring IoC.

The EAO is a simple class that relies on the EntityManager to perform
persistence operations:


public class GenericEaoJpa<E, PK extends Serializable> implements
GenericEao<E, PK> {
	protected final Log log = LogFactory.getLog(getClass());
    private Class<E> persistentClass;
    
    @PersistenceContext(unitName="ApplicationEntityManager")
    private EntityManager em;
        
	public GenericEaoJpa(Class <E> persistentClass) {
		super();
		this.persistentClass = persistentClass;
	}

	public boolean exists(Serializable id) {
		E entity = em.find(persistentClass, id);
		return entity == null? false:true;
	}

	public E get(PK id) {
		E entity = em.find(persistentClass, id);
		if (entity == null) {
            log.warn("Uh oh, '" + this.persistentClass + "' object with id
'" + id + "' not found...");
            throw new ObjectRetrievalFailureException(this.persistentClass,
id);
        }

        return entity;
	}

	public List<E> getAll() {
		// TODO Auto-generated method stub
		return em.createQuery("select " +
persistentClass.getName()).getResultList();
	}

	public void remove(PK id) {
		E entity = get(id);
		em.remove(entity);

	}
	
	public E save(E entity) {
		em.persist(entity);
		return entity;
	}

}


I use the following code to initialize the openejb context in my test case:


Properties p = new Properties();
        p.put(Context.INITIAL_CONTEXT_FACTORY,
"org.apache.openejb.client.LocalInitialContextFactory");
        p.put("myDs", "new://Resource?type=DataSource");
        p.put("myDs.JdbcDriver", "com.mysql.jdbc.Driver");
        p.put("myDs.JdbcUrl",
"jdbc:mysql://localhost/midastest?createDatabaseIfNotExist=true&amp;useUnicode=true&amp;characterEncoding=utf-8");
        p.put("myDs.UserName", "root");
        p.put("myDs.Password", "");

        this.context = new InitialContext(p);
       
        ServiceFacadeBean service = (ServiceFacadeBean) context
					.lookup("ServiceFacadeBeanLocal");



persistence.xml is defined as follows:


	<persistence-unit name="ApplicationEntityManager"
		transaction-type="JTA">
		<provider>org.hibernate.ejb.HibernatePersistence</provider>
		<jta-data-source>myDs</jta-data-source>
		<class>model.MyEntity</class>
		<properties>
         <property name="hibernate.dialect"
value="org.hibernate.dialect.HSQLDialect"/>
         <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
         <property name="hibernate.transaction.manager_lookup_class"
               
value="org.apache.openejb.hibernate.TransactionManagerLookup"/>
      </properties>
	</persistence-unit>


Now, my problem is in the spring application context configuration file. I
don't know if it is possible to obtain the EntityManager from the openejb
jndi context or if there is an EntityManagerFactory in openejb that i can
use to inject it to my EAO Pojo. An idea that ocurred to me is to use
spring's LocalContainerEntityManagerFactoryBean and pass the dataSource from
the openejb jndi context



<bean id="dataSource"
	        class="org.springframework.jndi.JndiObjectFactoryBean">
	        <property name="jndiName" value="java:openejb/Resource/myDs"/>
	        <property name="jndiEnvironment">
	            <props>
	                <prop key="java.naming.factory.initial">
	                    org.apache.openejb.client.LocalInitialContextFactory
	                </prop>
	            </props>
	        </property>
		</bean> 

<bean id="entityManagerFactory"
	
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
                <property name="dataSource" ref="dataSource">
		<property name="jpaVendorAdapter">
			<bean
				class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
				<property name="database" value="MYSQL" />
				<property name="showSql" value="true" />
			</bean>
		</property>
	</bean>

<!-- bean post-processor for JPA annotations -->
	<bean
	
class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"
/>

       <bean id="MyEntityEao"
		class="eao.jpa.GenericEaoJpa">
		<constructor-arg
			value="model.MyEntity" />
	</bean>


I get the following error when running the test

Invocation of init method failed; nested exception is javax.naming.N
ameNotFoundException: Name "java:openejb/Resource/myDs" not found.
Caused by: javax.naming.NameNotFoundException: Name
"java:openejb/Resource/myDs"
 not found.
        at
org.apache.openejb.core.ivm.naming.IvmContext.federate(IvmContext.jav
a:172)
        at
org.apache.openejb.core.ivm.naming.IvmContext.lookup(IvmContext.java:
129)
        at javax.naming.InitialContext.lookup(InitialContext.java:351)
        at
org.springframework.jndi.JndiTemplate$1.doInContext(JndiTemplate.java
:123)
        at
org.springframework.jndi.JndiTemplate.execute(JndiTemplate.java:85)
        at
org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:121)
        at
org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:146)
        at
org.springframework.jndi.JndiLocatorSupport.lookup(JndiLocatorSupport
.java:93)
        at
org.springframework.jndi.JndiObjectLocator.lookup(JndiObjectLocator.j
ava:105)
        at
org.springframework.jndi.JndiObjectFactoryBean.lookupWithFallback(Jnd
iObjectFactoryBean.java:197)
        at
org.springframework.jndi.JndiObjectFactoryBean.afterPropertiesSet(Jnd
iObjectFactoryBean.java:184)
        at
org.springframework.beans.factory.support.AbstractAutowireCapableBean
Factory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1202)
        at
org.springframework.beans.factory.support.AbstractAutowireCapableBean
Factory.initializeBean(AbstractAutowireCapableBeanFactory.java:1172)
        at
org.springframework.beans.factory.support.AbstractAutowireCapableBean
Factory.createBean(AbstractAutowireCapableBeanFactory.java:428)
        at
org.springframework.beans.factory.support.AbstractBeanFactory$1.getOb
ject(AbstractBeanFactory.java:251)
        at
org.springframework.beans.factory.support.DefaultSingletonBeanRegistr
y.getSingleton(DefaultSingletonBeanRegistry.java:156)
        at
org.springframework.beans.factory.support.AbstractBeanFactory.getBean
(AbstractBeanFactory.java:248)
        at
org.springframework.beans.factory.support.AbstractBeanFactory.getBean
(AbstractBeanFactory.java:160)
        at
org.springframework.beans.factory.support.BeanDefinitionValueResolver
.resolveReference(BeanDefinitionValueResolver.java:261)
        at
org.springframework.beans.factory.support.BeanDefinitionValueResolver
.resolveValueIfNecessary(BeanDefinitionValueResolver.java:109)
        at
org.springframework.beans.factory.support.AbstractAutowireCapableBean
Factory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1100)
        at
org.springframework.beans.factory.support.AbstractAutowireCapableBean
Factory.populateBean(AbstractAutowireCapableBeanFactory.java:862)
        at
org.springframework.beans.factory.support.AbstractAutowireCapableBean
Factory.createBean(AbstractAutowireCapableBeanFactory.java:424)
        at
org.springframework.beans.factory.support.AbstractBeanFactory$1.getOb
ject(AbstractBeanFactory.java:251)
        at
org.springframework.beans.factory.support.DefaultSingletonBeanRegistr
y.getSingleton(DefaultSingletonBeanRegistry.java:156)
        at
org.springframework.beans.factory.support.AbstractBeanFactory.getBean
(AbstractBeanFactory.java:248)
        at
org.springframework.beans.factory.support.AbstractBeanFactory.getBean
(AbstractBeanFactory.java:160)


I've been trying to retrieve the datasource from the jndi context with
different naming conventions with no success.

Maybe this is not the correct approach to solve the problem, so any advice
would be very appreciated.

Thanks in advance.

-- 
View this message in context: http://www.nabble.com/Help-with-OpenEJB3-and-Spring-IoC-tp17674222p17674222.html
Sent from the OpenEJB User mailing list archive at Nabble.com.


Re: Help with OpenEJB3 and Spring IoC

Posted by Karan Malhi <ka...@gmail.com>.
Christian,

Added the links to the page. Thank you very much, this is great info

On Thu, Jul 31, 2008 at 3:01 AM, Christian Schuhegger <
Christian.Schuhegger@gmx.de> wrote:

> Hello,
>
> David Blevins wrote:
>
>> Many thanks to you, Jon!  We definitely appreciate your time as well.
>>  I've crafted up a doc that attempts to summarize the information in this
>> thread:
>>
>> http://cwiki.apache.org/OPENEJBx30/spring.html
>>
>> (should sync to http://openejb.apache.org/3.0/spring.html in an hour or
>> so)
>>
>
> this is only half of the story, e.g. it only explains how to make available
> components from openejb to spring, but not the other way round. The other
> half is described here:
>
> http://twasink.net/blog/archives/2007/01/using_spring_wi.html
>
> http://static.springframework.org/spring/docs/2.5.x/api/org/springframework/ejb/interceptor/SpringBeanAutowiringInterceptor.html
> http://wiki.netbeans.org/MavenSpringEJBsOnGlassfish
>
> Perhaps these links could be added to the documentation page?
>
> Thanks and have a nice day,
> --
> Christian Schuhegger
> http://www.el-chef.de/
>
>


-- 
Karan Singh Malhi

Re: Help with OpenEJB3 and Spring IoC

Posted by Christian Schuhegger <Ch...@gmx.de>.
Hello,

David Blevins wrote:
> Many thanks to you, Jon!  We definitely appreciate your time as well.  
> I've crafted up a doc that attempts to summarize the information in this 
> thread:
> 
> http://cwiki.apache.org/OPENEJBx30/spring.html
> 
> (should sync to http://openejb.apache.org/3.0/spring.html in an hour or so)

this is only half of the story, e.g. it only explains how to make 
available components from openejb to spring, but not the other way 
round. The other half is described here:

http://twasink.net/blog/archives/2007/01/using_spring_wi.html
http://static.springframework.org/spring/docs/2.5.x/api/org/springframework/ejb/interceptor/SpringBeanAutowiringInterceptor.html
http://wiki.netbeans.org/MavenSpringEJBsOnGlassfish

Perhaps these links could be added to the documentation page?

Thanks and have a nice day,
-- 
Christian Schuhegger
http://www.el-chef.de/


Re: Help with OpenEJB3 and Spring IoC

Posted by David Blevins <da...@visi.com>.
Jon, this is great!

Very interesting technique on getting the OpenEJB TransactionManager  
plugged into Spring.  I suppose that is one of the tweaks that are  
required for anything that's a subclass of  
AbstractTransactionalSpringContextTests?

Hopefully I can get the doc updated in the next day or two.

Thank you very much!

-David


On Jun 16, 2008, at 4:52 PM, Jon Carrera wrote:

>
>
> Here are the results i got after trying out all spring abstract  
> support
> classes for JUnit :
>
>
>
>
> Spring Test Superclass
> Test result
> Problem
>
>
> org.springframework.test.AbstractDependencyInjectionSpringContextTests
> Pass
> &nbsp;
>
>
> org.springframework.test.AbstractTransactionalSpringContextTests
> Pass
> &nbsp;
>
>
> org.springframework.test.AbstractSingleSpringContextTests
> Pass
> &nbsp;
>
>
> org 
> .springframework 
> .test.AbstractTransactionalDataSourceSpringContextTests
> Pass
> &nbsp;
>
>
> org 
> .springframework 
> .test.annotation.AbstractAnnotationAwareTransactionalTests
> Pass
> &nbsp;
>
>
> org.springframework.test.jpa.AbstractJpaTests
> Fail
> ClassNotFoundException - Apparently a problem with the class loader
> OrmXmlOverridingShadowingClassLoader
>
>
>
>
> Here's my sample test case:
>
>
>
> public class UserEaoTest extends  
> AbstractTransactionalSpringContextTests {
>
> 	private GenericEao userEao;
>
> 	protected String[] getConfigLocations() {
>        setAutowireMode(AUTOWIRE_BY_NAME);
>
>        return new String[] {
>                "classpath*:/applicationContext-eao.xml"
>            };
>    }
>
> 	public void testCRUD() throws Exception{
> 		User user = new User();
> 		user.setName("John");
> 		user.setLastName("Doe");
> 		user.setStatus(new Short("1"));
>
> 		//Test create
> 		user = userEao.save(user);
> 		assertNotNull("Create failed...", user.getUserId());
>
> 		Long userId = user.getUserId();
> 		user = null;
>
> 		//Test read
> 		try {
> 			user = userEao.get(userId);
> 		} catch (RuntimeException e) {
> 			fail("Read failed...");
> 		}
> 		assertNotNull(user);
>
> 		//Test update
> 		user.setStatus(new Short("2"));
> 		userEao.save(user);
> 		assertEquals("Update failed...", userEao.get(userId).getStatus(),new
> Short("2"));
>
> 		//Test delete
> 		user = null;
> 		userEao.remove(userId);
> 		try {
> 			user = userEao.get(userId);
> 		} catch (RuntimeException e) {
> 			assertNull(user);
> 		}
> 	}
>
> 	//Injected by Spring
> 	public void setUserEao(GenericEao userEao) {
> 		this.userEao = userEao;
> 	}
> }
>
>
>
> The test case unit-tests a simple EAO that is managed by spring.  
> Notice that
> depending on the spring abstract superclass, the test case may require
> subtle changes.
>
>
>
> The spring application context file has the following definitions:
>
>
>
> 	&lt;!-- Initializes openEjb context--&gt;
> 	&lt;bean id="openEjbContext"
> 		class="net.quarksoft.arquetipo.eao.support.OpenEjbFactoryBean"&gt;
> 		&lt;property name="jndiEnvironment"&gt;
> 			&lt;props&gt;
> 				&lt;prop key="myDs"&gt;new://Resource?type=DataSource&lt;/prop&gt;
> 				&lt;prop key="myDs.JdbcDriver"&gt;com.mysql.jdbc.Driver&lt;/ 
> prop&gt;
> 				&lt;prop key="myDs.JdbcUrl"&gt;
> 				
> jdbc:mysql://localhost/midastest? 
> createDatabaseIfNotExist 
> =true&amp;useUnicode=true&amp;characterEncoding=utf-8
> 				&lt;/prop&gt;
> 				&lt;prop key="myDs.UserName"&gt;root&lt;/prop&gt;
> 				&lt;prop key="myDs.Password"&gt;&lt;/prop&gt;
> 			&lt;/props&gt;
> 		&lt;/property&gt;
> 	&lt;/bean&gt;
>
> 	&lt;!-- Obtains EntityManagerFactory from OpenEjb context via a  
> custom bean
> factory --&gt;
> 	&lt;bean id="entityManagerFactory"
> 			 
> class 
> ="net.quarksoft.arquetipo.eao.support.EntityManagerFactoryBean"&gt;
> 			&lt;property name="context" ref="openEjbContext" /&gt;
> 	&lt;/bean&gt;
>
> 	&lt;!-- Obtains TransactionManager from OpenEjb context via a  
> custom bean
> factory--&gt;
> 	&lt;bean id="transactionManagerFactory"
> class 
> = 
> "net 
> .quarksoft.arquetipo.eao.support.TransactionManagerFactory"&gt;&lt;/ 
> bean&gt;
>
> 	&lt;!-- Wraps OpenEjb's TransactionManager with spring's
> JtaTransactionManager so that it can be injected to spring's abstract
> transactional tests --&gt;
> 	&lt;bean id="transactionManager"
> class="org.springframework.transaction.jta.JtaTransactionManager"&gt;
> 		 	&lt;property name="transactionManager"
> ref="transactionManagerFactory"&gt;&lt;/property&gt;
> 	&lt;/bean&gt;
>
> 	&lt;!-- bean post-processor for JPA annotations --&gt;
> 	&lt;bean
> class 
> = 
> "org 
> .springframework 
> .orm.jpa.support.PersistenceAnnotationBeanPostProcessor"
> /&gt;
>
> 	&lt;!-- My persistent bean definition --&gt;
> 	&lt;bean id="userEao"
> 			class="net.quarksoft.arquetipo.eao.jpa.GenericEaoJpa"&gt;
> 			&lt;constructor-arg value="net.quarksoft.arquetipo.model.User" / 
> &gt;
> 	&lt;/bean&gt;
>
>
>
> These are the custom bean factories used to obtain the required  
> resources
> from OpenEjb context:
>
>
>
> /**
> * Custom spring factory to initialize OpenEjb context
> *
> */
> public class OpenEjbFactoryBean implements FactoryBean {
>
>         private Properties properties = new Properties();
>
>         public OpenEjbFactoryBean() {
>             properties.put(Context.INITIAL_CONTEXT_FACTORY,
> "org.apache.openejb.client.LocalInitialContextFactory");
>         }
>
>         public Properties getJndiEnvironment() {
>             return properties;
>         }
>
>         public void setJndiEnvironment(Properties properties) {
>             this.properties.putAll(properties);
>         }
>
>         public Object getObject() {
>             try {
>                 return new InitialContext(properties);
>             } catch (NamingException e) {
>                 throw new RuntimeException(e);
>             }
>         }
>
>         public Class getObjectType(){
>             return Context.class;
>         }
>
>         public boolean isSingleton() {
>             return true;
>         }
>     }
>
>
>
> /**
> * Obtains an instance of EntityManagerFactory from the openEjb context
> */
> public class EntityManagerFactoryBean implements FactoryBean {
> 	private Context context;
>
> 	public Object getObject() {
> 		try {
> 			ResourceLocal bean = (ResourceLocal) context
> 					.lookup("ResourceBeanLocal");
> 			return bean.getEntityManagerFactory();
> 		} catch (NamingException e) {
> 			throw new RuntimeException(e);
> 		}
> 	}
>
> 	public Class getObjectType() {
> 		return EntityManagerFactory.class;
> 	}
>
> 	public boolean isSingleton() {
> 		return true;
> 	}
>
> 	public Context getContext() {
>        return context;
>    }
>
>    public void setContext(Context context) {
>        this.context = context;
>    }
>
> }
>
>
>
> /**
> * Obtains an instance of javax.transaction.TransactionManager from
> * the OpenEjb context
> */
> public class TransactionManagerFactory implements FactoryBean {
>
> 	public Object getObject() throws Exception {
> 		return org.apache.openejb.OpenEJB.getTransactionManager();
> 	}
>
> 	public Class getObjectType() {
> 		return TransactionManager.class;
> 	}
>
> 	public boolean isSingleton() {
> 		return true;
> 	}
>
> }
>
>
>
> The persistence.xml definition:
>
>
>
> 	&lt;persistence-unit name="ApplicationEntityManager"
> 		transaction-type="JTA"&gt;
> 		&lt;provider&gt;org.hibernate.ejb.HibernatePersistence&lt;/ 
> provider&gt;
> 		&lt;jta-data-source&gt;myDs&lt;/jta-data-source&gt;
> 		&lt;class&gt;myapp.model.User&lt;/class&gt;
> 		&lt;properties&gt;
> 			&lt;property name="hibernate.dialect"
> 				value="org.hibernate.dialect.HSQLDialect" /&gt;
> 			&lt;property name="hibernate.transaction.manager_lookup_class"
>
> value="org.apache.openejb.hibernate.TransactionManagerLookup"/&gt;
> 		&lt;/properties&gt;
> 	&lt;/persistence-unit&gt;
>
>
>
> Finally, the persistent Entity and the generic implementation of the  
> EAO:
>
>
>
> @Entity
> @Table(name = "user")
> public class User implements Serializable{
>
> 	private static final long serialVersionUID = -8787893234778745429L;
>
> 	private Long userId;
> 	private String name;
> 	private String lastName;
> 	private Short status;
>
> 	@Column(name = "lastName", length = 30)
> 	public String getLastName() {
> 		return lastName;
> 	}
> 	public void setLastName(String lastName) {
> 		this.lastName = lastName;
> 	}
>
> 	@Column(name = "name", length = 30)
> 	public String getName() {
> 		return name;
> 	}
> 	public void setName(String name) {
> 		this.name = name;
> 	}
>
> 	@Column(name = "status")
> 	public Short getStatus() {
> 		return status;
> 	}
> 	public void setStatus(Short status) {
> 		this.status = status;
> 	}
>
> 	@Id
> 	@GeneratedValue (strategy=GenerationType.AUTO)
> 	@Column(name = "userId")
> 	public Long getUserId() {
> 		return userId;
> 	}
> 	public void setUserId(Long userId) {
> 		this.userId = userId;
> 	}
> }
>
>
>
>
> public class GenericEaoJpa implements GenericEao {
> 	protected final Log log = LogFactory.getLog(getClass());
>    private Class persistentClass;
>
>  //Injected by spring postprocessor
>    @PersistenceContext
>    private EntityManager entityManager;
>
> 	public GenericEaoJpa(Class  persistentClass) {
> 		super();
> 		this.persistentClass = persistentClass;
> 	}
>
> 	public boolean exists(Serializable id) {
> 		E entity = entityManager.find(persistentClass, id);
> 		return entity == null? false:true;
> 	}
>
> 	public E get(PK id) {
> 		E entity = entityManager.find(persistentClass, id);
> 		if (entity == null) {
>            log.warn("Uh oh, '" + this.persistentClass + "' object  
> with id
> '" + id + "' not found...");
>            throw new  
> ObjectRetrievalFailureException(this.persistentClass,
> id);
>        }
>
>        return entity;
> 	}
>
> 	public List getAll() {
> 		return entityManager.createQuery("select " +
> persistentClass.getName()).getResultList();
> 	}
>
> 	public void remove(PK id) {
> 		E entity = get(id);
> 		entityManager.remove(entity);
>
> 	}
>
> 	public E save(E entity) {
> 		entityManager.persist(entity);
> 		return entity;
> 	}
> }
>
>
>
> Hope this helps.
>
>
>
> -Jon
>
> -- 
> View this message in context: http://www.nabble.com/Help-with-OpenEJB3-and-Spring-IoC-tp17674222p17875549.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.


Re: Help with OpenEJB3 and Spring IoC

Posted by Jon Carrera <jc...@quarksoft.net>.

Here are the results i got after trying out all spring abstract support
classes for JUnit :




Spring Test Superclass
Test result
Problem


org.springframework.test.AbstractDependencyInjectionSpringContextTests
Pass
&nbsp;


org.springframework.test.AbstractTransactionalSpringContextTests
Pass
&nbsp;


org.springframework.test.AbstractSingleSpringContextTests
Pass
&nbsp;


org.springframework.test.AbstractTransactionalDataSourceSpringContextTests
Pass
&nbsp;


org.springframework.test.annotation.AbstractAnnotationAwareTransactionalTests
Pass
&nbsp;


org.springframework.test.jpa.AbstractJpaTests
Fail
ClassNotFoundException - Apparently a problem with the class loader
OrmXmlOverridingShadowingClassLoader




Here's my sample test case:



public class UserEaoTest extends AbstractTransactionalSpringContextTests {

	private GenericEao userEao;

	protected String[] getConfigLocations() {
        setAutowireMode(AUTOWIRE_BY_NAME);

        return new String[] {
                "classpath*:/applicationContext-eao.xml"
            };
    }

	public void testCRUD() throws Exception{
		User user = new User();
		user.setName("John");
		user.setLastName("Doe");
		user.setStatus(new Short("1"));

		//Test create
		user = userEao.save(user);
		assertNotNull("Create failed...", user.getUserId());

		Long userId = user.getUserId();
		user = null;

		//Test read
		try {
			user = userEao.get(userId);
		} catch (RuntimeException e) {
			fail("Read failed...");
		}
		assertNotNull(user);

		//Test update
		user.setStatus(new Short("2"));
		userEao.save(user);
		assertEquals("Update failed...", userEao.get(userId).getStatus(),new
Short("2"));

		//Test delete
		user = null;
		userEao.remove(userId);
		try {
			user = userEao.get(userId);
		} catch (RuntimeException e) {
			assertNull(user);
		}
	}

	//Injected by Spring
	public void setUserEao(GenericEao userEao) {
		this.userEao = userEao;
	}
}



The test case unit-tests a simple EAO that is managed by spring. Notice that
depending on the spring abstract superclass, the test case may require
subtle changes.



The spring application context file has the following definitions:



	&lt;!-- Initializes openEjb context--&gt;
	&lt;bean id="openEjbContext"
		class="net.quarksoft.arquetipo.eao.support.OpenEjbFactoryBean"&gt;
		&lt;property name="jndiEnvironment"&gt;
			&lt;props&gt;
				&lt;prop key="myDs"&gt;new://Resource?type=DataSource&lt;/prop&gt;
				&lt;prop key="myDs.JdbcDriver"&gt;com.mysql.jdbc.Driver&lt;/prop&gt;
				&lt;prop key="myDs.JdbcUrl"&gt;
				
jdbc:mysql://localhost/midastest?createDatabaseIfNotExist=true&amp;useUnicode=true&amp;characterEncoding=utf-8
				&lt;/prop&gt;
				&lt;prop key="myDs.UserName"&gt;root&lt;/prop&gt;
				&lt;prop key="myDs.Password"&gt;&lt;/prop&gt;
			&lt;/props&gt;
		&lt;/property&gt;
	&lt;/bean&gt;

	&lt;!-- Obtains EntityManagerFactory from OpenEjb context via a custom bean
factory --&gt;
	&lt;bean id="entityManagerFactory"
			class="net.quarksoft.arquetipo.eao.support.EntityManagerFactoryBean"&gt;
			&lt;property name="context" ref="openEjbContext" /&gt;
	&lt;/bean&gt;

	&lt;!-- Obtains TransactionManager from OpenEjb context via a custom bean
factory--&gt;
	&lt;bean id="transactionManagerFactory"
class="net.quarksoft.arquetipo.eao.support.TransactionManagerFactory"&gt;&lt;/bean&gt;

	&lt;!-- Wraps OpenEjb's TransactionManager with spring's
JtaTransactionManager so that it can be injected to spring's abstract
transactional tests --&gt;
	&lt;bean id="transactionManager"
class="org.springframework.transaction.jta.JtaTransactionManager"&gt;
		 	&lt;property name="transactionManager"
ref="transactionManagerFactory"&gt;&lt;/property&gt;
	&lt;/bean&gt;

	&lt;!-- bean post-processor for JPA annotations --&gt;
	&lt;bean
class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"
/&gt;

	&lt;!-- My persistent bean definition --&gt;
	&lt;bean id="userEao"
			class="net.quarksoft.arquetipo.eao.jpa.GenericEaoJpa"&gt;
			&lt;constructor-arg value="net.quarksoft.arquetipo.model.User" /&gt;
	&lt;/bean&gt;



These are the custom bean factories used to obtain the required resources
from OpenEjb context:



/**
 * Custom spring factory to initialize OpenEjb context
 *
 */
public class OpenEjbFactoryBean implements FactoryBean {

         private Properties properties = new Properties();

         public OpenEjbFactoryBean() {
             properties.put(Context.INITIAL_CONTEXT_FACTORY,
"org.apache.openejb.client.LocalInitialContextFactory");
         }

         public Properties getJndiEnvironment() {
             return properties;
         }

         public void setJndiEnvironment(Properties properties) {
             this.properties.putAll(properties);
         }

         public Object getObject() {
             try {
                 return new InitialContext(properties);
             } catch (NamingException e) {
                 throw new RuntimeException(e);
             }
         }

         public Class getObjectType(){
             return Context.class;
         }

         public boolean isSingleton() {
             return true;
         }
     }



/**
 * Obtains an instance of EntityManagerFactory from the openEjb context
 */
public class EntityManagerFactoryBean implements FactoryBean {
	private Context context;

	public Object getObject() {
		try {
			ResourceLocal bean = (ResourceLocal) context
					.lookup("ResourceBeanLocal");
			return bean.getEntityManagerFactory();
		} catch (NamingException e) {
			throw new RuntimeException(e);
		}
	}

	public Class getObjectType() {
		return EntityManagerFactory.class;
	}

	public boolean isSingleton() {
		return true;
	}

	public Context getContext() {
        return context;
    }

    public void setContext(Context context) {
        this.context = context;
    }

}



/**
 * Obtains an instance of javax.transaction.TransactionManager from
 * the OpenEjb context
 */
public class TransactionManagerFactory implements FactoryBean {

	public Object getObject() throws Exception {
		return org.apache.openejb.OpenEJB.getTransactionManager();
	}

	public Class getObjectType() {
		return TransactionManager.class;
	}

	public boolean isSingleton() {
		return true;
	}

}



The persistence.xml definition:



	&lt;persistence-unit name="ApplicationEntityManager"
		transaction-type="JTA"&gt;
		&lt;provider&gt;org.hibernate.ejb.HibernatePersistence&lt;/provider&gt;
		&lt;jta-data-source&gt;myDs&lt;/jta-data-source&gt;
		&lt;class&gt;myapp.model.User&lt;/class&gt;
		&lt;properties&gt;
			&lt;property name="hibernate.dialect"
				value="org.hibernate.dialect.HSQLDialect" /&gt;
			&lt;property name="hibernate.transaction.manager_lookup_class"
               
value="org.apache.openejb.hibernate.TransactionManagerLookup"/&gt;
		&lt;/properties&gt;
	&lt;/persistence-unit&gt;



Finally, the persistent Entity and the generic implementation of the EAO:



@Entity
@Table(name = "user")
public class User implements Serializable{

	private static final long serialVersionUID = -8787893234778745429L;

	private Long userId;
	private String name;
	private String lastName;
	private Short status;

	@Column(name = "lastName", length = 30)
	public String getLastName() {
		return lastName;
	}
	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	@Column(name = "name", length = 30)
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}

	@Column(name = "status")
	public Short getStatus() {
		return status;
	}
	public void setStatus(Short status) {
		this.status = status;
	}

	@Id
	@GeneratedValue (strategy=GenerationType.AUTO)
	@Column(name = "userId")
	public Long getUserId() {
		return userId;
	}
	public void setUserId(Long userId) {
		this.userId = userId;
	}
}




public class GenericEaoJpa implements GenericEao {
	protected final Log log = LogFactory.getLog(getClass());
    private Class persistentClass;

  //Injected by spring postprocessor
    @PersistenceContext
    private EntityManager entityManager;

	public GenericEaoJpa(Class  persistentClass) {
		super();
		this.persistentClass = persistentClass;
	}

	public boolean exists(Serializable id) {
		E entity = entityManager.find(persistentClass, id);
		return entity == null? false:true;
	}

	public E get(PK id) {
		E entity = entityManager.find(persistentClass, id);
		if (entity == null) {
            log.warn("Uh oh, '" + this.persistentClass + "' object with id
'" + id + "' not found...");
            throw new ObjectRetrievalFailureException(this.persistentClass,
id);
        }

        return entity;
	}

	public List getAll() {
		return entityManager.createQuery("select " +
persistentClass.getName()).getResultList();
	}

	public void remove(PK id) {
		E entity = get(id);
		entityManager.remove(entity);

	}

	public E save(E entity) {
		entityManager.persist(entity);
		return entity;
	}
}



Hope this helps.



-Jon

-- 
View this message in context: http://www.nabble.com/Help-with-OpenEJB3-and-Spring-IoC-tp17674222p17875549.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: Help with OpenEJB3 and Spring IoC

Posted by Jon Carrera <jc...@quarksoft.net>.

"Are you game for trying out the parent of  
AbstractTransactionalSpringContextTests and so on till it breaks so we  
can get that data for the doc as well?  Also, do you have any small  
sample test case code we could possibly show?"

Sure, count me in :-). I'll post the results as soon as I get them done.

"On a side note, we actually do have a much tighter integration  
planned.  Nothing concrete, but we'd like to find a way so that spring  
and ejb (openejb) can be mixed more easily with things like  
EntityManagers declarable and referencable right there in the spring  
xml obviating the need for your own custom factories, etc.  You  
interested in trying something like that out and giving feedback when  
we get a prototype going?"  

Definitely yes. I would be happy to collaborate. 

"We're also interested in what people think  
would be their dream syntax for mixing spring and ejb and other things  
like entitymanagers, topics, queues, etc.  Definitely feel free to  
post mock bean definition examples -- don't worry about reality, feel  
free to dream, there's usually a way to do anything with enough effort. "

I'll work on my wish list too.

Jon
-- 
View this message in context: http://www.nabble.com/Help-with-OpenEJB3-and-Spring-IoC-tp17674222p17804653.html
Sent from the OpenEJB User mailing list archive at Nabble.com.


Re: Help with OpenEJB3 and Spring IoC

Posted by David Blevins <da...@visi.com>.
On Jun 9, 2008, at 3:53 PM, Jon Carrera wrote:

>
> I went for the naughty option for printing out the classpath and it  
> worked
> from within the test case, but didn't work with the bean factory.  
> Apparently
> the problem is in org.springframework.test.jpa.AbstractJpaTests which
> internally uses
> org.springframework.test.jpa.OrmXmlOverridingShadowingClassLoader  
> (which by
> the way isn't a subclass of URLClassLoader, so the PrintClasspath  
> class
> didn't work here) and for some reason is not able to find the required
> classes. I solved the problem by replacing AbstractJpaTests with
> org.springframework.test.AbstractTransactionalSpringContextTests.  
> Now my
> tests run just fine.
>
> I also changed the factories as you suggested so that OpenEjb was
> initialized by spring.
>
> Hope this can be of use for others.
>
> Thanks David and keep up the great job.

Many thanks to you, Jon!  We definitely appreciate your time as well.   
I've crafted up a doc that attempts to summarize the information in  
this thread:

http://cwiki.apache.org/OPENEJBx30/spring.html

(should sync to http://openejb.apache.org/3.0/spring.html in an hour  
or so)

I'd like to put a section in there about testing and some details  
about which Abstract*Tests superclasses work and which do not.  We  
definitely know that AbstractTransactionalSpringContextTests works and  
AbstractJpaTests does not.  Are you game for trying out the parent of  
AbstractTransactionalSpringContextTests and so on till it breaks so we  
can get that data for the doc as well?  Also, do you have any small  
sample test case code we could possibly show?

On a side note, we actually do have a much tighter integration  
planned.  Nothing concrete, but we'd like to find a way so that spring  
and ejb (openejb) can be mixed more easily with things like  
EntityManagers declarable and referencable right there in the spring  
xml obviating the need for your own custom factories, etc.  You  
interested in trying something like that out and giving feedback when  
we get a prototype going?  We're also interested in what people think  
would be their dream syntax for mixing spring and ejb and other things  
like entitymanagers, topics, queues, etc.  Definitely feel free to  
post mock bean definition examples -- don't worry about reality, feel  
free to dream, there's usually a way to do anything with enough effort.


-David


Re: Help with OpenEJB3 and Spring IoC

Posted by Jon Carrera <jc...@quarksoft.net>.
I went for the naughty option for printing out the classpath and it worked
from within the test case, but didn't work with the bean factory. Apparently
the problem is in org.springframework.test.jpa.AbstractJpaTests which
internally uses
org.springframework.test.jpa.OrmXmlOverridingShadowingClassLoader (which by
the way isn't a subclass of URLClassLoader, so the PrintClasspath class
didn't work here) and for some reason is not able to find the required
classes. I solved the problem by replacing AbstractJpaTests with
org.springframework.test.AbstractTransactionalSpringContextTests. Now my
tests run just fine.

I also changed the factories as you suggested so that OpenEjb was
initialized by spring.

Hope this can be of use for others.

Thanks David and keep up the great job.



-- 
View this message in context: http://www.nabble.com/Help-with-OpenEJB3-and-Spring-IoC-tp17674222p17744010.html
Sent from the OpenEJB User mailing list archive at Nabble.com.


Re: Help with OpenEJB3 and Spring IoC

Posted by David Blevins <da...@visi.com>.
Hmm.  This one is a bit tricky...  The big question on both our minds  
is likely, what *is* in the classpath?

With maven it's easy to see via adding "-X" as an argument, which will  
set the log level to debug and cause all sorts of information to be  
printed, including the test classpath.  It's a lot of output, so  
you'll have to scan for a while to find it.

Alternatively... we can be a little naughty :)  Here's a chunk of code  
which will pull the classpath out of the classloader and print it.  It  
works on a URLClassLoader which is a superclass of nearly every  
classloader out there.

import java.net.URLClassLoader;
import java.net.URL;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.lang.reflect.Field;

public class PrintClasspath {

     public static void printClasspath(URLClassLoader loader) throws  
Exception {
         String name = loader.getClass().getSimpleName() + "@" +  
loader.hashCode();

         for (URL url : getURLs(loader)) {
             System.out.println(name + " = " + url.toExternalForm());
         }
     }

     private static URL[] getURLs(URLClassLoader loader) throws  
Exception {
         return ((sun.misc.URLClassPath)  
getUcpField().get(loader)).getURLs();
     }

     private static Field getUcpField() throws Exception {
         return (Field) AccessController.doPrivileged(new  
PrivilegedAction() {
             public Object run() {
                 try {
                     Field ucp =  
URLClassLoader.class.getDeclaredField("ucp");
                     ucp.setAccessible(true);
                     return ucp;
                 } catch (Exception e) {
                     throw new RuntimeException(e);
                 }
             }
         });
     }
}

Use this in your TestCase to get a clean and short printout of the  
test classpath and again inside the bean factory.

The second thing I notice is that your TestCase is inheriting from  
org.springframework.test.jpa.AbstractJpaTests, which makes me realize  
your spring factory bean is likely to get executed before your test's  
setUp() method.  We should probably revise things so OpenEJB  
initializes via your spring xml file as well.

The revised factories might look like this:

     public class OpenEjbFactoryBean implements  
org.springframework.beans.factory.FactoryBean {

         private Properties properties = new Properties();

         public OpenEjbFactoryBean() {
             properties.put(Context.INITIAL_CONTEXT_FACTORY,  
"org.apache.openejb.client.LocalInitialContextFactory");
         }

         public Properties getJndiEnvironment() {
             return properties;
         }

         public void setJndiEnvironment(Properties properties) {
             this.properties.putAll(properties);
         }

         public Object getObject() {
             try {
                 return new InitialContext(properties);
             } catch (NamingException e) {
                 throw new RuntimeException(e);
             }
         }

         public Class getObjectType(){
             return Context.class;
         }

         boolean isSingleton() {
             return true;
         }
     }


     public class EntityManagerFactoryBean implements  
org.springframework.beans.factory.FactoryBean {
         private Context context;

         public Context getContext() {
             return context;
         }

         public void setContext(Context context) {
             this.context = context;
         }

         public Object getObject() {
             try {
                 ResourceLocal bean = (ResourceLocal)  
context.lookup("ResourceBeanLocal");
                 return bean.getEntityManager();
             } catch (NamingException e) {
                 throw new RuntimeException(e);
             }
         }

         public Class getObjectType(){
             return EntityManager.class;
         }

         boolean isSingleton() {
             return true;
         }
     }

   <bean id="OpenEjbContext" class="org.acme.OpenEjbFactoryBean">
     <property name="jndiEnvironment">
       <props>
         <prop key="myDs">new://Resource?type=DataSource</prop>
         <prop key="myDs.JdbcDriver">com.mysql.jdbc.Driver</prop>
         <prop key="myDs.JdbcUrl">jdbc:mysql://localhost/midastest? 
createDatabaseIfNotExist 
=true&amp;useUnicode=true&amp;characterEncoding=utf-8</prop>
         <prop key="myDs.UserName">root</prop>
         <prop key="myDs.Password"></prop>
       </props>
     </property>
   </bean>

   <bean id="ApplicationEntityManager"  
class="org.acme.EntityManagerFactoryBean">
     <property name="context" ref="OpenEjbContext">
   </bean>


Hope this helps, and thanks for posting.  This will make a great doc  
when we are done!

-David




Re: Help with OpenEJB3 and Spring IoC

Posted by Jon Carrera <jc...@quarksoft.net>.
Thanks for your help David. Nice workaround btw :clap:. I did as you
suggested and now I'm having a strange problem when running my test. I'm
using Maven 2.0.7 to build and test my application and now I'm getting a
ClassNotFoundException for  org.hibernate.ejb.HibernatePersistence when
initializing the openejb context from the custom EntityManager factory bean.
I'm pretty sure it is in the classpath as it is declared as a dependency in
the pom. 

The strange thing is that if i initialize the openejb context using the same
code inside the JUnit test class it  starts the openejb container with no
problem at all, but when the spring context is created and the custom
factory is accessed, openejb is unable to find the HibernatePersistence
class. It appears that for some reason the test and the custom factory bean
don't share the same classpath.

My test case is something like this:

public class PartidaEaoTest extends AbstractJpaTests {
	protected final Log log = LogFactory.getLog(PartidaEaoTest.class);
	
	protected InitialContext context;

        //This starts the spring context
	protected String[] getConfigLocations() {

	        setAutowireMode(AUTOWIRE_BY_NAME);
	        return new String[] {
	                "classpath*:/applicationContext-resources.xml",
	                "classpath*:/applicationContext-eao.xml"
	            };
	    }


             public void testSomething() throws Exception{
		...
	    }
       }


Here's the stacktrace:

ERROR - Application could not be deployed: 
C:\workspace\MidasTestEJB\data-acce
\target\classes
org.apache.openejb.OpenEJBException: createApplication.failed
[C:\workspace\Mid
sTestEJB\data-acces\target\classes]: java.lang.ClassNotFoundException:
org.hibe
nate.ejb.HibernatePersistence: org.hibernate.ejb.HibernatePersistence
        at
org.apache.openejb.assembler.classic.Assembler.createApplication(Ass
mbler.java:592)
        at
org.apache.openejb.assembler.classic.Assembler.buildContainerSystem(
ssembler.java:338)
        at
org.apache.openejb.assembler.classic.Assembler.build(Assembler.java:
50)
        at org.apache.openejb.OpenEJB$Instance.<init>(OpenEJB.java:149)
        at org.apache.openejb.OpenEJB.init(OpenEJB.java:288)
        at org.apache.openejb.OpenEJB.init(OpenEJB.java:267)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl
java:39)
        at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcce
sorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at
org.apache.openejb.loader.OpenEJBInstance.init(OpenEJBInstance.java:
6)
        at
org.apache.openejb.client.LocalInitialContextFactory.init(LocalIniti
lContextFactory.java:62)
        at
org.apache.openejb.client.LocalInitialContextFactory.init(LocalIniti
lContextFactory.java:51)
        at
org.apache.openejb.client.LocalInitialContextFactory.getInitialConte
t(LocalInitialContextFactory.java:40)
        at
javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:
67)
        at
javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:24
)
        at javax.naming.InitialContext.init(InitialContext.java:223)
        at javax.naming.InitialContext.<init>(InitialContext.java:197)
        at
net.quarksoft.arquetipo.eao.support.EntityManagerFactoryBean.getObje
t(EntityManagerFactoryBean.java:26)
        at
org.springframework.beans.factory.support.AbstractBeanFactory.getObj
ctFromFactoryBean(AbstractBeanFactory.java:1227)
        at
org.springframework.beans.factory.support.AbstractBeanFactory.getObj
ctForBeanInstance(AbstractBeanFactory.java:1198)
        at
org.springframework.beans.factory.support.AbstractBeanFactory.getBea
(AbstractBeanFactory.java:262)
        at
org.springframework.beans.factory.support.AbstractBeanFactory.getBea
(AbstractBeanFactory.java:160)
        at
org.springframework.beans.factory.support.BeanDefinitionValueResolve
.resolveReference(BeanDefinitionValueResolver.java:261)
        at
org.springframework.beans.factory.support.BeanDefinitionValueResolve
.resolveValueIfNecessary(BeanDefinitionValueResolver.java:109)
        at
org.springframework.beans.factory.support.AbstractAutowireCapableBea
Factory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1100)
        at
org.springframework.beans.factory.support.AbstractAutowireCapableBea
Factory.populateBean(AbstractAutowireCapableBeanFactory.java:862)
        at
org.springframework.beans.factory.support.AbstractAutowireCapableBea
Factory.createBean(AbstractAutowireCapableBeanFactory.java:424)
        at
org.springframework.beans.factory.support.AbstractBeanFactory$1.getO
ject(AbstractBeanFactory.java:251)
        at
org.springframework.beans.factory.support.DefaultSingletonBeanRegist
y.getSingleton(DefaultSingletonBeanRegistry.java:156)
        at
org.springframework.beans.factory.support.AbstractBeanFactory.getBea
(AbstractBeanFactory.java:248)
        at
org.springframework.beans.factory.support.AbstractBeanFactory.getBea
(AbstractBeanFactory.java:160)
        at
org.springframework.beans.factory.support.BeanDefinitionValueResolve
.resolveReference(BeanDefinitionValueResolver.java:261)
        at
org.springframework.beans.factory.support.BeanDefinitionValueResolve
.resolveValueIfNecessary(BeanDefinitionValueResolver.java:109)
        at
org.springframework.beans.factory.support.AbstractAutowireCapableBea
Factory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1100)
        at
org.springframework.beans.factory.support.AbstractAutowireCapableBea
Factory.populateBean(AbstractAutowireCapableBeanFactory.java:862)
        at
org.springframework.beans.factory.support.AbstractAutowireCapableBea
Factory.createBean(AbstractAutowireCapableBeanFactory.java:424)
        at
org.springframework.beans.factory.support.BeanDefinitionValueResolve
.resolveInnerBean(BeanDefinitionValueResolver.java:215)
        at
org.springframework.beans.factory.support.BeanDefinitionValueResolve
.resolveValueIfNecessary(BeanDefinitionValueResolver.java:127)
        at
org.springframework.beans.factory.support.AbstractAutowireCapableBea
Factory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1100)
        at
org.springframework.beans.factory.support.AbstractAutowireCapableBea
Factory.populateBean(AbstractAutowireCapableBeanFactory.java:862)
        at
org.springframework.beans.factory.support.AbstractAutowireCapableBea
Factory.createBean(AbstractAutowireCapableBeanFactory.java:424)
        at
org.springframework.beans.factory.support.AbstractBeanFactory$1.getO
ject(AbstractBeanFactory.java:251)
        at
org.springframework.beans.factory.support.DefaultSingletonBeanRegist
y.getSingleton(DefaultSingletonBeanRegistry.java:156)
        at
org.springframework.beans.factory.support.AbstractBeanFactory.getBea
(AbstractBeanFactory.java:248)
        at
org.springframework.beans.factory.support.AbstractBeanFactory.getBea
(AbstractBeanFactory.java:160)
        at
org.springframework.aop.framework.autoproxy.BeanFactoryAdvisorRetrie
alHelper.findAdvisorBeans(BeanFactoryAdvisorRetrievalHelper.java:87)
        at
org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxy
reator.findCandidateAdvisors(AbstractAdvisorAutoProxyCreator.java:96)
        at
org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxy
reator.findEligibleAdvisors(AbstractAdvisorAutoProxyCreator.java:83)
        at
org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxy
reator.getAdvicesAndAdvisorsForBean(AbstractAdvisorAutoProxyCreator.java:66)
        at
org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator
postProcessAfterInitialization(AbstractAutoProxyCreator.java:296)
        at
org.springframework.beans.factory.support.AbstractAutowireCapableBea
Factory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanF
ctory.java:315)
        at
org.springframework.beans.factory.support.AbstractAutowireCapableBea
Factory.initializeBean(AbstractAutowireCapableBeanFactory.java:1181)
        at
org.springframework.beans.factory.support.AbstractAutowireCapableBea
Factory.createBean(AbstractAutowireCapableBeanFactory.java:428)
        at
org.springframework.beans.factory.support.AbstractBeanFactory$1.getO
ject(AbstractBeanFactory.java:251)
        at
org.springframework.beans.factory.support.DefaultSingletonBeanRegist
y.getSingleton(DefaultSingletonBeanRegistry.java:156)
        at
org.springframework.beans.factory.support.AbstractBeanFactory.getBea
(AbstractBeanFactory.java:248)
        at
org.springframework.beans.factory.support.AbstractBeanFactory.getBea
(AbstractBeanFactory.java:160)
        at
org.springframework.context.support.AbstractApplicationContext.getBe
n(AbstractApplicationContext.java:733)
        at
org.springframework.context.support.AbstractApplicationContext.regis
erBeanPostProcessors(AbstractApplicationContext.java:511)
        at
org.springframework.context.support.AbstractApplicationContext.refre
h(AbstractApplicationContext.java:337)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl
java:39)
        at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcce
sorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at
org.springframework.test.jpa.AbstractJpaTests.runBare(AbstractJpaTes
s.java:229)
        at junit.framework.TestResult$1.protect(TestResult.java:106)
        at junit.framework.TestResult.runProtected(TestResult.java:124)
        at junit.framework.TestResult.run(TestResult.java:109)
        at junit.framework.TestCase.run(TestCase.java:120)
        at junit.framework.TestSuite.runTest(TestSuite.java:230)
        at junit.framework.TestSuite.run(TestSuite.java:225)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl
java:39)
        at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcce
sorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at
org.apache.maven.surefire.junit.JUnitTestSet.execute(JUnitTestSet.ja
a:213)
        at
org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTe
tSet(AbstractDirectoryTestSuite.java:138)
        at
org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(A
stractDirectoryTestSuite.java:125)
        at org.apache.maven.surefire.Surefire.run(Surefire.java:132)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl
java:39)
        at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcce
sorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at
org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(S
refireBooter.java:290)
        at
org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.
ava:818)
Caused by: org.apache.openejb.OpenEJBException:
java.lang.ClassNotFoundExceptio
: org.hibernate.ejb.HibernatePersistence:
org.hibernate.ejb.HibernatePersistenc

        at
org.apache.openejb.assembler.classic.Assembler.createApplication(Ass
mbler.java:459)
        ... 85 more
Caused by: java.lang.ClassNotFoundException:
org.hibernate.ejb.HibernatePersist
nce
        at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
        at
org.apache.openejb.assembler.classic.PersistenceBuilder.createEntity
anagerFactory(PersistenceBuilder.java:177)
        at
org.apache.openejb.assembler.classic.Assembler.createApplication(Ass
mbler.java:454)
        ... 85 more


I think it maybe a maven thing but i'm not really sure. Any help will be
very appreciated.

Thanks.


David Blevins wrote:
> 
> Hi Jon,
> 
> I wonder if it might be possible to pass the EntityManager through via  
> a custom Spring factory bean.  Thinking you could create a stateless  
> bean with an @PersistenceContext ref in it, then use a factory bean to  
> look it up, pull the EntityManager out and return it.
> 
> Something like:
> 
>      @Stateless
>      public class ResourceBean implements ResourceLocal {
>          @PersistenceContext(unitName="ApplicationEntityManager")
>          private EntityManager entityManager;
> 
>          public EntityManager getEntityManager() {
>              return entityManager;
>          }
>      }
> 
>      public interface ResourceLocal {
>          public EntityManager getEntityManager();
>      }
> 
>      public class EntityManagerFactoryBean implements  
> org.springframework.beans.factory.FactoryBean {
>          public Object getObject() {
>              try {
>                  Properties p = new Properties();
>                  p.put(Context.INITIAL_CONTEXT_FACTORY,  
> "org.apache.openejb.client.LocalInitialContextFactory");
>                  InitialContext context = new InitialContext(p);
>                  ResourceLocal bean = (ResourceLocal)  
> context.lookup("ResourceBeanLocal");
>                  return bean.getEntityManager();
>              } catch (NamingException e) {
>                  throw new RuntimeException(e);
>              }
>          }
> 
>          public Class getObjectType(){
>              return EntityManager.class;
>          }
> 
>          boolean isSingleton() {
>              return true;
>          }
>      }
> 
> You could likely expand the same bean and factory to handle anything  
> you wanted to pull from the environment, such as the DataSource,  
> though it sounds like you're really just after the EntityManager.
> 
> -David
> 
> On Jun 5, 2008, at 9:30 AM, Jon Carrera wrote:
> 
>>
>> I've been playing with OpenEJB for a few days now trying to make it  
>> work with
>> an application that uses an EJB facade that delegates to a spring- 
>> managed
>> service pojo that relies on an EAO to retrieve and persist data. So  
>> far
>> OpenEJB works fine as a container for the ejb, but i can't still  
>> figure out
>> how can I inject the PersistenceContext created by OpenEJB to the  
>> EAO via
>> Spring IoC.
>>
>> The EAO is a simple class that relies on the EntityManager to perform
>> persistence operations:
>>
>>
>> public class GenericEaoJpa<E, PK extends Serializable> implements
>> GenericEao<E, PK> {
>> 	protected final Log log = LogFactory.getLog(getClass());
>>    private Class<E> persistentClass;
>>
>>    @PersistenceContext(unitName="ApplicationEntityManager")
>>    private EntityManager em;
>>
>> 	public GenericEaoJpa(Class <E> persistentClass) {
>> 		super();
>> 		this.persistentClass = persistentClass;
>> 	}
>>
>> 	public boolean exists(Serializable id) {
>> 		E entity = em.find(persistentClass, id);
>> 		return entity == null? false:true;
>> 	}
>>
>> 	public E get(PK id) {
>> 		E entity = em.find(persistentClass, id);
>> 		if (entity == null) {
>>            log.warn("Uh oh, '" + this.persistentClass + "' object  
>> with id
>> '" + id + "' not found...");
>>            throw new  
>> ObjectRetrievalFailureException(this.persistentClass,
>> id);
>>        }
>>
>>        return entity;
>> 	}
>>
>> 	public List<E> getAll() {
>> 		// TODO Auto-generated method stub
>> 		return em.createQuery("select " +
>> persistentClass.getName()).getResultList();
>> 	}
>>
>> 	public void remove(PK id) {
>> 		E entity = get(id);
>> 		em.remove(entity);
>>
>> 	}
>> 	
>> 	public E save(E entity) {
>> 		em.persist(entity);
>> 		return entity;
>> 	}
>>
>> }
>>
>>
>> I use the following code to initialize the openejb context in my  
>> test case:
>>
>>
>> Properties p = new Properties();
>>        p.put(Context.INITIAL_CONTEXT_FACTORY,
>> "org.apache.openejb.client.LocalInitialContextFactory");
>>        p.put("myDs", "new://Resource?type=DataSource");
>>        p.put("myDs.JdbcDriver", "com.mysql.jdbc.Driver");
>>        p.put("myDs.JdbcUrl",
>> "jdbc:mysql://localhost/midastest? 
>> createDatabaseIfNotExist 
>> =true&amp;useUnicode=true&amp;characterEncoding=utf-8");
>>        p.put("myDs.UserName", "root");
>>        p.put("myDs.Password", "");
>>
>>        this.context = new InitialContext(p);
>>
>>        ServiceFacadeBean service = (ServiceFacadeBean) context
>> 					.lookup("ServiceFacadeBeanLocal");
>>
>>
>>
>> persistence.xml is defined as follows:
>>
>>
>> 	<persistence-unit name="ApplicationEntityManager"
>> 		transaction-type="JTA">
>> 		<provider>org.hibernate.ejb.HibernatePersistence</provider>
>> 		<jta-data-source>myDs</jta-data-source>
>> 		<class>model.MyEntity</class>
>> 		<properties>
>>         <property name="hibernate.dialect"
>> value="org.hibernate.dialect.HSQLDialect"/>
>>         <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
>>         <property name="hibernate.transaction.manager_lookup_class"
>>
>> value="org.apache.openejb.hibernate.TransactionManagerLookup"/>
>>      </properties>
>> 	</persistence-unit>
>>
>>
>> Now, my problem is in the spring application context configuration  
>> file. I
>> don't know if it is possible to obtain the EntityManager from the  
>> openejb
>> jndi context or if there is an EntityManagerFactory in openejb that  
>> i can
>> use to inject it to my EAO Pojo. An idea that ocurred to me is to use
>> spring's LocalContainerEntityManagerFactoryBean and pass the  
>> dataSource from
>> the openejb jndi context
>>
>>
>>
>> <bean id="dataSource"
>> 	        class="org.springframework.jndi.JndiObjectFactoryBean">
>> 	        <property name="jndiName" value="java:openejb/Resource/ 
>> myDs"/>
>> 	        <property name="jndiEnvironment">
>> 	            <props>
>> 	                <prop key="java.naming.factory.initial">
>> 	                     
>> org.apache.openejb.client.LocalInitialContextFactory
>> 	                </prop>
>> 	            </props>
>> 	        </property>
>> 		</bean>
>>
>> <bean id="entityManagerFactory"
>> 	
>> class 
>> ="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
>>                <property name="dataSource" ref="dataSource">
>> 		<property name="jpaVendorAdapter">
>> 			<bean
>> 				 
>> class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
>> 				<property name="database" value="MYSQL" />
>> 				<property name="showSql" value="true" />
>> 			</bean>
>> 		</property>
>> 	</bean>
>>
>> <!-- bean post-processor for JPA annotations -->
>> 	<bean
>> 	
>> class 
>> = 
>> "org 
>> .springframework 
>> .orm.jpa.support.PersistenceAnnotationBeanPostProcessor"
>> />
>>
>>       <bean id="MyEntityEao"
>> 		class="eao.jpa.GenericEaoJpa">
>> 		<constructor-arg
>> 			value="model.MyEntity" />
>> 	</bean>
>>
>>
>> I get the following error when running the test
>>
>> Invocation of init method failed; nested exception is javax.naming.N
>> ameNotFoundException: Name "java:openejb/Resource/myDs" not found.
>> Caused by: javax.naming.NameNotFoundException: Name
>> "java:openejb/Resource/myDs"
>> not found.
>>        at
>> org.apache.openejb.core.ivm.naming.IvmContext.federate(IvmContext.jav
>> a:172)
>>        at
>> org.apache.openejb.core.ivm.naming.IvmContext.lookup(IvmContext.java:
>> 129)
>>        at javax.naming.InitialContext.lookup(InitialContext.java:351)
>>        at
>> org.springframework.jndi.JndiTemplate$1.doInContext(JndiTemplate.java
>> :123)
>>        at
>> org.springframework.jndi.JndiTemplate.execute(JndiTemplate.java:85)
>>        at
>> org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:121)
>>        at
>> org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:146)
>>        at
>> org.springframework.jndi.JndiLocatorSupport.lookup(JndiLocatorSupport
>> .java:93)
>>        at
>> org.springframework.jndi.JndiObjectLocator.lookup(JndiObjectLocator.j
>> ava:105)
>>        at
>> org.springframework.jndi.JndiObjectFactoryBean.lookupWithFallback(Jnd
>> iObjectFactoryBean.java:197)
>>        at
>> org.springframework.jndi.JndiObjectFactoryBean.afterPropertiesSet(Jnd
>> iObjectFactoryBean.java:184)
>>        at
>> org.springframework.beans.factory.support.AbstractAutowireCapableBean
>> Factory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java: 
>> 1202)
>>        at
>> org.springframework.beans.factory.support.AbstractAutowireCapableBean
>> Factory.initializeBean(AbstractAutowireCapableBeanFactory.java:1172)
>>        at
>> org.springframework.beans.factory.support.AbstractAutowireCapableBean
>> Factory.createBean(AbstractAutowireCapableBeanFactory.java:428)
>>        at
>> org.springframework.beans.factory.support.AbstractBeanFactory$1.getOb
>> ject(AbstractBeanFactory.java:251)
>>        at
>> org.springframework.beans.factory.support.DefaultSingletonBeanRegistr
>> y.getSingleton(DefaultSingletonBeanRegistry.java:156)
>>        at
>> org.springframework.beans.factory.support.AbstractBeanFactory.getBean
>> (AbstractBeanFactory.java:248)
>>        at
>> org.springframework.beans.factory.support.AbstractBeanFactory.getBean
>> (AbstractBeanFactory.java:160)
>>        at
>> org.springframework.beans.factory.support.BeanDefinitionValueResolver
>> .resolveReference(BeanDefinitionValueResolver.java:261)
>>        at
>> org.springframework.beans.factory.support.BeanDefinitionValueResolver
>> .resolveValueIfNecessary(BeanDefinitionValueResolver.java:109)
>>        at
>> org.springframework.beans.factory.support.AbstractAutowireCapableBean
>> Factory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java: 
>> 1100)
>>        at
>> org.springframework.beans.factory.support.AbstractAutowireCapableBean
>> Factory.populateBean(AbstractAutowireCapableBeanFactory.java:862)
>>        at
>> org.springframework.beans.factory.support.AbstractAutowireCapableBean
>> Factory.createBean(AbstractAutowireCapableBeanFactory.java:424)
>>        at
>> org.springframework.beans.factory.support.AbstractBeanFactory$1.getOb
>> ject(AbstractBeanFactory.java:251)
>>        at
>> org.springframework.beans.factory.support.DefaultSingletonBeanRegistr
>> y.getSingleton(DefaultSingletonBeanRegistry.java:156)
>>        at
>> org.springframework.beans.factory.support.AbstractBeanFactory.getBean
>> (AbstractBeanFactory.java:248)
>>        at
>> org.springframework.beans.factory.support.AbstractBeanFactory.getBean
>> (AbstractBeanFactory.java:160)
>>
>>
>> I've been trying to retrieve the datasource from the jndi context with
>> different naming conventions with no success.
>>
>> Maybe this is not the correct approach to solve the problem, so any  
>> advice
>> would be very appreciated.
>>
>> Thanks in advance.
>>
>> -- 
>> View this message in context:
>> http://www.nabble.com/Help-with-OpenEJB3-and-Spring-IoC-tp17674222p17674222.html
>> Sent from the OpenEJB User mailing list archive at Nabble.com.
>>
>>
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Help-with-OpenEJB3-and-Spring-IoC-tp17674222p17699352.html
Sent from the OpenEJB User mailing list archive at Nabble.com.


Re: Help with OpenEJB3 and Spring IoC

Posted by David Blevins <da...@visi.com>.
Hi Jon,

I wonder if it might be possible to pass the EntityManager through via  
a custom Spring factory bean.  Thinking you could create a stateless  
bean with an @PersistenceContext ref in it, then use a factory bean to  
look it up, pull the EntityManager out and return it.

Something like:

     @Stateless
     public class ResourceBean implements ResourceLocal {
         @PersistenceContext(unitName="ApplicationEntityManager")
         private EntityManager entityManager;

         public EntityManager getEntityManager() {
             return entityManager;
         }
     }

     public interface ResourceLocal {
         public EntityManager getEntityManager();
     }

     public class EntityManagerFactoryBean implements  
org.springframework.beans.factory.FactoryBean {
         public Object getObject() {
             try {
                 Properties p = new Properties();
                 p.put(Context.INITIAL_CONTEXT_FACTORY,  
"org.apache.openejb.client.LocalInitialContextFactory");
                 InitialContext context = new InitialContext(p);
                 ResourceLocal bean = (ResourceLocal)  
context.lookup("ResourceBeanLocal");
                 return bean.getEntityManager();
             } catch (NamingException e) {
                 throw new RuntimeException(e);
             }
         }

         public Class getObjectType(){
             return EntityManager.class;
         }

         boolean isSingleton() {
             return true;
         }
     }

You could likely expand the same bean and factory to handle anything  
you wanted to pull from the environment, such as the DataSource,  
though it sounds like you're really just after the EntityManager.

-David

On Jun 5, 2008, at 9:30 AM, Jon Carrera wrote:

>
> I've been playing with OpenEJB for a few days now trying to make it  
> work with
> an application that uses an EJB facade that delegates to a spring- 
> managed
> service pojo that relies on an EAO to retrieve and persist data. So  
> far
> OpenEJB works fine as a container for the ejb, but i can't still  
> figure out
> how can I inject the PersistenceContext created by OpenEJB to the  
> EAO via
> Spring IoC.
>
> The EAO is a simple class that relies on the EntityManager to perform
> persistence operations:
>
>
> public class GenericEaoJpa<E, PK extends Serializable> implements
> GenericEao<E, PK> {
> 	protected final Log log = LogFactory.getLog(getClass());
>    private Class<E> persistentClass;
>
>    @PersistenceContext(unitName="ApplicationEntityManager")
>    private EntityManager em;
>
> 	public GenericEaoJpa(Class <E> persistentClass) {
> 		super();
> 		this.persistentClass = persistentClass;
> 	}
>
> 	public boolean exists(Serializable id) {
> 		E entity = em.find(persistentClass, id);
> 		return entity == null? false:true;
> 	}
>
> 	public E get(PK id) {
> 		E entity = em.find(persistentClass, id);
> 		if (entity == null) {
>            log.warn("Uh oh, '" + this.persistentClass + "' object  
> with id
> '" + id + "' not found...");
>            throw new  
> ObjectRetrievalFailureException(this.persistentClass,
> id);
>        }
>
>        return entity;
> 	}
>
> 	public List<E> getAll() {
> 		// TODO Auto-generated method stub
> 		return em.createQuery("select " +
> persistentClass.getName()).getResultList();
> 	}
>
> 	public void remove(PK id) {
> 		E entity = get(id);
> 		em.remove(entity);
>
> 	}
> 	
> 	public E save(E entity) {
> 		em.persist(entity);
> 		return entity;
> 	}
>
> }
>
>
> I use the following code to initialize the openejb context in my  
> test case:
>
>
> Properties p = new Properties();
>        p.put(Context.INITIAL_CONTEXT_FACTORY,
> "org.apache.openejb.client.LocalInitialContextFactory");
>        p.put("myDs", "new://Resource?type=DataSource");
>        p.put("myDs.JdbcDriver", "com.mysql.jdbc.Driver");
>        p.put("myDs.JdbcUrl",
> "jdbc:mysql://localhost/midastest? 
> createDatabaseIfNotExist 
> =true&amp;useUnicode=true&amp;characterEncoding=utf-8");
>        p.put("myDs.UserName", "root");
>        p.put("myDs.Password", "");
>
>        this.context = new InitialContext(p);
>
>        ServiceFacadeBean service = (ServiceFacadeBean) context
> 					.lookup("ServiceFacadeBeanLocal");
>
>
>
> persistence.xml is defined as follows:
>
>
> 	<persistence-unit name="ApplicationEntityManager"
> 		transaction-type="JTA">
> 		<provider>org.hibernate.ejb.HibernatePersistence</provider>
> 		<jta-data-source>myDs</jta-data-source>
> 		<class>model.MyEntity</class>
> 		<properties>
>         <property name="hibernate.dialect"
> value="org.hibernate.dialect.HSQLDialect"/>
>         <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
>         <property name="hibernate.transaction.manager_lookup_class"
>
> value="org.apache.openejb.hibernate.TransactionManagerLookup"/>
>      </properties>
> 	</persistence-unit>
>
>
> Now, my problem is in the spring application context configuration  
> file. I
> don't know if it is possible to obtain the EntityManager from the  
> openejb
> jndi context or if there is an EntityManagerFactory in openejb that  
> i can
> use to inject it to my EAO Pojo. An idea that ocurred to me is to use
> spring's LocalContainerEntityManagerFactoryBean and pass the  
> dataSource from
> the openejb jndi context
>
>
>
> <bean id="dataSource"
> 	        class="org.springframework.jndi.JndiObjectFactoryBean">
> 	        <property name="jndiName" value="java:openejb/Resource/ 
> myDs"/>
> 	        <property name="jndiEnvironment">
> 	            <props>
> 	                <prop key="java.naming.factory.initial">
> 	                     
> org.apache.openejb.client.LocalInitialContextFactory
> 	                </prop>
> 	            </props>
> 	        </property>
> 		</bean>
>
> <bean id="entityManagerFactory"
> 	
> class 
> ="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
>                <property name="dataSource" ref="dataSource">
> 		<property name="jpaVendorAdapter">
> 			<bean
> 				 
> class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
> 				<property name="database" value="MYSQL" />
> 				<property name="showSql" value="true" />
> 			</bean>
> 		</property>
> 	</bean>
>
> <!-- bean post-processor for JPA annotations -->
> 	<bean
> 	
> class 
> = 
> "org 
> .springframework 
> .orm.jpa.support.PersistenceAnnotationBeanPostProcessor"
> />
>
>       <bean id="MyEntityEao"
> 		class="eao.jpa.GenericEaoJpa">
> 		<constructor-arg
> 			value="model.MyEntity" />
> 	</bean>
>
>
> I get the following error when running the test
>
> Invocation of init method failed; nested exception is javax.naming.N
> ameNotFoundException: Name "java:openejb/Resource/myDs" not found.
> Caused by: javax.naming.NameNotFoundException: Name
> "java:openejb/Resource/myDs"
> not found.
>        at
> org.apache.openejb.core.ivm.naming.IvmContext.federate(IvmContext.jav
> a:172)
>        at
> org.apache.openejb.core.ivm.naming.IvmContext.lookup(IvmContext.java:
> 129)
>        at javax.naming.InitialContext.lookup(InitialContext.java:351)
>        at
> org.springframework.jndi.JndiTemplate$1.doInContext(JndiTemplate.java
> :123)
>        at
> org.springframework.jndi.JndiTemplate.execute(JndiTemplate.java:85)
>        at
> org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:121)
>        at
> org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:146)
>        at
> org.springframework.jndi.JndiLocatorSupport.lookup(JndiLocatorSupport
> .java:93)
>        at
> org.springframework.jndi.JndiObjectLocator.lookup(JndiObjectLocator.j
> ava:105)
>        at
> org.springframework.jndi.JndiObjectFactoryBean.lookupWithFallback(Jnd
> iObjectFactoryBean.java:197)
>        at
> org.springframework.jndi.JndiObjectFactoryBean.afterPropertiesSet(Jnd
> iObjectFactoryBean.java:184)
>        at
> org.springframework.beans.factory.support.AbstractAutowireCapableBean
> Factory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java: 
> 1202)
>        at
> org.springframework.beans.factory.support.AbstractAutowireCapableBean
> Factory.initializeBean(AbstractAutowireCapableBeanFactory.java:1172)
>        at
> org.springframework.beans.factory.support.AbstractAutowireCapableBean
> Factory.createBean(AbstractAutowireCapableBeanFactory.java:428)
>        at
> org.springframework.beans.factory.support.AbstractBeanFactory$1.getOb
> ject(AbstractBeanFactory.java:251)
>        at
> org.springframework.beans.factory.support.DefaultSingletonBeanRegistr
> y.getSingleton(DefaultSingletonBeanRegistry.java:156)
>        at
> org.springframework.beans.factory.support.AbstractBeanFactory.getBean
> (AbstractBeanFactory.java:248)
>        at
> org.springframework.beans.factory.support.AbstractBeanFactory.getBean
> (AbstractBeanFactory.java:160)
>        at
> org.springframework.beans.factory.support.BeanDefinitionValueResolver
> .resolveReference(BeanDefinitionValueResolver.java:261)
>        at
> org.springframework.beans.factory.support.BeanDefinitionValueResolver
> .resolveValueIfNecessary(BeanDefinitionValueResolver.java:109)
>        at
> org.springframework.beans.factory.support.AbstractAutowireCapableBean
> Factory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java: 
> 1100)
>        at
> org.springframework.beans.factory.support.AbstractAutowireCapableBean
> Factory.populateBean(AbstractAutowireCapableBeanFactory.java:862)
>        at
> org.springframework.beans.factory.support.AbstractAutowireCapableBean
> Factory.createBean(AbstractAutowireCapableBeanFactory.java:424)
>        at
> org.springframework.beans.factory.support.AbstractBeanFactory$1.getOb
> ject(AbstractBeanFactory.java:251)
>        at
> org.springframework.beans.factory.support.DefaultSingletonBeanRegistr
> y.getSingleton(DefaultSingletonBeanRegistry.java:156)
>        at
> org.springframework.beans.factory.support.AbstractBeanFactory.getBean
> (AbstractBeanFactory.java:248)
>        at
> org.springframework.beans.factory.support.AbstractBeanFactory.getBean
> (AbstractBeanFactory.java:160)
>
>
> I've been trying to retrieve the datasource from the jndi context with
> different naming conventions with no success.
>
> Maybe this is not the correct approach to solve the problem, so any  
> advice
> would be very appreciated.
>
> Thanks in advance.
>
> -- 
> View this message in context: http://www.nabble.com/Help-with-OpenEJB3-and-Spring-IoC-tp17674222p17674222.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>
>