Hibernate version: JBoss4.0
I use HibernaetContext.getSession(JNDI) within a stateless session bean in JBoss4 like this:
Code:
public void callMethod() {
Session session = HibernaetContext.getSession(JNDI);
try {
Transaction tx = session.beginSession();
// do something with session
tx.commit();
} catch(HibernaetException e) {
} finally {
if(session!=null) {
session.close();
}
}
}
After I call this method, JBoss show the warning: Session is closed
And if I marked up the finally part, it is still working without no warning message.
Do I need to close session when using HibernateContext.getSession() or just leave the close jobs to JBoss JXA Manager?
One more question: I use Oracle for DB and configure oracle-ds.xml by the sample in JBoss, but when the system idles for sometime and I call the method again, the connection seems hanging for a long time and it shows "connection reset", "Destroying connection that could not be successfully matched"
Are there any configurations I miss, or what can I do to avoid these situations?
oracle-ds.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>
<datasources>
<local-tx-datasource>
<jndi-name>OracleDS</jndi-name>
<connection-url>jdbc:oracle:thin:@dbserver:1521:apmdb</connection-url>
<driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
<user-name>xxxxx</user-name>
<password>xxxxxx</password>
<exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.OracleExceptionSorter</exception-sorter-class-name>
<new-connection-sql>select 1 from dual</new-connection-sql>
<check-valid-connection-sql>select sysdate from dual</check-valid-connection-sql>
<metadata>
<type-mapping>Oracle9i</type-mapping>
</metadata>
<min-pool-size>20</min-pool-size>
<max-pool-size>100</max-pool-size>
<idle-timeout-minutes>0</idle-timeout-minutes>
</local-tx-datasource>
</datasources>