All,
We have table A and B and for each entry in table A, we can have multiple entries in table B. We have mapped table B as a value type and we are retrieving all the values of table B eagerly(lazy=false).
While retrieving the data from Table A, I am facing an issue where in while initializng non-lazy collections the participating transaction fails and as a result of this the object representing table A does not contain the set of Table B data. As a result of this , null pointer exception is thrown in the code as we are expecting the data to be present in the collection.
Code:
.jdbc.AbstractBatcher] about to open ResultSet (open ResultSets: 0, globally: 0)
''[2013-05-21 09:33:25,952] - [rId:1368247265872|ip:209.73.161.30|URI: V16/ApprovalCallbackService.updateApprovalStatus] DEBUG [org.hibernate.loader.Loader] result row: EntityKey[com.yahoo.satg.bp.apvl.ApvlInstance#1612739551], EntityKey[com.yahoo.satg.bp.apvl.ApvlInstanceObjectDetailsPart#1598505551]
''[2013-05-21 09:33:25,952] - [rId:1368247265872|ip:209.73.161.30|URI: V16/ApprovalCallbackService.updateApprovalStatus] DEBUG [org.hibernate.loader.Loader] found row of collection: [com.yahoo.satg.bp.apvl.ApvlInstance.objDetailsParts#1612739551]
''[2013-05-21 09:33:25,952] - [rId:1368247265872|ip:209.73.161.30|URI: V16/ApprovalCallbackService.updateApprovalStatus] DEBUG [org.hibernate.jdbc.AbstractBatcher] about to close ResultSet (open ResultSets: 1, globally: 1)
''[2013-05-21 09:33:25,952] - [rId:1368247265872|ip:209.73.161.30|URI: V16/ApprovalCallbackService.updateApprovalStatus] DEBUG [org.hibernate.jdbc.AbstractBatcher] about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
''[2013-05-21 09:33:25,952] - [rId:1368247265872|ip:209.73.161.30|URI: V16/ApprovalCallbackService.updateApprovalStatus] DEBUG [org.hibernate.jdbc.ConnectionManager] aggressively releasing JDBC connection
''[2013-05-21 09:33:25,952] - [rId:1368247265872|ip:209.73.161.30|URI: V16/ApprovalCallbackService.updateApprovalStatus] DEBUG [org.hibernate.jdbc.ConnectionManager] releasing JDBC connection [ (open PreparedStatements: 0, globally: 0) (open ResultSets: 0, globally: 0)]
''[2013-05-21 09:33:25,952] - [rId:1368247265872|ip:209.73.161.30|URI: V16/ApprovalCallbackService.updateApprovalStatus] DEBUG [org.hibernate.engine.StatefulPersistenceContext] initializing non-lazy collections
''[2013-05-21 09:33:25,952] - [rId:1368247265872|ip:209.73.161.30|URI: V16/ApprovalCallbackService.updateApprovalStatus] DEBUG [org.springframework.transaction.jta.JtaTransactionManager] Participating transaction failed - marking existing transaction as rollback-only
''[2013-05-21 09:33:25,952] - [rId:1368247265872|ip:209.73.161.30|URI: V16/ApprovalCallbackService.updateApprovalStatus] DEBUG [org.springframework.transaction.jta.JtaTransactionManager] Setting JTA transaction rollback-only
''[2013-05-21 09:33:25,953] - [rId:1368247265872|ip:209.73.161.30|URI: V16/ApprovalCallbackService.updateApprovalStatus] WARN [com.yahoo.satg.bp.exch.orders.OrderMgmtPodServiceImpl] (getOrderApvlInstances) - Error calling ApvlInstanceService for order=ORDER [orderId=545500051, acctId=20864466876, name='2013 Q2 MetLife LI Campaign', status=4, terminalCompleteFlg=false, reopenFlg=false, agencyContractId=71148551] and exceptionCondition(s)=[Credit_Approval_Y_Only]
''[2013-05-21 09:33:25,953] - [rId:1368247265872|ip:209.73.161.30|URI: V16/ApprovalCallbackService.updateApprovalStatus] DEBUG [com.yahoo.sm.ads.persist.common.session.HibernateSessionManagmentCommand] (doFilter) - Closed 0 hibernate sessions
''[2013-05-21 09:33:25,953] - [rId:1368247265872|ip:209.73.161.30|URI: V16/ApprovalCallbackService.updateApprovalStatus] DEBUG [com.yahoo.sm.ads.persist.common.session.HibernateUtil] (closeSessions) - Closing Session of this thread
''[2013-05-21 09:33:25,953] - [rId:1368247265872|ip:209.73.161.30|URI: V16/ApprovalCallbackService.updateApprovalStatus] DEBUG [org.hibernate.jdbc.ConnectionManager] releasing JDBC connection [ (open PreparedStatements: 0, globally: 0) (open ResultSets: 0, globally: 0)]
''[2013-05-21 09:33:25,953] - [rId:1368247265872|ip:209.73.161.30|URI: V16/ApprovalCallbackService.updateApprovalStatus] DEBUG [org.hibernate.util.JDBCExceptionReporter] could not log warnings
In the logs we can see that the Participating transaction fails while initializing non-lazy collections.
Quote:
''[2013-05-21 09:33:25,952] - [rId:1368247265872|ip:209.73.161.30|URI: V16/ApprovalCallbackService.updateApprovalStatus] DEBUG [org.hibernate.engine.StatefulPersistenceContext] initializing non-lazy collections
''[2013-05-21 09:33:25,952] - [rId:1368247265872|ip:209.73.161.30|URI: V16/ApprovalCallbackService.updateApprovalStatus] DEBUG [org.springframework.transaction.jta.JtaTransactionManager] Participating transaction failed - marking existing transaction as rollback-only
''[2013-05-21 09:33:25,952] - [rId:1368247265872|ip:209.73.161.30|URI: V16/ApprovalCallbackService.updateApprovalStatus] DEBUG [org.springframework.transaction.jta.JtaTransactionManager] Setting JTA transaction rollback-only
What we can also see is that the hibernate loader is able to load both the table A and B data.
Quote:
[org.hibernate.loader.Loader] result row: EntityKey[com.yahoo.satg.bp.apvl.ApvlInstance#1612739551], EntityKey[com.yahoo.satg.bp.apvl.ApvlInstanceObjectDetailsPart#1598505551]
''[2013-05-21 09:33:25,952] - [rId:1368247265872|ip:209.73.161.30|URI: V16/ApprovalCallbackService.updateApprovalStatus] DEBUG [org.hibernate.loader.Loader] found row of collection: [com.yahoo.satg.bp.apvl.ApvlInstance.objDetailsParts#1612739551]
Am not sure as to why the transaction fails. This is not happening always. It happens for few entities.
The method that is being called has a transaction attribute type of REQUIRED.
Configuration details for Session factory:
Code:
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.Oracle9Dialect</prop>
<prop key="hibernate.cache.use_second_level_cache">false</prop>
<prop key="hibernate.connection.autocommit">true</prop>
<prop key="hibernate.jdbc.batch_size">20</prop>
<prop key="hibernate.generate_statistics">true</prop>
<prop key="hibernate.show_sql">false</prop>
<prop key="hibernate.query.substitutions">true 1, false 0</prop>
<prop key="hibernate.transaction.auto_close_session">false</prop>
<prop key="hibernate.transaction.flush_before_completion">true</prop>
<prop key="hibernate.connection.release_mode">after_transaction</prop>
<prop key="hibernate.transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</prop>
<prop key="hibernate.transaction.manager_lookup_class">org.hibernate.transaction.JBossTransactionManagerLookup</prop>
<prop key="hibernate.current_session_context_class">jta</prop>
</props>
</property>