Murshida Ck
Murshida Ck

Reputation: 1

update blob data using service builder classes failed

I'm using liferay-6.1 CE.I am developing a project for storing the application data as BLOB in DB using service builder. This is my entity in service.xml

<entity name="MyEntity" local-service="true" remote-service="false" table="MyEntity">

I have defined my blob data as below in service.xml

 <column name="myData" type="Blob"/>

I persisted data into db by using code below.

long primarykey = CounterLocalServiceUtil.increment(com.mycompany.portal.model.MyEntity.class.getName())
MyEntity entityobj = MyEntityLocalServiceUtil.createMyEntity(primarykey);
byte[] bytes =String.valueOf(JAXBUtil.getInstance().marshal(appModelAttri, AppEntity.class)).getBytes();
//String.valueOf(JAXBUtil.getInstance().marshal(appModelAttri, AppEntity.class)).getBytes(); has the marshalled xml data of my application
Blob blobdata = new SerialBlob(bytes);
entityobj.setmyData(blobdata);
MyEntityLocalServiceUtil.addMyEntity(entityobj)

Persisting to db worked well.But when I tried to update the same record in DB every other fields in my table except the blob data field is updated.

Code for updating Blob data is given below.

MyEntity entityobj = MyEntityLocalServiceUtil.getMyEntityByScreenName(PortalUtil.getUser(actionRequest).getScreenName());
byte[] bytes =String.valueOf(JAXBUtil.getInstance().marshal(appModelAttri, AppEntity.class)).getBytes();
Blob blobdata = new SerialBlob(bytes);
entityobj.setmyData(blobdata);
MyEntityLocalServiceUtil.updateMyEntity(entityobj);

I dont understand why only Blob data is not getting updated when I call updateMyEntity method. Is there anything specific with Blob data updation using service builder generated classes?.Please help me.

Upvotes: 0

Views: 381

Answers (1)

Murshida Ck
Murshida Ck

Reputation: 1

I got the solution for blob updation failure. To solve this you have to set cachedmodel to false and call the update method with 2 parameters (entity object and merge ).By doing so you are forcefully making it execute session.saveOrUpdate statement and will skip session.merge(appModel) statement in upadate() method of BatchSessionImpl.

entityobj.setCachedModel(false);

MyEntityLocalServiceUtil.updateMyEntity(entityobj,false);

Upvotes: 0

Related Questions