Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
How to create composite primary key in Liferay6.1 using service builder Raghu k February 4, 2013 6:43 AM
RE: How to create composite primary key in Liferay6.1 using service builder David H Nebinger February 4, 2013 7:48 AM
RE: How to create composite primary key in Liferay6.1 using service builder Hitoshi Ozawa February 4, 2013 4:28 PM
RE: How to create composite primary key in Liferay6.1 using service builder Raghu k February 5, 2013 2:33 AM
RE: How to create composite primary key in Liferay6.1 using service builder MICHAIL MOUDATSOS February 5, 2013 3:16 AM
RE: How to create composite primary key in Liferay6.1 using service builder David H Nebinger February 5, 2013 5:32 AM
RE: How to create composite primary key in Liferay6.1 using service builder MICHAIL MOUDATSOS February 5, 2013 6:34 AM
RE: How to create composite primary key in Liferay6.1 using service builder Raghu k February 5, 2013 7:25 AM
RE: How to create composite primary key in Liferay6.1 using service builder Raghu k February 5, 2013 7:31 AM
RE: How to create composite primary key in Liferay6.1 using service builder Raghu k February 5, 2013 9:17 AM
RE: How to create composite primary key in Liferay6.1 using service builder MICHAIL MOUDATSOS February 5, 2013 11:45 PM
RE: How to create composite primary key in Liferay6.1 using service builder Raghu k February 6, 2013 12:53 AM
RE: How to create composite primary key in Liferay6.1 using service builder Raghu k February 7, 2013 6:47 AM
RE: How to create composite primary key in Liferay6.1 using service builder David H Nebinger February 5, 2013 10:23 AM
RE: How to create composite primary key in Liferay6.1 using service builder Raghu k February 5, 2013 11:36 PM
RE: How to create composite primary key in Liferay6.1 using service builder David H Nebinger February 5, 2013 5:28 AM
Raghu k
How to create composite primary key in Liferay6.1 using service builder
February 4, 2013 6:43 AM
Answer

Raghu k

Rank: Junior Member

Posts: 58

Join Date: August 10, 2012

Recent Posts

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
February 4, 2013 7:48 AM
Answer

David H Nebinger

Rank: Liferay Legend

Posts: 6704

Join Date: September 1, 2006

Recent Posts

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
February 4, 2013 4:28 PM
Answer

Hitoshi Ozawa

Rank: Liferay Legend

Posts: 7990

Join Date: March 23, 2010

Recent Posts

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
February 5, 2013 2:33 AM
Answer

Raghu k

Rank: Junior Member

Posts: 58

Join Date: August 10, 2012

Recent Posts

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
February 5, 2013 3:16 AM
Answer

MICHAIL MOUDATSOS

Rank: Regular Member

Posts: 110

Join Date: October 4, 2011

Recent Posts

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
February 5, 2013 5:28 AM
Answer

David H Nebinger

Rank: Liferay Legend

Posts: 6704

Join Date: September 1, 2006

Recent Posts

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
February 5, 2013 5:32 AM
Answer

David H Nebinger

Rank: Liferay Legend

Posts: 6704

Join Date: September 1, 2006

Recent Posts

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
February 5, 2013 6:34 AM
Answer

MICHAIL MOUDATSOS

Rank: Regular Member

Posts: 110

Join Date: October 4, 2011

Recent Posts

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
February 5, 2013 7:25 AM
Answer

Raghu k

Rank: Junior Member

Posts: 58

Join Date: August 10, 2012

Recent Posts

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
February 5, 2013 7:31 AM
Answer

Raghu k

Rank: Junior Member

Posts: 58

Join Date: August 10, 2012

Recent Posts

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
February 5, 2013 9:17 AM
Answer

Raghu k

Rank: Junior Member

Posts: 58

Join Date: August 10, 2012

Recent Posts

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
February 5, 2013 10:23 AM
Answer

David H Nebinger

Rank: Liferay Legend

Posts: 6704

Join Date: September 1, 2006

Recent Posts

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
February 5, 2013 11:36 PM
Answer

Raghu k

Rank: Junior Member

Posts: 58

Join Date: August 10, 2012

Recent Posts

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
February 5, 2013 11:45 PM
Answer

MICHAIL MOUDATSOS

Rank: Regular Member

Posts: 110

Join Date: October 4, 2011

Recent Posts

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
February 6, 2013 12:53 AM
Answer

Raghu k

Rank: Junior Member

Posts: 58

Join Date: August 10, 2012

Recent Posts

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
February 7, 2013 6:47 AM
Answer

Raghu k

Rank: Junior Member

Posts: 58

Join Date: August 10, 2012

Recent Posts

David / Hitoshi / Michail,
Thanks for your reply. It is working fine now. Problem is with Eclipse. It is working after removing static.