Results 1 to 2 of 2

Thread: Use Hibernate StatelessSession along another Spring managed session.

Hybrid View

  1. #1

    Default Use Hibernate StatelessSession along another Spring managed session.

    Hi,

    Normally, we use Spring and Atomikos to manage the JTA sessions and set hibernate.auto_close_session to true. Now, if we manually open a stateless session (for some async job) as:

    Code:
    StatelessSession sl = sessionFactory.openStatelessSession();
    How do we close the StatelessSession? If we call

    Code:
    sl.close()
    then the "currentSession" will rollback.

    If we annotate

    Code:
    @Transactional(propagation = Propagation.NOT_SUPPORTED)
    on the method that use the StatelessSession, the commit hangs, the Atomikos log shows that it keep spawning new transactions and never stops.

    Full code:

    Code:
    public Vendor findByCode(String code) {
                    StatelessSession slsession = null;
                    Transaction tx = null;
                    try {
                            slsession = getStatelessSession();
                            tx = slsession.beginTransaction();
                            return (Vendor) slsession.createQuery("from Vendor"
                                            + " where code = :code")
                                            .setParameter("code", code)
                                            .uniqueResult();
                    } catch (HibernateException e) {
                            e.printStackTrace();
                            return null;
                    } finally {
                            if (slsession != null && tx != null) {
                                    tx.commit();
                                    slsession.close();
                            }
                    }
            }
    There is already a Spring managed session, and this method was called.

    Could you suggest what is wrong?
    Last edited by Dao007forever; Dec 6th, 2012 at 03:44 AM.

  2. #2

    Default

    Hi, anyone could shed some insight on this matter?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •