Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
Samuli Saarinen
Service builder convert-null=false and caching
March 21, 2013 12:44 AM
Answer

Samuli Saarinen

Rank: New Member

Posts: 12

Join Date: February 21, 2012

Recent Posts

Hi,
I'm using Liferay EE 6.1.20 and I have a problem with service builder and caching. I have defined some entity using service bulder as follows:

1
2<entity name="Platform" local-service="true" remote-service="false" cache-enabled="true" >
3        <column name="id" db-name="RECID" type="long" primary="true" />
4        <column name="location" type="String" convert-null="false"/>
5</entity>


And test code that shows the not wanted behavior

 1
 2public void testCaching() {
 3        List<Platform> platforms = getPlatforms();
 4        Platform p1 = platforms.get(0);
 5
 6        List<Platform> cachedPlatforms = getPlatforms();
 7        Platform p2 = cachedPlatforms.get(0);
 8
 9        platformPersistence.clearCache();
10
11        List<Platform> freshPlatforms = getPlatforms();
12        Platform p3 = freshPlatforms.get(0);
13
14        System.out.println("initial: " + p1.getLocation());
15        System.out.println("cached: " + p2.getLocation());
16        System.out.println("fresh: " + p3.getLocation());
17    }


This produces following output
> initial: null
> cached:
> fresh: null

It seems that when object is returned from cache the convert-null=false behavior is not respected and null is converted to empty string.

I would assume that caching an entity should not change it's data. Is there a bug in liferay or am I doing something wrong here?

Cheers,

Samuli