掲示板

another problem with service builder in 6.2

9年前 に Piña Kanpokaldean によって更新されました。

another problem with service builder in 6.2

Junior Member 投稿: 79 参加年月日: 12/04/14 最新の投稿
Well, I'm porting my website from 6.1 to 6.2, and I started with the service builder. Mapping-key has been deprecated, so I take them all out. So far so good. Problem is, now my 1 to many relationships are no longer working. Checked the forums, and I basically had to turn most of them into many to many. So far so good.

However, some of them (such as the relation between project and incentive, code below) works simply by setting as a long with a mapping table, while others (like projects and rewards) will not build if I do it that way and required a full many to many relationship. Ok, it bugs me not to see the difference between both, but I can't afford to look too much into it so I move along to see what happens. It builds, I add the rest of the code, fix the getters so it works around the many to many, compile everything, smooth. For the record, if I try to do the type long with a mapping-table on the reward, I get the following exception:
serviceBuilder.getMappingEntities(column.mappingTable) as mapColumn [on line 280, column 41 in com/liferay/portal/tools/servicebuilder/dependencies/model_impl.ftl]


An then I start to test, and I get a exception when trying to fetch by primary key (as in, projectPersistence.getProjectLocations(project.getProjectId());). Debugging I find out it only happens if the query actually brings out results. The exception I get is
com.services.model.impl.ProjectLocationImpl cannot be cast to com.services.model.ProjectLocation

When I search for this in the forum, I find this. Apparently never fully ressolved, but it looks like my own issue. So I'll be trying to fix it through custom queries. The data is there on DB, so I should be able to retrieve it that way.

Still, it's a royal pain doing this for each case, the whole point of the Service Builder is not having to do that. So, if anyone could suggest me some other way, I'd much appreciate it. Thanks.

Attached a piece of my service XML, in case it helps.

<entity name="Project" local-service="true" remote-service="false" uuid="true">
		<column name="projectId" type="long" primary="true" />
		
		<column name="userId" type="long" />
		<column name="companyId" type="long" />
		
		<column name="name" type="String" />
		<column name="imageURL" type="String" />
		<column name="videoURL" type="String" />
		<column name="projectStatus" type="String" />
		<column name="createDate" type="Date" />
		<column name="confirmDate" type="Date" />
		<column name="liveDate" type="Date" />
		<column name="shortDescription" type="String" />
		<column name="whyMe" type="String" />
		<column name="longDescription" type="String" />
		<column name="totalDays" type="int" />
		<column name="type" type="String" />
		<column name="currency" type="String" />
		<column name="totalAmount" type="long" />
		<column name="author" type="String" />
		<column name="backerNumber" type="long" />
		<column name="believerNumber" type="long" />
		<column name="raisedAmount" type="long" />
		<column name="curator" type="String" />
		<column name="curatorId" type="long" />
		<column name="forumCategoryId" type="long" />
		<column name="paypalEmail" type="String" />
		<column name="termsAccepted" type="boolean" />
		
		<column name="backings" type="Collection" entity="Backing" mapping-table="project_backings" />
		<column name="requirements" type="Collection" entity="Requirement" mapping-table="project_requirement" />
		<column name="categories" type="Collection" entity="Category" mapping-table="project_categories" />
		<column name="founders" type="Collection" entity="UserProfile" mapping-table="founders" />
		<column name="countries" type="Collection" entity="ProjectLocation" mapping-table="project_location" />
		<column name="incentives" type="Collection" entity="Incentive" mapping-table="project_incentive" />
		<column name="rewards" type="Collection" entity="Reward" mapping-table="project_reward" />
		<column name="files" type="Collection" entity="StoredFile" />
		
		<!--Liferay asset fields -->
		<column name="status" type="int" />
		<column name="statusByUserId" type="long" />
		<column name="statusByUserName" type="String" />
		<column name="statusDate" type="Date" />
		<column name="groupId" type="long" />
		
		<finder return-type="Collection" name="Status">
			<finder-column name="projectStatus" />
		</finder>
		<finder return-type="Collection" name="User">
			<finder-column name="userId" />
			<finder-column name="projectStatus" />
		</finder>
		
	  <reference package-path="com.liferay.portlet.asset" entity="AssetEntry" />
	</entity>
