Connect to a single database with HibernateTemplate and SessionFactory

on the java side, everything works fine, but when I look at a special oracle table V $ SESSION and in my log table, which records any login or logout operations, it’s a disaster ... every single request performs a login / exit system. So here is my question: is there a way to configure Spring to have a unique database connection, or is there something wrong with the way I make the connection? Here is my datasource bean configuration:

<bean id="dataSource"
        class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName">
            <value>oracle.jdbc.OracleDriver</value>
        </property>
        <property name="url">
            <value>jdbc:oracle:thin:@nanssunorad:1523:nanorad3</value>
        </property>
        <property name="username">
            <value>foo</value>
        </property>
        <property name="password">
            <value>bar</value>
        </property>
    </bean>
<bean id="sessionFactory"
    class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <property name="configLocation">
        <value>hibernateESign.cfg.xml</value>
    </property>
    <property name="dataSource">
        <ref bean="dataSource" />
    </property>
    <property name="configurationClass">
        <value>org.hibernate.cfg.AnnotationConfiguration</value>
    </property>
</bean>

<bean id="transactionManager"
    class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    <property name="sessionFactory">
        <ref local="sessionFactory" />
    </property>
</bean>
<bean id="IXalVaParametresDAO" class="fr.asterion.archivage.hibernate.XalVaParametresDAO">
    <property name="sessionFactory">
        <ref local="sessionFactory" />
    </property>
</bean>

In my application, to get the DAO for database parameters, I do

  IXalVaParametresDAO parametreDAO = (IXalVaParametresDAO) ConfigApplication
           .getApplicationContext(this.log).getBean("IXalVaParametresDAO");

And finally, in my DAO class, I do the following:

public class XalVaParametresDAO implements IXalVaParametresDAO
{

   private HibernateTemplate hibernateTemplate;

   public void setSessionFactory(SessionFactory sessionFactory)
   {
      this.hibernateTemplate = new HibernateTemplate(sessionFactory);
   }



   public List<XalVaParametres> findAll()
   {
      log.debug("finding all XalVaParametres instances");
      try
      {
         String queryString = "from XalVaParametres";
         List lst = this.hibernateTemplate.find(queryString);

, "find", / . , . ? , . , HibernateTemplate . ?

Manux

+3
4

DriverManagerDataSource , .

, c3p0 Apache DBCP.

+3

It is better to use application server pooling and specify the jndi file in spring xml:

<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
    <property name="jndiName" value="jdbc/DSTest"/>
</bean>
+1
source

You can use your own oracle data source with connection caching, for example:

<bean id="myDataSource" class="oracle.jdbc.pool.OracleDataSource" destroy-method="close">
        <property name="connectionCachingEnabled" value="true"/>
        <property name="URL">
            <value>${jdbc.url}</value>
        </property>
        <property name="user">
            <value>${jdbc.username}</value>
        </property>
        <property name="password">
            <value>${jdbc.password}</value>
        </property>
        <property name="connectionCacheProperties">
            <value>
                MinLimit:1
                MaxLimit:1
                InitialLimit:1
                ConnectionWaitTimeout:120
                InactivityTimeout:180
                ValidateConnection:true
                MaxStatementsLimit:0
            </value>
        </property>
    </bean>
0
source

All Articles