WebSphere + JNDI + Spring Framework + Hibernate

Thought I'd post a snippet of applicationContext.xml for all the people out there trying a JNDI data source wired up in IBM's WebSphere Application Server through Spring Framework and Hibernate. I couldn't find this information as a whole anywhere out there so hopefully it helps someone.

Hit the jump for the xml.

XML:
  1. <beans>
  2.     <bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
  3.         <property name="jndiName" value="jdbc/DB2"/>
  4.         <property name="lookupOnStartup" value="false"/>
  5.         <property name="cache" value="true" />
  6.         <property name="proxyInterface" value="javax.sql.DataSource" />
  7.     </bean>
  8.    
  9.     <!-- Hibernate SessionFactory -->
  10.     <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
  11.         <property name="dataSource" ref="dataSource"/>
  12.         <property name="mappingResources">
  13.             <list>
  14.                 <value>User.hbm.xml</value>
  15.             </list>
  16.         </property>
  17.         <property name="hibernateProperties">
  18.             <props>
  19.               <prop key="hibernate.dialect">org.hibernate.dialect.DB2Dialect</prop>
  20.               <prop key="hibernate.show_sql">true</prop>
  21.               <!--    IBM WAS SPECIFIC    -->       
  22.               <prop key="hibernate.connection.datasource">jdbc/DB2</prop>
  23.               <prop key="hibernate.transaction.factory_class">org.hibernate.transaction.CMTTransactionFactory</prop>
  24.               <prop key="hibernate.transaction.manager_lookup_class">org.hibernate.transaction.WebSphereExtendedJTATransactionLookup</prop>
  25.               <!--    /END IBM WAS SPECIFIC         -->
  26.             </props>
  27.         </property>
  28.     </bean>
  29.  
  30.     <bean id="transactionManager"
  31.         class="org.springframework.transaction.jta.JtaTransactionManager">
  32.             <property name="autodetectTransactionManager" value="false" />
  33.     </bean>
  34. </beans>

Sphere: Related Content

One Comment

  1. henry
    Posted July 11, 2008 at 4:01 am | Permalink

    thank you so much. I learning from your setting now, it is interesting, because there are many kinds of setting, yours looks good.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*