I'm using hibernate and oracle 11g2 in one of my projects. I had to upgrade recently to a new version of hibernate, first from 3.6.1 to 3.6.10 and then to 4.1.8. However after migrating to 4.1.8 now my oracle sessions are never closed even after I close SessionFactory and I don't understand why.
Below you can find an example of how I'm creating and closing the session factory:
- Using hibernate 3.6.10: SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory(); Session session = sessionFactory.openSession(); Journal t = (Journal) session.get(Journal.class, 12); session.close(); sessionFactory.close();
- Using hibernate 4.1.8: Configuration configuration = new Configuration(); configuration.configure(); ServiceRegistry serviceRegistry = new ServiceRegistryBuilder(). applySettings(configuration.getProperties()). buildServiceRegistry(); SessionFactory sessionFactory = configuration.buildSessionFactory(serviceRegistry); Session session = sessionFactory.openSession(); Journal t = (Journal) session.get(Journal.class, 12); session.close(); sessionFactory.close();
- The hibernate.cfg.xml is:
<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration> <session-factory> <property name="hibernate.bytecode.use_reflection_optimizer">false</property> <property name="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</property> <property name="hibernate.connection.driver_class">oracle.jdbc.OracleDriver</property> <property name="hibernate.connection.url">jdbc:oracle:thin:@....</property>
<property name="hibernate.default_schema">xx</property> <property name="hibernate.connection.username">yy</property> <property name="hibernate.connection.password">zz</property>
<property name="hibernate.show_sql">true</property> <property name="hibernate.format_sql">true</property> <property name="hibernate.use_sql_comments">true</property>
<mapping resource="Journal.hbm.xml" /> </session-factory> </hibernate-configuration>
After the upgrade to 4.1.8 all oracle sessions are never closed... I usually run the following select statement to check which are the open connections: - select status, logon_time, SID, Serial#, UserName, SchemaName, Program, Machine from v$session;
Please can anyone give me any insight on how to fix this?
Many thanks in advance.
|