David H Nebinger:
To do bulk import and stick with your SB code, you want to a) enable the remote SB interfaces and b) use a web service client to invoke the methods to create and populate your objects.
This ensures that your business logic gets executed, your counter object is updated appropriately, and you don't have issues w/ Liferay SB code having stale cached entities.
Thanks David. This might be the proper way and directly importing to the database is probably a hack that shouldn't be done. However, as restarting Liferay after each import does resolve the stale cashed entities issue, and there are complex SQL JOIN statements that are hard to express in DAO way, we are hoping that there is a "Liferay, please pick up the new data from the database" kind of method to quickly resolve the issue.
Jack Bakker:
Merry Christmas !
Strange that CacheRegistryUtil.clear() is not working. I believe that is what is called when Control Panel : Server Administration : "Clear the database cache. " is clicked. I have systems where other subsystem apps update db directly and then human clicking Execute for "Clear the database cache" OR programmatically doing a per entity clear cache seems to do the trick ( xXXPersistence.clearCache() )
Thanks Jack and Merry Christmas to you too!

Actually, the funnies thing is that, even though we did "Clear the database cache", Liferay still didn't pickup the changes unless we restart the Liferay service. I also tried the following functions:
1 xXXUtil.clearCache();
2 CacheRegistryUtil.clear();
3 MultiVMPoolUtil.clear();
4 WebCachePoolUtil.clear();
5 EhcachePortalCacheManager portalCacheManager = new EhcachePortalCacheManager();
6 portalCacheManager.clearAll();
All these ran before the line CounterLocalServiceUtil.increment(xXX.class.getName()); But none of them resolve the issue.

Jack Bakker:
Is the problem that user db crud might be taking place during the bulk db crud and that incurs conflicts ?
Good guess, but I tested them locally by doing it one at a time (first import a bunch of new records, then add a new record through the UI), and it still failed at the CounterLocalServiceUtil.increment saying that the ID already exists.
Thanks,
Brian
Firmi prego dentro per inbandierare questo come inadeguato.