RE: Service builder: Implementing Trash when primary key string

thumbnail
Adnan Yaqoob, modified 7 Years ago. Junior Member Posts: 36 Join Date: 3/24/14 Recent Posts
I'm trying to enable trash feature on my entity as below
<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?
thumbnail
Adnan Yaqoob, modified 7 Years ago. Junior Member Posts: 36 Join Date: 3/24/14 Recent Posts
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'.
&gt; 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
thumbnail
Sushil Patidar, modified 7 Years ago. Expert Posts: 467 Join Date: 10/31/11 Recent Posts
Hi,

Got your point.Which version of lIferay you are using?
Did you check after clearing generated classes and build service builder again.

Regards
thumbnail
Adnan Yaqoob, modified 7 Years ago. Junior Member Posts: 36 Join Date: 3/24/14 Recent Posts

Liferay 7 - Yes I tried clearing generated classes as well

thumbnail
Minhchau Dang, modified 7 Years ago. Liferay Master Posts: 598 Join Date: 10/22/07 Recent Posts
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.