PDA

View Full Version : jee:jndi-lookup vs JndiObjectFactoryBean



richardgundersen
Feb 11th, 2009, 07:28 AM
Hi

I spent a while trying to get the jee:jndi-lookup definition working (Hibernate EntityManager on Tomcat) without success (it seemed like the flashy way to do things).


<jee:jndi-lookup id="entityManagerFactory" jndi-name="java:comp/env/jdbc/myDs"/>

Then I realised I could do the same with JndiObjectFactoryBean, and it works fine.


<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="java:comp/env/jdbc/myDs"/>
</bean>

myDs is configured in Tomcat's server.xml like so


<Context distributable="true" path="/BulkUploader" reloadable="true">
<Resource name="jdbc/myDs"
auth="Container"
type="javax.sql.DataSource"
username="username"
password="password"
driverClassName="oracle.jdbc.OracleDriver"
url="...myUrl..."
maxActive="8"
maxIdle="4"/>
</Context>

As I don't have a great understanding of how JPA, Spring, transactions etc all fit together, I'm wondering if my simpler approach comes at a cost (performance, transaction support etc etc).

It all seems to be working, but would appreciate any ideas/thoughts :)

Richard

Marten Deinum
Feb 11th, 2009, 08:05 AM
As I don't have a great understanding of how JPA, Spring, transactions etc all fit together, I'm wondering if my simpler approach comes at a cost (performance, transaction support etc etc).

No it doesn't. Underneath the covers the namespace does the same as you do with the JndiObjectFactoryBean, but it is much easier/shorter :)...

Regarding your setup, it is a DataSource not an EntityManagerFactory as you initialy mention...

richardgundersen
Feb 11th, 2009, 08:24 AM
Thanks Marten, that puts my mind at rest. When I get some time I'll try and figure out the shorter version wasn't working

-Richard