DbPersistenceServiceFactory should not close SessionFactory if it didn't opened it
----------------------------------------------------------------------------------
Key: JBPM-2605
URL:
https://jira.jboss.org/jira/browse/JBPM-2605
Project: jBPM
Issue Type: Bug
Security Level: Public (Everyone can see)
Affects Versions: jBPM 3.2.7
Environment: JBoss 4.2.3, Seam 2.1
Reporter: Stefano Travelli
I configure JBpm with Seam 2.1 so that the JBpm SessionFactory is the same of the
underlying SessionFactory used by the EntityManagerFactory in JPA.
In order to do so I include JBpm hibernate.cfg.xml in the persistence-unit. Then I declare
the JNDI name in jbpm.cfg.xml:
<persistence-unit name="getin">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>java:/getinDS</jta-data-source>
<propertyies>
<!--- ... --->
<property name="hibernate.session_factory_name"
value="java:/getinSessionFactory"/>
<property name="hibernate.ejb.cfgfile"
value="jbpm.hibernate.cfg.xml"/>
</properties>
</persistence-unit>
<jbpm-configuration>
<jbpm-context>
<service name="persistence">
<factory>
<bean
class="org.jbpm.persistence.db.DbPersistenceServiceFactory">
<field name="isTransactionEnabled">
<false/>
</field>
<field name="sessionFactoryJndiName">
<string value="java:/getinSessionFactory"/>
</field>
</bean>
</factory>
</service>
<service name="tx"
factory="org.jbpm.tx.TxServiceFactory"/>
<service name="message"
factory="org.jbpm.msg.db.DbMessageServiceFactory"/>
<service name="scheduler"
factory="org.jbpm.scheduler.db.DbSchedulerServiceFactory"/>
<service name="logging"
factory="org.jbpm.logging.db.DbLoggingServiceFactory"/>
<service name="authentication"
factory="org.jbpm.security.authentication.DefaultAuthenticationServiceFactory"/>
</jbpm-context>
</jbpm-configuration>
It works fine except that during test execution in the Seam enviroment JBpm context is
opened and closed several times while the persistence unit stays.
However, as a JBpm context closes, DbPersistenceServiceFactory also closes the
SessionFactory invalidating the EntityManagerFactory.
When DbPersistenceServiceFactory doesn't create the SessionFactory taking it from
JNDI, it shouldn't close it as this should be a responsibility of the component who
registered it in JNDI in first place.
The patch is simple:
public void close()
{
if (sessionFactory != null && sessionFactoryJndiName == null)
{
log.debug("closing hibernate session factory");
sessionFactory.close();
}
}
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
https://jira.jboss.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira