Fórumok

Service builder convert-null=false and caching

Samuli Saarinen, módosítva 11 év-val korábban

Service builder convert-null=false and caching

New Member Bejegyzések: 16 Csatlakozás dátuma: 2012.02.22. Legújabb bejegyzések
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:


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


And test code that shows the not wanted behavior


public void testCaching() {
		List<platform> platforms = getPlatforms();
		Platform p1 = platforms.get(0);

		List<platform> cachedPlatforms = getPlatforms();
		Platform p2 = cachedPlatforms.get(0);

		platformPersistence.clearCache();

		List<platform> freshPlatforms = getPlatforms();
		Platform p3 = freshPlatforms.get(0);

		System.out.println("initial: " + p1.getLocation());
		System.out.println("cached: " + p2.getLocation());
		System.out.println("fresh: " + p3.getLocation());
	}
</platform></platform></platform>


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