Announcement Announcement Module
Collapse
No announcement yet.
Trying to configure spring w/ Hibernate on Geronimo Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Trying to configure spring w/ Hibernate on Geronimo

    I can't seem to get Spring and Hibernate working on Geronimo with a JNDI datasource managed by geronimo. Hibernate works fine when I just configure persistence.xml and leave out spring, and Spring+Hibernate work fine when I just use something like org.apache.commons.dbcp instead of the managed DB POOL. Here are my config files:

    META-INF/persistence.xml
    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>
    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>
    My geronimo dbPool RA config

    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>
    Then I get the following exception:
    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
    Other Points:

    - jdbc/wakapeek is the correct JNDI name, that's how it's configured in persistence.xml and that works when I remove spring. Also, that is the JNDI name when I browse JNDI through the geronimo console.

    - I do not have a jndi.properties file, I'm assuming (perhaps incorrectly) since it's on the same JVM and local, Spring should be able to locate it.

    - I've also tried many different configurations, but always the same problem. The reason I want to use Spring is to allow me to inject an EntityManager into my DAOs using @PersistenceContext (and all the other nice Spring stuff too)

    - I didnt add anything to web.xml because I'm not using a servlet. This is just an EJB3 / Hibernate backend. I'm currently bootstrapping spring with ContextSingletonBeanFactoryLocator

    If the PU and DB details are configured in persistence.xml, is there a way to configure spring to just get the info from the persistence.xml file?

    Any clues would really be helpful. Most examples I've googled for do not show usage with a container managed datasource.

    Thanks,

    Billy

  • #2
    follow up

    So apparently Geronimo doesn't use JNDI internally to locate the DataSource..

    Not sure there is a solution.. There has to be someone out there using Spring + Hibernate with Geronimo 2.x with a container managed dbpool, no?

    Comment


    • #3
      Hi,

      I am stuck up with the same problem. Any luck for the solution to this?

      Thanks!

      Comment

      Working...
      X