background: I am using geronimo + hibernate + spring. Just using the JPA api's on an EJB backend that contains no servlets, no web.xml.
I've been working on this for literally 41 days and have tried all types of combinations so now I'm asking on StackOverflow for help. Please bare with me I have not slept.
I have a geronimo managed app, with a deployed dbpool in the app server. I have a persistence.xml
file for JPA:
<persistence>
<persistence-unit name="mypu" transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>jdbc/mydb</jta-data-source>
<non-jta-data-source>jdbc/mydb</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>
the db works and I can use the @Resource
annotation and @PersistenceContext
in my stateless ejb to get the datasource and entitymanager, and I can even do a JNDI lookup in the ejb on java:comp/env/jdbc/mydb
just fine. (without spring)
Thus, it's all working in an EE component as per the EE spec says it should.
But I don't want that. I want the @PersistenceContext
injected in the DAO. As I understand, the container cant do that, but Spring can! But this does not work for me. I get a stacktrace: NotContextException: jdbc/mydb
Here is my latest config. it might look weird, but I've tried so many permutations, and this is the latest incarnation: [breathe]
<context:annotation-config />
<tx:annotation-driven />
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="resourceRef">
<value>false</value>
</property>
<property name="jndiName">
<value>java:comp/env/jdbc/mydb</value>
</property>
</bean>
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.ContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource" />
</bean>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
<property name="dataSource" ref="dataSource" />
</bean>
<bean id="categoryDao" class="com.wakapeek.persistence.dao.impl.CategoryDaoImpl">
<property name="dataSource" ref="dataSource" />
</bean>
<bean id="categoryService" class="com.wakapeek.ejb.service.CategoryServiceImpl">
<property name="categoryDao" ref="categoryDao" />
</bean>
When spring bootstraps, it gives me the stacktrace: NotContextException: jdbc/mydb
Also this is really important: I'm running this on an EJB backend, there is no web layer, no servlets, no web.xml DD! So in my ejb-jar.xml
file I define:
<session>
<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/mydb</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
</session>
Ok, so if anyone helps me get this working, I will put you down on my PayItForward list, and when I become rich, I will buy you a ticket to an island
somewhere. But seriously, I would really be grateful, because I'd get to keep my job. I'm not fired yet, just being handed my hat.