-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Hibernate/Spring loading an JNDI data source
PostPosted: Sun Oct 18, 2009 9:38 am 
Newbie

Joined: Sun Oct 18, 2009 9:34 am
Posts: 1
Hello ,

I'm trying to load my datasource of hibernate from the JNDI of Webspherer, that's my configuration file that's run successfully but without looking up an JNDI configuration. I would like to do so, but with an JNDI config of my datasource. I hope that i have well descripted my request
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "file:/C:/Bin/spring122/dist/spring-beans.dtd">

<beans>
   <!-- ========================= Start of PERSISTENCE DEFINITIONS ========================= -->

   <!-- DataSource Definition -->
   <bean id="dataSource"
      class="com.mchange.v2.c3p0.ComboPooledDataSource"
      destroy-method="close">
      <property name="driverClass">
         <value>oracle.jdbc.driver.OracleDriver</value>
      </property>

   
      <property name="jdbcUrl">
         <value>jdbc:oracle:thin:@myhost:1521:database</value>

      </property>
      <property name="user">
         <value>user</value>
      </property>
      <property name="password">
         <value>password</value>
      </property>
   </bean>

   <!-- Hibernate SessionFactory Definition -->
   <bean id="sessionFactory"
      class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
      <property name="mappingResources">
         <list>            
            <value>model/bean/client.hbm.xml</value>
            <value>model/bean/material.hbm.xml</value>
      
            
         </list>

      </property>

      <property name="hibernateProperties">
         <props>
      
            <prop key="hibernate.dialect">
               org.hibernate.dialect.OracleDialect
            </prop>
            <prop key="hibernate.show_sql">true</prop>
            <prop key="hibernate.cglib.use_reflection_optimizer">
               true
            </prop>
            <prop key="hibernate.cache.provider_class">
                org.hibernate.cache.HashtableCacheProvider
            </prop>
            <prop key="hibernate.c3p0.acquire_increment">1</prop>
               <prop key="hibernate.c3p0.minPoolSize">10</prop>
               <prop key="hibernate.c3p0.maxPoolSize">100</prop>
            <prop key="hibernate.c3p0.timeout">100</prop>
            <prop key="hibernate.c3p0.max_statement">20</prop> 
            <prop key="hibernate.c3p0.idle_test_period">100</prop>
          <!-- 
          <prop key="hibernate.current_session_context_class">org.hibernate.transaction.JDBCTransactionFactory</prop>   
            **Enable Hibernate's automatic Session context management **
            <prop key="hibernate.transaction.factory_class">thread</prop> 
          -->   
         
            </props>
      </property>


      <property name="dataSource">
         <ref bean="dataSource" />
      </property>
   </bean>

   <!-- Spring Data Access Exception Translator Defintion -->
   <!-- translation des erreur come elle est au console-->
   <bean id="jdbcExceptionTranslator"
      class="org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator">
      <property name="dataSource">
         <ref bean="dataSource" />
      </property>
   </bean>

   <!-- Hibernate Template Defintion -->
   <bean id="hibernateTemplate"
      class="org.springframework.orm.hibernate3.HibernateTemplate">
      <property name="sessionFactory">
         <ref bean="sessionFactory" />
      </property>
      <property name="jdbcExceptionTranslator">
         <ref bean="jdbcExceptionTranslator" />
      </property>
   </bean>

   <!-- Hibernate Transaction Manager Definition -->
   <!-- cette classe est ds la le jar jta -->
   <bean id="transactionManager"
      class="org.springframework.orm.hibernate3.HibernateTransactionManager">
      <property name="sessionFactory">
         <ref local="sessionFactory" />
      </property>
   </bean>
</beans>


Thanks


Top
 Profile  
 
 Post subject: Re: Hibernate/Spring loading an JNDI data source
PostPosted: Mon Nov 16, 2009 9:04 am 
Newbie

Joined: Mon Nov 16, 2009 8:43 am
Posts: 2
Location: Mumbai, India
Hi,
I think you can do it by following these steps:
1. Define and setup your JNDI Datasource in WebSphere application server. Remember its name
2. Add a bean from Spring in your spring configuration as follows:
Code:
        <bean id="jndiDataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
      <property name="jndiName" value="java:comp/env/jdbc/nbaDev"/>
   </bean>

3. Point this above JNDI dataSorce bean in Hibernate bean as follows:
Code:
        <bean  id="sessionFactory"
         class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
      <property name="dataSource" ref="jndiDataSource" />


      <property name="annotatedClasses">
         <list>
              <value>com.domain.BannedEmail</value>
              <value>com.domain.Company</value>
         </list>
      </property>
      <property name="hibernateProperties">
         <props>
            <prop key="hibernate.show_sql">false</prop>
            <prop key="hibernate.format_sql">false</prop>
            <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
                                <prop key="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</prop>
                      <prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop>
                      <prop key="hibernate.cache.provider_configuration_file_resource_path">my-ehcache.xml</prop>
                           <prop key="hibernate.cache.use_structured_entries">true</prop>
                      <prop key="hibernate.cache.use_second_level_cache">true</prop>
                      <prop key="hibernate.cache.use_query_cache">true</prop>
                      <prop key="hibernate.default_batch_fetch_size">30</prop>
                      <prop key="hibernate.jdbc.batch_size">30</prop>
                      <prop key="hibernate.generate_statistics">true</prop>
                      <prop key="hibernate.order_updates">true</prop>
                      <prop key="hibernate.connection.release_mode">auto</prop>
         </props>
      </property>
   </bean>
   

_________________
Yagnesh Chawda
yagnesh.chawda@gmail.com
http://yagneshchawda.blogspot.com/
Good planets are hard to find, save energy and plants !!!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.