フォーラム

ホーム » Liferay Portal » English » 3. Development

構造的に表示 平面上に表示 ツリー上に表示
スレッド [ 前へ | 次へ ]
toggle
How to create composite primary key in Liferay6.1 using service builder Raghu k 2013/02/04 6:43
RE: How to create composite primary key in Liferay6.1 using service builder David H Nebinger 2013/02/04 7:48
RE: How to create composite primary key in Liferay6.1 using service builder Madasamy P 2017/02/15 3:53
RE: How to create composite primary key in Liferay6.1 using service builder David H Nebinger 2017/02/15 4:27
RE: How to create composite primary key in Liferay6.1 using service builder Madasamy P 2017/02/19 23:14
RE: How to create composite primary key in Liferay6.1 using service builder Hitoshi Ozawa 2013/02/04 16:28
RE: How to create composite primary key in Liferay6.1 using service builder Raghu k 2013/02/05 2:33
RE: How to create composite primary key in Liferay6.1 using service builder MICHAIL MOUDATSOS 2013/02/05 3:16
RE: How to create composite primary key in Liferay6.1 using service builder David H Nebinger 2013/02/05 5:32
RE: How to create composite primary key in Liferay6.1 using service builder MICHAIL MOUDATSOS 2013/02/05 6:34
RE: How to create composite primary key in Liferay6.1 using service builder Raghu k 2013/02/05 7:25
RE: How to create composite primary key in Liferay6.1 using service builder Raghu k 2013/02/05 7:31
RE: How to create composite primary key in Liferay6.1 using service builder Raghu k 2013/02/05 9:17
RE: How to create composite primary key in Liferay6.1 using service builder MICHAIL MOUDATSOS 2013/02/05 23:45
RE: How to create composite primary key in Liferay6.1 using service builder Raghu k 2013/02/06 0:53
RE: How to create composite primary key in Liferay6.1 using service builder Raghu k 2013/02/07 6:47
RE: How to create composite primary key in Liferay6.1 using service builder David H Nebinger 2013/02/05 10:23
RE: How to create composite primary key in Liferay6.1 using service builder Raghu k 2013/02/05 23:36
RE: How to create composite primary key in Liferay6.1 using service builder David H Nebinger 2013/02/05 5:28
Raghu k
How to create composite primary key in Liferay6.1 using service builder
2013/02/04 6:43
答え

Raghu k

ランク: Junior Member

投稿: 58

参加年月日: 2012/08/10

最近の投稿

Hi,
I want to create a table whose primary key is a combination of below fields.
GROUPID, COMPANYID, USERID, FILEENTRYID
How can i create or define a composite primary key using service builder? When i checked in Liferay forum for this issue, i dint find any replies for it. Instead this bug is closed due to inactivity. Below is the link i checked.
http://issues.liferay.com/browse/LPS-4383
Is there any alternatives to do CRUD operations apart from service builder?
Can anyone help me here please.
David H Nebinger
RE: How to create composite primary key in Liferay6.1 using service builder
2013/02/04 7:48
答え

David H Nebinger

Community Moderator

ランク: Liferay Legend

投稿: 12525

参加年月日: 2006/09/01

最近の投稿

Just add the columns to the SB entity and decorate them all with "primary='true'". The composite key will be created and can be used by your code.
Hitoshi Ozawa
RE: How to create composite primary key in Liferay6.1 using service builder
2013/02/04 16:28
答え

Hitoshi Ozawa

ランク: Liferay Legend

投稿: 7949

参加年月日: 2010/03/23

最近の投稿

http://issues.liferay.com/browse/LPS-4383


That's an old thread and as the comment in the issues states, it was probably just a request for assistance instead of a bug report.
Raghu k
RE: How to create composite primary key in Liferay6.1 using service builder
2013/02/05 2:33
答え

Raghu k

ランク: Junior Member

投稿: 58

参加年月日: 2012/08/10

最近の投稿

David and Hitoshi,
Thanks for your reply.
I have one more doubt.
Can we have 2 packages in a single service.xml? So that I can move classes generated by Service builder into respective package.
MICHAIL MOUDATSOS
RE: How to create composite primary key in Liferay6.1 using service builder
2013/02/05 3:16
答え

MICHAIL MOUDATSOS

ランク: Regular Member

投稿: 110

参加年月日: 2011/10/04

最近の投稿

However this doesn't work:

 1    <entity name="FirstEntity" local-service="false" remote-service="false">
 2        <column name="firstEntityId" type="int" primary="true"/>
 3        <!-- ... -->
 4    </entity>
 5
 6    <entity name="SecondEntity" local-service="false" remote-service="false">
 7        <column name="secondEntityId" type="int" primary="true"/>
 8        <!-- ...-->
 9        <column name="values" type="Collection" entity="ValueEntity" mapping-key="secondEntityId"/>
