but:
a) i'm using jboss and there a JTA-Datasource
b) i'm using
getCurrentSession of jndi-registered SessionFactory instead of explicitly open a new Session via
openSession.
I think, that in case of an JTA-Datasource and an EJB3-Container (Jboss), the implementation class of
CurrentSessionContxt is
"org.hibernate.context.JTASessionContext". And for this class the java-doc constitutes for the method
currentSession:
Quote:
* Note that the sessions returned from this method are automatically configured with
* both the {@link org.hibernate.cfg.Environment#FLUSH_BEFORE_COMPLETION auto-flush} and
* {@link org.hibernate.cfg.Environment#AUTO_CLOSE_SESSION auto-close} attributes set to
* true, meaning that the Session will be automatically flushed and closed
* as part of the lifecycle for the JTA transaction to which it is associated
Equivalent to this explanation, shouldn't be autoflush- and close automatically set to true and work, if i binding the sessionFactory of a JTA-Datasource to jdni via following persistence.xml of a jboss-application:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<persistence>
<persistence-unit name="lims" transactionType="JTA">
<jta-data-source>java:/DefaultDS</jta-data-source>
<properties>
<property name="hibernate.session_factory_name"
value="java:hibernate/SessionFactory" />
</properties>
</persistence-unit>
</persistence>
BTW: I'm using the SessionFactory and "getCurrentSession" not in a regular EJB3 Session-Bean, but in an Hibernate PostInsertListener. But these listener should in my opinion span the same JTA-Transaction than the original bean-method. Isn't ?