-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: How to persist - setPropertyValue method in ClassMetadata
PostPosted: Thu Apr 08, 2010 10:25 am 
Newbie

Joined: Wed Apr 07, 2010 5:04 pm
Posts: 1
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;
}


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.