フォーラム

ホーム » Liferay Portal » English » 6. Portal Framework

構造的に表示 平面上に表示 ツリー上に表示
スレッド [ 前へ | 次へ ]
toggle
Mike Wirth
ServiceBuilder one-to-many realationship
2012/10/15 23:26
答え

Mike Wirth

ランク: New Member

投稿: 3

参加年月日: 2012/08/02

最近の投稿

Hi,

I struggle with the ServiceBuilder with the Liferay SDK 6.1.1.

After a few weeks working with the ServiceBuilder I wonder what is the strategy? ServiceBuilder is using Hibernate underneath, but why is it then building it's own implementations and creating it's own models, utils and persistency layer? Why does Liferay invent the wheel again?

The documentation of the ServiceBuilder is very little, almost inexistent. There are a few docs and tutorials, but none of them is for any better use that a simple select statement. On the web I found many questions to the ServiceBuilder relationship mapping, but without any solution.

I try to implement a simple one-to-many relationship to the SAME entity. There is no example or documentation about how to do this. I mean this is pretty standard of every ORM framework and I think this is not a very exotic requirement, or is it? If ServiceBuilder depends on Hibernate or JPA why isn't it using that feature, why does LIferay it's own implementation?

I tried to make a simple example, but it can't build the service without error and the expected Foo.getChildren() method is missing.

Thanks,
Michael




 1<?xml version="1.0" encoding="UTF-8"?>
 2<!DOCTYPE service-builder PUBLIC "-//Liferay//DTD Service Builder 6.1.0//EN" "http://www.liferay.com/dtd/liferay-service-builder_6_1_0.dtd">
 3<service-builder package-path="com.liferay.test">
 4  <author>author</author>
 5  <namespace>test</namespace>
 6
 7  <entity name="Foo" local-service="true" remote-service="true">
 8
 9    <!-- PK fields -->
10
11    <column name="fooId" type="long" primary="true" />
12
13    <!-- Audit fields -->
14
15    <!-- Other fields -->
16        <column name="children" type="Collection" entity="Foo" mapping-key="parentId"></column>
17        <column name="parentId" type="long"></column>
18
19    <!-- Finder methods -->
20  </entity>
21</service-builder>
MICHAIL MOUDATSOS
RE: ServiceBuilder one-to-many realationship
2013/02/05 2:04
答え

MICHAIL MOUDATSOS

ランク: Regular Member

投稿: 110

参加年月日: 2011/10/04

最近の投稿

Could anyone reply on this please? Can we or can we not, define a 'one to many' or 'many to many' relationship between an entity and itself?

Thank you in advance
David H Nebinger
RE: ServiceBuilder one-to-many realationship
2013/02/05 5:54
答え

David H Nebinger

ランク: Liferay Legend

投稿: 7217

参加年月日: 2006/09/01

最近の投稿

Many to many relationships have not been supported by Liferay.

One to many relationships are supposed to be supported, but it doesn't translate very well.

Your best bet to handle these relationships is to do so on your own.

For example, to solve the OP's issue I'd add a finder method to return a collection using the parentId as the argument. That will create the method in the persistance layer, which must be exposed in the XxxLocalServiceImpl class to make it available to outside callers.

Many to many is doable in the same fashion, just a little more work.

Remember that SB is not intended to be a full ORM stack; it is meant to solve a specific problem (how does one expose DAOs in a portal environment that can be accessed across the web app class loader boundary).