留言板
custom service getXXXXCount() doesn't update after inserting new entry
Jianbin LIN,修改在12 年前。
custom service getXXXXCount() doesn't update after inserting new entry
New Member 帖子: 10 加入日期: 11-12-24 最近的帖子
Hello everyone,
environment:
OS: Mac OSX 10.6.8
java version "1.6.0_29"
LIFERAY: 6.1 RC 1
I create a custom service with Liferay service builder in a portlet.
Also, I added a custom method as follows.
And access it with another portlet.
However, each time I run the code above, I got exactly the same number of ems.
Actually, these entries have been added into the table because after I restart tomcat, I will get the right count.
So just the EntityMappingLocalServiceUtil.getEntityMappingsCount() doesn't report the right number.
I guessed it's the problem of caching.
And changed the portlet.xml of the custom service and added
But it doesn't help.
Anyone has got any idea?
Thank you.
environment:
OS: Mac OSX 10.6.8
java version "1.6.0_29"
LIFERAY: 6.1 RC 1
I create a custom service with Liferay service builder in a portlet.
<service-builder package-path="com.test.mapping">
<namespace>Mapping</namespace>
<entity name="EntityMapping" local-service="true" remote-service="true">
<!-- PK fields -->
<column name="id" type="long" primary="true" />
<!-- Group instance -->
<!-- Audit fields -->
<column name="type" type="String" />
<column name="entity1" type="String" />
<column name="entity2" type="String" />
<!-- Other fields -->
</entity>
</service-builder>
Also, I added a custom method as follows.
public class EntityMappingLocalServiceImpl
extends EntityMappingLocalServiceBaseImpl {
public EntityMapping addEntityMapping(String type, String entity1,
String entity2) throws PortalException, SystemException {
long id = counterLocalService.increment();
EntityMapping em = entityMappingPersistence.create(id);
em.setType(type);
em.setEntity1(entity1);
em.setEntity2(entity2);
entityMappingPersistence.update(em, false);
return em;
}
}
And access it with another portlet.
System.out.println("There are " + EntityMappingLocalServiceUtil.getEntityMappingsCount() + " ems");
EntityMappingLocalServiceUtil.addEntityMapping("type2", "azbc", "csde");
System.out.println("There are " + EntityMappingLocalServiceUtil.getEntityMappingsCount() + " ems");
However, each time I run the code above, I got exactly the same number of ems.
Actually, these entries have been added into the table because after I restart tomcat, I will get the right count.
So just the EntityMappingLocalServiceUtil.getEntityMappingsCount() doesn't report the right number.
I guessed it's the problem of caching.
And changed the portlet.xml of the custom service and added
<expiration-cache>5</expiration-cache>
But it doesn't help.
Anyone has got any idea?
Thank you.
Jianbin LIN,修改在12 年前。
RE: custom service getXXXXCount() doesn't update after inserting new entry
New Member 帖子: 10 加入日期: 11-12-24 最近的帖子
Anyone has a clue?
Hitoshi Ozawa,修改在12 年前。
RE: custom service getXXXXCount() doesn't update after inserting new entry
Liferay Legend 帖子: 7942 加入日期: 10-3-24 最近的帖子
Have you updated your index after inserting?
Jianbin LIN,修改在12 年前。
RE: custom service getXXXXCount() doesn't update after inserting new entry
New Member 帖子: 10 加入日期: 11-12-24 最近的帖子Hitoshi Ozawa:
Have you updated your index after inserting?
I've tried indexing it. But it reported NullPointerException, it seems there is no proper indexer for this custom service class. How can I configure an indexer for it?
final Indexer indexer = IndexerRegistryUtil.getIndexer(EntityMapping.class);
indexer.reindex(em);
Sandeep Nair,修改在12 年前。
RE: custom service getXXXXCount() doesn't update after inserting new entry
Liferay Legend 帖子: 1744 加入日期: 08-11-6 最近的帖子
Not an indexing issue. It should work first
In your code i see EntityMappingLocalServiceUtil.addEntityMapping("type2", "azbc", "csde");
what is type2, azbc csde
Basically the default method that liferay provides once u run servicebuilder is
EntityMappingLocalServiceUtil.addEntityMapping(entityMapping);
Regards,
Sandeep
In your code i see EntityMappingLocalServiceUtil.addEntityMapping("type2", "azbc", "csde");
what is type2, azbc csde
Basically the default method that liferay provides once u run servicebuilder is
EntityMappingLocalServiceUtil.addEntityMapping(entityMapping);
Regards,
Sandeep
Jianbin LIN,修改在12 年前。
RE: custom service getXXXXCount() doesn't update after inserting new entry
New Member 帖子: 10 加入日期: 11-12-24 最近的帖子Sandeep Nair:
Not an indexing issue. It should work first
In your code i see EntityMappingLocalServiceUtil.addEntityMapping("type2", "azbc", "csde");
what is type2, azbc csde
Basically the default method that liferay provides once u run servicebuilder is
EntityMappingLocalServiceUtil.addEntityMapping(entityMapping);
Regards,
Sandeep
Actually, that is a custom method as follows.
public class EntityMappingLocalServiceImpl
extends EntityMappingLocalServiceBaseImpl {
public EntityMapping addEntityMapping(String type, String entity1,
String entity2) throws PortalException, SystemException {
long id = counterLocalService.increment();
EntityMapping em = entityMappingPersistence.create(id);
em.setType(type);
em.setEntity1(entity1);
em.setEntity2(entity2);
entityMappingPersistence.update(em, false);
return em;
}
}
Sandeep Nair,修改在12 年前。
RE: custom service getXXXXCount() doesn't update after inserting new entry
Liferay Legend 帖子: 1744 加入日期: 08-11-6 最近的帖子
Then in that case you are doing nothing wrong my friend. Can you please try the code in stable version of Liferay (6.0.6) to just check if this is not a bug in Liferay 6.1 RC1 release.
Regards,
Sandeep
Regards,
Sandeep
Jianbin LIN,修改在12 年前。
RE: custom service getXXXXCount() doesn't update after inserting new entry
New Member 帖子: 10 加入日期: 11-12-24 最近的帖子Sandeep Nair:
Then in that case you are doing nothing wrong my friend. Can you please try the code in stable version of Liferay (6.0.6) to just check if this is not a bug in Liferay 6.1 RC1 release.
Regards,
Sandeep
Thank you for you reply.
In fact, in the version(6.0.6), I failed to get one portlet access the service provided by another portlet. So I moved to version 6.1.
cheers,
Jianbin
Sandeep Nair,修改在12 年前。
RE: custom service getXXXXCount() doesn't update after inserting new entry
Liferay Legend 帖子: 1744 加入日期: 08-11-6 最近的帖子
So you mean to say the above code worked perfectly fine in 6.0.6 right?