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: Service builder: Implementing Trash when primary key string
I'm trying to enable trash feature on my entity as below
When I run service builder, it generates code which is not compilable and has errors. For example,
The problem is getContainerModelClassName expect 'long classPK' where is 'getPrimaryKey' return String because entity primary key is String not long. Similar below.
I'm having the same issue for another entity who primary key is composite.
for this one getPrimaryKey return's PositionSupportPK but getTrashEntryClassPK (as above) expects long
How to enable trash on entities with primary String or composite but not long?
<entity local-service="true" name="Position" remote-service="false" uuid="true" t[b]rash-enabled="true" [ b]>
<!-- PK fields -->
<column name="positionId" primary="true" type="String" />[/
....
..
</entity>
When I run service builder, it generates code which is not compilable and has errors. For example,
com.liferay.portal.kernel.trash.TrashHandler trashHandler = getTrashHandler();
if (!Validator.isNull([b]trashHandler.getContainerModelClassName(
getPrimaryKey())[/b])) {
ContainerModel containerModel = null;
The problem is getContainerModelClassName expect 'long classPK' where is 'getPrimaryKey' return String because entity primary key is String not long. Similar below.
@Override
public long getTrashEntryClassPK() {
return getPrimaryKey();
}
I'm having the same issue for another entity who primary key is composite.
<entity name="PositionSupport" remote-service="false" local-service="true" trash-enabled="true">
<!-- PK fields -->
<column name="SupportedBy" primary="true" type="string" />
<column name="positionId" primary="true" type="string"></column></entity>
for this one getPrimaryKey return's PositionSupportPK but getTrashEntryClassPK (as above) expects long
@Override
public PositionSupportPK getPrimaryKey() {
return new PositionSupportPK(_SupportedBy, _positionId);
}
How to enable trash on entities with primary String or composite but not long?
Below you can see the build errors which may help to understand the problem details
:modules:directory-core:directory-core-service:compileJavaD:\Development\ABC\xyz\Source\test\testWS\modules\directory-core\directory-core-service\src\main\java\com\xyz\test\directory\model\impl\PositionModelImpl.java:845: error: incompatible types: String cannot be converted to long
getPrimaryKey()))) {
^
D:\Development\ABC\xyz\Source\test\testWS\modules\directory-core\directory-core-service\src\main\java\com\xyz\test\directory\model\impl\PositionModelImpl.java:878: error: incompatible types: String cannot be converted to long
return getPrimaryKey();
^
D:\Development\ABC\xyz\Source\test\testWS\modules\directory-core\directory-core-service\src\main\java\com\xyz\test\directory\model\impl\PositionModelImpl.java:906: error: incompatible types: String cannot be converted to long
getPrimaryKey()))) {
^
D:\Development\ABC\xyz\Source\test\testWS\modules\directory-core\directory-core-service\src\main\java\com\xyz\test\directory\model\impl\PositionManagerModelImpl.java:222: error: incompatible types: PositionManagerPK cannot be converted to long
getPrimaryKey()))) {
^
D:\Development\ABC\xyz\Source\test\testWS\modules\directory-core\directory-core-service\src\main\java\com\xyz\test\directory\model\impl\PositionManagerModelImpl.java:255: error: incompatible types: PositionManagerPK cannot be converted to long
return getPrimaryKey();
^
D:\Development\ABC\xyz\Source\test\testWS\modules\directory-core\directory-core-service\src\main\java\com\xyz\test\directory\model\impl\PositionManagerModelImpl.java:283: error: incompatible types: PositionManagerPK cannot be converted to long
getPrimaryKey()))) {
^
D:\Development\ABC\xyz\Source\test\testWS\modules\directory-core\directory-core-service\src\main\java\com\xyz\test\directory\model\impl\PositionSupportModelImpl.java:222: error: incompatible types: PositionSupportPK cannot be converted to long
getPrimaryKey()))) {
^
D:\Development\ABC\xyz\Source\test\testWS\modules\directory-core\directory-core-service\src\main\java\com\xyz\test\directory\model\impl\PositionSupportModelImpl.java:255: error: incompatible types: PositionSupportPK cannot be converted to long
return getPrimaryKey();
^
D:\Development\ABC\xyz\Source\test\testWS\modules\directory-core\directory-core-service\src\main\java\com\xyz\test\directory\model\impl\PositionSupportModelImpl.java:283: error: incompatible types: PositionSupportPK cannot be converted to long
getPrimaryKey()))) {
^
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Note: Some messages have been simplified; recompile with -Xdiags:verbose to get full output
9 errors
FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':modules:directory-core:directory-core-service:compileJava'.
> Compilation failed; see the compiler error output for details.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 8.003 secs
Hi,
Got your point.Which version of lIferay you are using?
Did you check after clearing generated classes and build service builder again.
Regards
Got your point.Which version of lIferay you are using?
Did you check after clearing generated classes and build service builder again.
Regards
Liferay 7 - Yes I tried clearing generated classes as well
Adnan Yaqoob:How to enable trash on entities with primary String or composite but not long?
Unfortunately, this isn't possible. The TrashEntry
table's classPK
column is defined as a long.
Copyright © 2025 Liferay, Inc
• Privacy Policy
Powered by Liferay™