<entity name="Incentive" local-service="true" remote-service="false">
		<column name="incentiveId" type="long" primary="true" />
		
		<column name="companyId" type="long" />
		<column name="projectId" type="long" mapping-table="project_incentive" />
    	<column name="requirementId" type="long" mapping-table="requirement_incentive" />
		
		<column name="threshold" type="long" />
		<column name="shortDescription" type="String" />
		<column name="longDescription" type="String" />
		<column name="rewardAmount" type="int" />
		
		<column name="incentiveRewardMapping" type="Collection" entity="IncentiveRewardMapping" />
		
		<column name="rewards" type="Collection" entity="Reward" mapping-table="incentive_rewards" />
		
		<order by="asc">
			<order-column name="threshold" />
		</order>
		<finder return-type="Collection" name="Requirement">
			<finder-column name="requirementId" />
		</finder>
	</entity>
	
	<entity name="Reward" local-service="true" remote-service="false">
		<column name="rewardId" type="long" primary="true" />
		
		<column name="companyId" type="long" />
		<column name="project" type="Collection" entity="Project" mapping-table="project_reward" />
		
		<column name="description" type="String" />
		<column name="totalAmount" type="long" />
		<column name="amountLeft" type="long" />
		<column name="type" type="String" />
		<column name="incentives" type="Collection" entity="Incentive" mapping-table="incentive_rewards" />
		<column name="incentiveRewardMapping" type="Collection" entity="IncentiveRewardMapping" />
	</entity>


UPDATE: As expected, the custom SQL works. Problem is I have to do it on several places now. Sigh.
thumbnail
9年前 に David H Nebinger によって更新されました。

RE: another problem with service builder in 6.2

Liferay Legend 投稿: 14917 参加年月日: 06/09/02 最新の投稿
one to many and many to many have never worked very well, and if you look at the generated source for the collection-based classes you'll see a lot of OperationNotSupportedExceptions.

I've long ago given up trying to model relations using SB and instead self-manage relations. PITA, certainly, but works across Liferay versions and is not susceptible to breakages w/ new releases.

As I stated in the link you found, ClassCastException is typically related to class loader issues. Do you have multiple versions of the service jar floating around or perhaps some compiled class in the classes folder which may be triggering this failure?

If you are using separate plugin wars, does the dependent plugin have the same service jar as the service-providing plugin?

Finally, did you try building the service within a hook plugin?
thumbnail
9年前 に Jack Bakker によって更新されました。

RE: another problem with service builder in 6.2

Liferay Master 投稿: 978 参加年月日: 10/01/03 最新の投稿
David H Nebinger:

I've long ago given up trying to model relations using SB and instead self-manage relations.

A good blog on self-manage of relations would be good. I started typing a long-winded "the way I do things in service builder" response here, but stopped as it got exponential and I got bored with myself. But yeah, service.xml is good for entities with finders to create the persistence classes, then after put one-to-etc. in generated Entity*ServiceImpl.java and then EntityImpl.java
thumbnail
9年前 に David H Nebinger によって更新されました。

RE: another problem with service builder in 6.2

Liferay Legend 投稿: 14917 参加年月日: 06/09/02 最新の投稿
Right, the goal of SB is to expose services to other plugins so you can implement a shared service tier across all of your plugins. It was never meant to be a full blown ORM and doesn't even try to implement it all.
9年前 に Piña Kanpokaldean によって更新されました。

RE: another problem with service builder in 6.2

Junior Member 投稿: 79 参加年月日: 12/04/14 最新の投稿
David H Nebinger:
one to many and many to many have never worked very well, and if you look at the generated source for the collection-based classes you'll see a lot of OperationNotSupportedExceptions.

I've long ago given up trying to model relations using SB and instead self-manage relations. PITA, certainly, but works across Liferay versions and is not susceptible to breakages w/ new releases.

As I stated in the link you found, ClassCastException is typically related to class loader issues. Do you have multiple versions of the service jar floating around or perhaps some compiled class in the classes folder which may be triggering this failure?

If you are using separate plugin wars, does the dependent plugin have the same service jar as the service-providing plugin?

Finally, did you try building the service within a hook plugin?


I know it's never worked too well, and I had to manually manage things like many2many with extra relationship fields. Still, it worked before, and above that, it was consistent. I find it puzzling that things work in one place and the same thing doesn't work right next to it. I know that in IT, that is completely impossible and it means I simply wasn't able to figure the difference out, but still. And maybe the latest changes improved backend, or performance, or whatever. Question is, was it worth the loss of functionality?

But I digress. To answer your questions, nope I don't have multiple versions of the jar. Not that I'm aware of at least, but I'm porting so it's a clean liferay install with only my portlet deployed; unless 6.2 itself does that without telling me it shouldn't be the case. So no, no different plugins. And I haven't tried buidling the services within a hook, and honestly I'll probably not try that this time. I will give it a spin next time though, I can see that coming handy. This time, so long as it at least inserts the data properly I'll just go with the custom SQLs.