Hi there,
I am having a description object to maintain code and description values and it will be cached with usage as "nonstrict-read-write". Occasionally this object will be updated with new values from the mainframe host system. For that reason, I gave this object with Classcache value as "nonstrict-read-write". Recently our backend database (DB2) upgraded to version 9.7. After this I am not able to update the object with new values and it is giving me the below exception
Code:
Application attempted to edit read only item: com.westpac.nzlo.pd.security.SecurityDescription#2
[10/4/11 18:01:01:543 NZDT] 00000036 RegisteredSyn E WTRN0074E: Exception caught from before_completion synchronization operation: java.lang.UnsupportedOperationException
at org.hibernate.transaction.WebSphereExtendedJTATransactionLookup$TransactionManagerAdapter$TransactionAdapter.setRollbackOnly(WebSphereExtendedJTATransactionLookup.java:211)
at org.hibernate.transaction.CacheSynchronization.setRollbackOnly(CacheSynchronization.java:73)
at org.hibernate.transaction.CacheSynchronization.beforeCompletion(CacheSynchronization.java:63)
at org.hibernate.transaction.WebSphereExtendedJTATransactionLookup$1.invoke(WebSphereExtendedJTATransactionLookup.java:136)
at $Proxy24.beforeCompletion(Unknown Source)
at com.ibm.ws.jtaextensions.SynchronizationCallbackWrapper.beforeCompletion(SynchronizationCallbackWrapper.java:66)
at com.ibm.tx.jta.RegisteredSyncs.coreDistributeBefore(RegisteredSyncs.java:289)
at com.ibm.ws.tx.jta.RegisteredSyncs.distributeBefore(RegisteredSyncs.java:150)
at com.ibm.ws.tx.jta.TransactionImpl.prePrepare(TransactionImpl.java:2316)
at com.ibm.ws.tx.jta.TransactionImpl.stage1CommitProcessing(TransactionImpl.java:536)
at com.ibm.tx.jta.TransactionImpl.processCommit(TransactionImpl.java:983)
at com.ibm.tx.jta.TransactionImpl.commit(TransactionImpl.java:918)
at com.ibm.ws.tx.jta.TranManagerImpl.commit(TranManagerImpl.java:377)
at com.ibm.tx.jta.TranManagerSet.commit(TranManagerSet.java:161)
at com.ibm.ejs.csi.TranStrategy.commit(TranStrategy.java:927)
at com.ibm.ejs.csi.TranStrategy.postInvoke(TranStrategy.java:230)
at com.ibm.ejs.csi.TransactionControlImpl.postInvoke(TransactionControlImpl.java:570)
at com.ibm.ejs.container.EJSContainer.postInvoke(EJSContainer.java:4558)
at com.westpac.nzlo.framework.serviceexecutor.EJSLocalStatelessServiceExecutorEJB_e5d362d6.executeBatch(Unknown Source)
at com.westpac.nzlo.framework.batchexecutor.BatchExecutorFacadeEJB.executeBatch(BatchExecutorFacadeEJB.java:219)
at com.westpac.nzlo.framework.batchexecutor.EJSRemoteStatelessBatchExecutorFacade_00f94d8e.executeBatch(Unknown Source)
at com.westpac.nzlo.framework.batchexecutor._EJSRemoteStatelessBatchExecutorFacade_00f94d8e_Tie.executeBatch(_EJSRemoteStatelessBatchExecutorFacade_00f94d8e_Tie.java:160)
at com.westpac.nzlo.framework.batchexecutor._EJSRemoteStatelessBatchExecutorFacade_00f94d8e_Tie._invoke(_EJSRemoteStatelessBatchExecutorFacade_00f94d8e_Tie.java:103)
at com.ibm.CORBA.iiop.ServerDelegate.dispatchInvokeHandler(ServerDelegate.java:623)
at com.ibm.CORBA.iiop.ServerDelegate.dispatch(ServerDelegate.java:476)
at com.ibm.rmi.iiop.ORB.process(ORB.java:513)
at com.ibm.CORBA.iiop.ORB.process(ORB.java:1574)
at com.ibm.rmi.iiop.Connection.respondTo(Connection.java:2845)
at com.ibm.rmi.iiop.Connection.doWork(Connection.java:2718)
at com.ibm.rmi.iiop.WorkUnitImpl.doWork(WorkUnitImpl.java:63)
at com.ibm.ejs.oa.pool.PooledThread.run(ThreadPool.java:118)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1604)
Please find the code for update and hibernate.cfg.xml
Code:
import java.math.BigDecimal;
import java.sql.Date;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import org.apache.commons.collections.map.MultiValueMap;
import org.apache.log4j.Logger;
import org.hibernate.Session;
/**
* <p>
* The <code>SecurityDescription</code> describes the type of
* <code>Security</code>.
*
* </p>
*
* @hibernate.class table="SECURITY_DESCRIPTION"
*
*
* @version 1.0
*
*/
public class SecurityDescription extends BaseBusinessObject {
/**
* <P> Logger</p>
*/
private static Logger LOG = Logger
.getLogger( SecurityDescription.class );
/**
* <P> This is object id property (primary key)</p>
*/
private Long oid;
/**
* <P> This property refers to the code of this description</p>
*/
private String code;
/**
* <P> This property describes the <code>SecurityDescription</code></p>
*/
private String description;
/**
* Priority of security to display on screen
*/
private int sortOrder;
/**
* @hibernate.id generator-class="native" column="SECURITY_DESC_ID"
*
* @return Returns the oid.
*/
public Long getOid() {
return oid;
}
/**
* @param oid
* The oid to set.
*/
public void setOid(Long oid) {
this.oid = oid;
}
/**
* @hibernate.property column="CODE"
*
* @return Returns the code.
*/
public String getCode() {
return code;
}
/**
* @param code
* <code>String</code> The code to set.
*/
public void setCode(String code) {
this.code = code;
}
/**
* @hibernate.property column="DESCRIPTION"
*
* @return Returns the description.
*/
public String getDescription() {
return description;
}
/**
* @param description
* <code>String</code> The description to set.
*/
public void setDescription(String description) {
this.description = description;
}
/**
* @hibernate.property column="SORT_ORDER"
*
* @return Returns the SortOrder.
*/
public int getSortOrder() {
return sortOrder;
}
/**
* @param sortOrder
* <code>int</code> The sortOrder to set.
*/
public void setSortOrder(int sortOrder) {
this.sortOrder = sortOrder;
}
/**
* <p>
* Find the <code>SecurityDescription <code> by code
* <p>
*
* @param code
* code for search <code>SecurityDescription<code>
*
* @return <code>SecurityDescription<code> represented by the supplied code
*
* @throws MoreThanOneMatchesCriteriaException
* if many <code>SecurityDescription</code> is found for the code
*/
public static SecurityDescription findByCode(String code) {
SecurityDescription securityDescription= null;
try
{
IDescriptionDAO descriptionDAO = (IDescriptionDAO) ExternalSystemFactory
.getImplementor(IDescriptionDAO.class);
securityDescription = (SecurityDescription)
descriptionDAO.findByCode(SecurityDescription.class,code);
}
catch ( PersistenceException persistenceException )
{
LOG
.error( "PersistenceException in findByCode of Security description",
persistenceException );
throw persistenceException;
}
catch ( MoreThanOneMatchesCriteriaException matchesCriteriaException )
{
LOG
.error( "MoreThanOneMatchesCriteriaException in findByCode of Security description",
matchesCriteriaException );
throw new PersistenceException( matchesCriteriaException );
}
return securityDescription;
}
/**
* <p>
* This method describes whether the
* <code>SecurityDescription</code> object is cached
* or not. By default it returns true.
* </p>
*
* @return boolean true
*/
public boolean isCached()
{
return true;
}
/**
* <p>
* This method describes whether the
* <code>SecurityDescription</code> object can be
* edited ie changeable. By default it returns false.
* </p>
*
* @return boolean false
*/
public boolean isMutable()
{
return false;
}
/**
* <p>
*
* This method is used to refresh all NZLO
* <code>SecurityDescription</code>s with host (From security registry)
* <code>SecurityDescription</code>s
*
* </p>
*
* @return <code>ExternalSystemException</code>
* @return <code>Exception</code>
*/
public static void refresh()throws ExternalSystemException,Exception
{
List securityDescriptionList = new ArrayList();
try {
Object securitySystemInterface = ExternalSystemFactory.getImplementor(ISecuritySystem.class);
ISecuritySystem securitySystem = (ISecuritySystem) securitySystemInterface;
securityDescriptionList = securitySystem.listAllAssetDescription();
Iterator securityDescriptionListItr = securityDescriptionList.iterator();
while(securityDescriptionListItr.hasNext())
{
SecurityDescription securityDescription = (SecurityDescription)
securityDescriptionListItr.next();
saveOrUpdateSecurityDescription(securityDescription);
}
evictSecurityDescription();
}
catch (ExternalSystemException e) {
throw e;
}
catch (Exception e) {
throw e;
}
}
/**
* <p>
* Evict all entries from the second-level cache for
* <code>SecurityDescription</code>.
* </p>
*
*/
private static void evictSecurityDescription()
{
Session session = ((HibernateUtils3) PersistenceUtils.getInstance()).currentSession();
session.getSessionFactory().evict(SecurityDescription.class);
}
/**
* <p>
*
* This method is used to save/update <code>SecurityDescription</code>
* object.
*
* If given code of <code>SecurityDescription</code> object is available
* in database then <code>SecurityDescription</code> object
* description updates with given <code>SecurityDescription</code>
* object description.
*
* If given code of <code>SecurityDescription</code> object is not available
* in database then clone the new <code>SecurityDescription</code> object
* using given <code>SecurityDescription</code>object and save new entry into database.
*
* <p>
*
* @param securityDescription
* <code>SecurityDescription</code>
*
*/
private static void saveOrUpdateSecurityDescription(SecurityDescription securityDescription)throws Exception
{
SecurityDescription securityDescriptionObj = SecurityDescription.findByCode(securityDescription.getCode());
if( null != securityDescriptionObj ){
securityDescriptionObj.setDescription(securityDescription.getDescription());
securityDescriptionObj.update();
}
}
}
Hibernate.cfg.xmlCode:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<!-- Generated file - Do not edit! -->
<hibernate-configuration>
<!-- a SessionFactory instance listed as /jndi/name -->
<session-factory>
<!-- properties -->
<property name="connection.datasource">java:comp/env/jdbc/Lending</property>
<property name="dialect">org.hibernate.dialect.DB2Dialect</property>
<property name="show_sql">false</property>
<property name="use_outer_join">false</property>
<property name="transaction.manager_lookup_class">org.hibernate.transaction.WebSphereExtendedJTATransactionLookup</property>
<property name="hibernate.transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</property>
<property name="hibernate.transaction.flush_before_completion">true</property>
<property name="hibernate.transaction.auto_close_session">true</property>
<property name="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</property>
<property name="hibernate.cache.use_query_cache">true</property>
<property name="hibernate.connection.provider_class">org.hibernate.connection.DatasourceConnectionProvider</property>
<!-- mapping files -->
<mapping resource="com/westpac/nzlo/pd/security/SecurityDescription.hbm.xml"/>
<!-- Security Descriptions -->
<class-cache class="com.westpac.nzlo.pd.security.SecurityDescription" usage="nonstrict-read-write" region="frequentlyUpdatedCache"/>
<class-cache class="com.westpac.nzlo.pd.security.SecurityValuationDescription" usage="read-only"/>
<class-cache class="com.westpac.nzlo.pd.security.SecuredPartyGroupDescription" usage="nonstrict-read-write" region="frequentlyUpdatedCache"/>
<class-cache class="com.westpac.nzlo.pd.security.SecurityStatusDescription" usage="read-only"/>
</session-factory>
</hibernate-configuration>
Cache .xmlCode:
<ehcache>
<defaultCache
maxElementsInMemory="25000"
eternal="false"
timeToIdleSeconds="86400"
timeToLiveSeconds="86400"
overflowToDisk="false"
diskPersistent="false"
diskExpiryThreadIntervalSeconds="120" />
<cache name="frequentlyUpdatedCache"
maxElementsInMemory="5000"
eternal="false"
timeToIdleSeconds="3600"
timeToLiveSeconds="3600"
overflowToDisk="false"
diskExpiryThreadIntervalSeconds="120" >
</cache>
</ehcache>