Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
RE: LocalServiceUtil.getCount return a old value after insert a new record?
Hi all,
I have a problem. When i change database such as insert
a new record then LocalService still get a old version of database.
For example:
Table A have 10 records. I add 2 new records and use LocalServiceUtil.getCount in portlet then i still get 10 result.
What 's happening?
P/S: I added by handle in msql workbench.
Please help me.
Thanks for reading
Tinhnx
Can you please confirm if you have manually inserted record in database? If yes, try Clear Database Cache option under server administration.
How did you add the 2 records? Did you add it manually or did you use LocalServiceUtil to add. If you're not using LocalServiceUtil to add, there's no way for the portal to know that it needs to update it's cache.
Hi Samuel Kong and Ravi Shah,
I did insert new by LocalServiceUtil.update...
Is that your custom entity?
Absolutely, I added successfully to database and show it on searchContainer. But in another jsp file, i used LocalServiceUtil.getCount then it still return a old result (Here: 10 records).
I'm reading several conflicting statements here.
The others are right, pointing to Liferay's cache: When you manually insert records into the database, you can't expect Liferay's caches to be current and will need to invalidate them yourself. Or better: Don't write to the database manually.
In case there's something wrong with your code, please share your LocalServiceImpl code for the method that inserts into the database, and the code that calls this in order to insert.
If you're on Liferay 7, you should just use a @Reference to the service (interface) instead of the LocalServiceUtil. (this wouldn't change much in your case, but while we're at it, this could be changed as well)
Actually, I'm trying with a CRUD database example . I'll check my
code again then try create a new project.
I'll back when i done.
Anyway thanks for responding.
Finally, i found reason when i using update() of localServiceUtil it will not change cache . I must using add() and everything work perfectly.
I think different thing at model.setNew(true) in add().
Powered by Liferay™