Iam working on updating a mapped class property to the database using the setPropertyValue method. This is not updating the values in the database. Suggestions will be helpful. The code is excuting but not commiting to the DB.
public static String setPropertyValueForClass(AssetTrackingObject object,int parentId, Class parentClass, String attributeName,String attributeValue ) { Object legacyObject = null; String result = null; Session session = null; boolean isTransactionLocal = false; final String methodName = "setPropertyValueForClass"; getPropertyValueForClass( parentId, parentClass, attributeName ); try { isTransactionLocal = HibernateUtil.checkAndStartTrans(true, methodName, CLASSNAME, true); session = HibernateUtil.getSessionFactory().getCurrentSession(); logger.logInfo(CLASSNAME, "setPropertyValueForClass:ParentId="+ parentId + " Parent Class:"+ parentClass + " Attr.Name:"+ attributeName + " Attr.Value:"+attributeValue );
legacyObject = (Object) session.load(parentClass, new Integer(parentId)); ClassMetadata classMetadata = HibernateUtil.getSessionFactory().getClassMetadata(parentClass); ACMConstants.AssetValueType valueType = object.getAssetValueType(); Object attrValue = null; if (valueType==ACMConstants.AssetValueType.STRING){ attrValue = new String(attributeValue); } if (valueType==ACMConstants.AssetValueType.FLOAT){ attrValue = new Float(attributeValue); } if (valueType==ACMConstants.AssetValueType.INTEGER){ attrValue = new Integer(attributeValue); }
classMetadata.setPropertyValue(legacyObject, attributeName, attrValue,EntityMode.POJO); session.saveOrUpdate(legacyObject); HibernateUtil.commitTransaction(isTransactionLocal,methodName,CLASSNAME); } catch (Exception e) { HibernateUtil.rollbackTransaction(e, isTransactionLocal, methodName,CLASSNAME); logger.logError(CLASSNAME, "Failed due to " + e.getMessage());// fail if an error occurs logger.logError(CLASSNAME, "getPropertyValueForClass:Legacy Object Not Found: ParentId="+ parentId + " Parent Class:"+ parentClass + " Attr.Name:"+ attributeName ); } return result; }
|