Friday, October 30, 2015

Hibernate session is closed!

WHAT! The session was closed? Hibernate has closed the shop? No more business?
2015-10-29 12:29:04 ERROR javax.faces.event.MethodExpressionActionListener[180]: org.hibernate.SessionException: Session is closed!
 at org.hibernate.internal.AbstractSessionImpl.errorIfClosed(AbstractSessionImpl.java:129)
 at org.hibernate.internal.SessionImpl.createCriteria(SessionImpl.java:1576)
 at org.huahsin.MyBoImpl.filterBottle(MyBoImpl.java:123)
 ...
 ...
 ...
This is so ridiculous!! May be I have overlooked on this matter. Remember, I have TransactionInterceptor being define in the following way:
<bean id="transactionInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor">
        <property name="transactionManager">
            <ref bean="transactionManager"/>
        </property>
        <property name="transactionAttributes">
            <props>
                <prop key="add*">PROPAGATION_REQUIRED</prop>
                <prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
            </props>
        </property>
    </bean>
Any method defined in the BO/DAO that doesn't start with add or get will expect to see this error. In my case as shown in the stack trace, I have filterBottle() defined in MyBoImpl. To fix this, I'm require to define additional transactionAttributes in TransactionInterceptor.

No comments: