-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 
Author Message
 Post subject: JBoss: JNDI-SessionFactory - Session doesn't autoflush
PostPosted: Fri Jan 12, 2007 8:12 am 
Beginner
Beginner

Joined: Mon Sep 12, 2005 3:27 am
Posts: 48
Hello,

i have injected SessionFactory into Jndi. Then, inside an Hibernate-Event Listener i use the factory and get a session. With this session i can do my "unit of work". Before and after the unit of work i have NO transaction demarcation, cause jboss (4.0.5 EJB3) should use CMP.

At end of "unit of work", i have to explicitly flush the session, cause else the db-changes would not be refelected to database. Is this a bug ? Shouldn't it be autoflushed ?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 12, 2007 8:09 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
if you open the session, you're responsible for the flushing

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 15, 2007 4:28 am 
Beginner
Beginner

Joined: Mon Sep 12, 2005 3:27 am
Posts: 48
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 ?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 15, 2007 11:30 am 
Beginner
Beginner

Joined: Mon Sep 12, 2005 3:27 am
Posts: 48
Seems related to following bug: HHH-2259. Accordingly to to fisheye you changed following in 3.2.2: FishEye diff

There was stated, that auto-flush will not work correctly with getcurrentSession anymore, when using JTASessionContext and JDBCTransactionFactory. But i'm configured the sessionFactory to use JTASessionContext with JTATransactionFactory - and get the same non-working autoflush as in HHH-2259.

Is it correct now, that autoflush is not working anymore ?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 21, 2007 7:13 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
you should really use @PersistenceContext Session, not SF.getCurrentSession() when you use HEM

I do disable hibernate core auto flush to handle it myself to comply the spec.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 22, 2007 4:16 am 
Beginner
Beginner

Joined: Mon Sep 12, 2005 3:27 am
Posts: 48
But I'm using SF inside an Hibernate event listener - there doesn't any ejb3-injection work...therefore the workaround of jndi-registering and using this SF.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 24, 2007 3:43 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
if you use it inside an event or any interceptor, you have to create an new session (not reuse the current one) and flush manually

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.