10    </entity>
11
12    <entity name="ValueEntity" local-service="false" remote-service="false">
13        <column name="firstEntityId" type="int" primary="true"/>
14        <column name="secondEntityId" type="int" primary="true"/>
15        <column name="value" type="String"/>
16    </entity>
Is it a bug (that I should - therefore - report) or is it supposed to behave this way?

EDIT: To avoid any confusion, it doesnt matter if we change firstEntityId to another name, in ValueEntity definition. It just happens to be my case, that's why I used FirstEntity's primary key name
David H Nebinger
RE: How to create composite primary key in Liferay6.1 using service builder
2013/02/05 5:28
答え

David H Nebinger

Community Moderator

ランク: Liferay Legend

投稿: 12525

参加年月日: 2006/09/01

最近の投稿

Raghu k:
Can we have 2 packages in a single service.xml? So that I can move classes generated by Service builder into respective package.


No. Service builder uses the one package defined in service.xml for the base package of all classes. If you want a different package, you need a second plugin to host the second service.xml file.
David H Nebinger
RE: How to create composite primary key in Liferay6.1 using service builder
2013/02/05 5:32
答え

David H Nebinger

Community Moderator

ランク: Liferay Legend

投稿: 12525

参加年月日: 2006/09/01

最近の投稿

MICHAIL MOUDATSOS:
However this doesn't work:

1        <column name="values" type="Collection" entity="ValueEntity" mapping-key="secondEntityId"/>



Of course it doesn't work. ValueEntity has a composite key, but you're trying to do a mapping using only one key from the primary key of ValueEntity.

Basically you're trying to manually implement a many to many relationship between the first entity and the second entity, which is just not going to work.

You should drop the collection from the second entity, add finders to the ValueEntity to find all records based on getting either the first key or the second key, and manually maintain the ValueEntity listings.
MICHAIL MOUDATSOS
RE: How to create composite primary key in Liferay6.1 using service builder
2013/02/05 6:34
答え

MICHAIL MOUDATSOS

ランク: Regular Member

投稿: 110

参加年月日: 2011/10/04

最近の投稿

David H Nebinger:
Of course it doesn't work. ValueEntity has a composite key, but you're trying to do a mapping using only one key from the primary key of ValueEntity.
You 're so right! I almost forgot the most simple thing: I am doing an Entity Mapping! (as opposed to some db-wise parameterization) Thanks for the reply!
Raghu k
RE: How to create composite primary key in Liferay6.1 using service builder
2013/02/05 7:25
答え

Raghu k

ランク: Junior Member

投稿: 58

参加年月日: 2012/08/10

最近の投稿

I was able to build service.xml which had composite primaty without any issues. When did build, this generated required classes. But my service.xml also had finder methods.

When I checked my util class, i didn't find any method related to my finder methods. Am i missing anythong? Below is entity from my services.xml

<entity name="Favorites" local-service="true" remote-service="false" table="FAVORITE_DOCUMENTS">
<!-- PK fields -->
<column name="GROUPID" type="long" primary="true"></column>
<column name="COMPANYID" type="long" primary="true"></column>
<column name="USERID" type="long" primary="true"></column>
<column name="FILEENTRYID" type="long" primary="true"></column>
<!-- UI fields -->

<column name="CREATEDATE" type="Date"></column>

<finder name="GroupId" return-type="Collection">
<finder-column name="GROUPID" />
</finder>
<finder name="CompanyId" return-type="Collection">
<finder-column name="COMPANYID" />
</finder>
<finder name="UserId" return-type="Collection">
<finder-column name="USERID" />
</finder>
<finder name="singleFileOfUser" return-type="Collection">
<finder-column name="USERID" />
<finder-column name="GROUPID" />
<finder-column name="COMPANYID" />
<finder-column name="FILEENTRYID" />
</finder>
<finder name="allFilesForUGC" return-type="Collection">
<finder-column name="USERID" />
<finder-column name="GROUPID" />
<finder-column name="COMPANYID" />
</finder>

</entity>
Raghu k
RE: How to create composite primary key in Liferay6.1 using service builder
2013/02/05 7:31
答え

Raghu k

ランク: Junior Member

投稿: 58

参加年月日: 2012/08/10

最近の投稿

There are 2 util classes.
1.FavoritesUtil - which is in persistence package. This has my finder methods
2.FavoritesLocalServiceUtil - which is in service package. This has basic method not finder methods.

Which Util I should use in my class to perform required CRUD operation?
Raghu k
RE: How to create composite primary key in Liferay6.1 using service builder
2013/02/05 9:17
答え

Raghu k

ランク: Junior Member

投稿: 58

参加年月日: 2012/08/10

最近の投稿

I have taken below link as reference and did changes to FavoritesLocalServiceImpl by adding few methods which will intern call methods in FavoritesUtil. And then i build services.xml. But methods which i added in FavoritesLocalServiceImpl did not reflect in FavoritesLocalServiceUtil.
Can some one help me here please.
Link i referred:
http://www.liferay.com/community/forums/-/message_boards/message/4774829

