Announcement Announcement Module
Collapse
No announcement yet.
Using Hibernate and JDBCTEmplate with same datasource(and connection) Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Using Hibernate and JDBCTEmplate with same datasource(and connection)

    Hi ,

    I had a code which uses JDBC Template and I want to convert some of the DAO's to use Hibernatewith same conenction.

    Belwo is my application context .xml
    <jee:jndi-lookup id="containerManagedDataSource"
    jndi-name="jdbc/testDb"
    cache="true"
    resource-ref="true"
    lookup-on-startup="true"
    proxy-interface="javax.sql.DataSource"/>


    <!-- to enable jaMON SQL monitor, disable the following alias and uncomment the bean definition below -->

    <bean id="dataSource"
    class="org.springframework.jdbc.datasource.Transac tionAwareDataSourceProxy">

    <constructor-arg ref="containerManagedDataSource" />
    </bean>


    <bean id="sessionFactory"
    class="org.springframework.orm.hibernate3.LocalSes sionFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="configLocation">
    <value>classpath:hibernate.cfg.xml</value>
    </property>
    <property name="configurationClass">
    <value>org.hibernate.cfg.AnnotationConfiguration </value>
    </property>
    <property name="hibernateProperties">
    <props>
    <prop key="hibernate.dialect">org.hibernate.dialect.Orac le9Dialect</prop>
    <prop key="hibernate.show_sql">true</prop>
    </props>
    </property>
    </bean>

    <tx:annotation-driven />
    <bean id="transactionManager"
    class="org.springframework.orm.hibernate3.Hibernat eTransactionManager" >
    <property name="sessionFactory" ref="sessionFactory" />
    </bean>
    I am recieving the below exception

    Caused by: java.lang.IllegalStateException: Already value [org.springframework.jdbc.datasource.ConnectionHold er@f2c499] for key [oracle.jdbc.pool.OracleDataSource@152b6f5] bound to thread [http-8080-5]
    at org.springframework.transaction.support.Transactio nSynchronizationManager.bindResource(TransactionSy nchronizationManager.java:163)
    at org.springframework.orm.hibernate3.HibernateTransa ctionManager.doBegin(HibernateTransactionManager.j ava:526)
    ... 45 more

    Please help
Working...
X