Below is the code in FavoritesUtil
public static java.util.List<com.getransportation.cwc.webleads.model.Favorites> findByUserId(
long USERID) throws com.liferay.portal.kernel.exception.SystemException {
return getPersistence().findByUserId(USERID);
}

Below is the code from FavoritesLocalServiceImpl

public static List<Favorites> findByUserId(
long USERID)
throws SystemException {
return FavoritesUtil.findByUserId(USERID);
}
David H Nebinger
RE: How to create composite primary key in Liferay6.1 using service builder
2013/02/05 10:23
答え

David H Nebinger

Community Moderator

ランク: Liferay Legend

投稿: 12525

参加年月日: 2006/09/01

最近の投稿

Raghu k:
When I checked my util class, i didn't find any method related to my finder methods. Am i missing anythong?


Finders are only generated in the persistence layer. To expose them in the util class, you need to add them to the XxxLocalServiceImpl class and re-run service builder.

Kind of a pain, but I think the view is that the finder is to be used within the XxxLocalServiceImpl class and not normally exported. Think of your XxxLocalServiceImpl class as an implementation of business logic, and not just a facade over the persistence layer.

That's actually a good approach to take in most cases, because you don't want to have to replicate business logic in all of the portlets consuming the service.
Raghu k
RE: How to create composite primary key in Liferay6.1 using service builder
2013/02/05 23:36
答え

Raghu k

ランク: Junior Member

投稿: 58

参加年月日: 2012/08/10

最近の投稿

David H Nebinger:

Finders are only generated in the persistence layer. To expose them in the util class, you need to add them to the XxxLocalServiceImpl class and re-run service builder.
.

I added my method in my LocalServiceImpl class and did build as well. This build was successful. But my method in XxxLocalServiceImpl class was not available in my XxxLocalServiceUtil class.
My XxxLocalServiceImpl class with custom method is available in my earlier post.
MICHAIL MOUDATSOS
RE: How to create composite primary key in Liferay6.1 using service builder
2013/02/05 23:45
答え

MICHAIL MOUDATSOS

ランク: Regular Member

投稿: 110

参加年月日: 2011/10/04

最近の投稿

Raghu k:

Below is the code from FavoritesLocalServiceImpl

1public static List<Favorites> findByUserId(
2            long USERID)
3            throws SystemException {
4            return FavoritesUtil.findByUserId(USERID);
5}
I think the error is that you define the method as static. To the best of my knowledge, you shouldn't do that. Remove the 'static' keyword, rebuild and check what happens
Raghu k
RE: How to create composite primary key in Liferay6.1 using service builder
2013/02/06 0:53
答え

Raghu k

ランク: Junior Member

投稿: 58

参加年月日: 2012/08/10

最近の投稿

MICHAIL MOUDATSOS:
I think the error is that you define the method as static. To the best of my knowledge, you shouldn't do that. Remove the 'static' keyword, rebuild and check what happens

I tried by removing static as well. Still no luck.
Raghu k
RE: How to create composite primary key in Liferay6.1 using service builder
2013/02/07 6:47
答え

Raghu k

ランク: Junior Member

投稿: 58

参加年月日: 2012/08/10

最近の投稿

David / Hitoshi / Michail,
Thanks for your reply. It is working fine now. Problem is with Eclipse. It is working after removing static.
Madasamy P
RE: How to create composite primary key in Liferay6.1 using service builder
2017/02/15 3:53
答え

Madasamy P

ランク: Junior Member

投稿: 82

参加年月日: 2016/07/27

最近の投稿

David H Nebinger:
Just add the columns to the SB entity and decorate them all with "primary='true'". The composite key will be created and can be used by your code.



I have two fields as,

<entity name="History" local-service="true" remote-service="true" uuid="true">
<!-- PK fields -->
<column name="historyId" type="long" primary="true"></column>
<column name="bookId" type="long" primary="true"></column>
<!-- UI fields -->
<column name="bookTitle" type="String"></column>
<column name="formName" type="String"></column>
<column name="fieldName" type="String"></column>
<column name="fieldValue" type="String"></column>
</entity>

After building the service, I want to find an entry by using historyId and bookId (composite key) as programmatically
How could to solve this
David H Nebinger
RE: How to create composite primary key in Liferay6.1 using service builder
2017/02/15 4:27
答え

David H Nebinger

Community Moderator

ランク: Liferay Legend

投稿: 12525

参加年月日: 2006/09/01

最近の投稿

Did you check the generated code? You should see getHistory() and fetchHistory() methods which take a composite key object as the argument.
Madasamy P
RE: How to create composite primary key in Liferay6.1 using service builder
2017/02/19 23:14
答え

Madasamy P

ランク: Junior Member

投稿: 82

参加年月日: 2016/07/27

最近の投稿

Thank you David
I checked and found the solution