Tribune

Home » Liferay Portal » English » 3. Development

Vista Combinata Vista Piatta Vista ad Albero
Discussioni [ Precedente | Successivo ]
toggle
How to create composite primary key in Liferay6.1 using service builder Raghu k 4 febbraio 2013 6.43
RE: How to create composite primary key in Liferay6.1 using service builder David H Nebinger 4 febbraio 2013 7.48
RE: How to create composite primary key in Liferay6.1 using service builder Hitoshi Ozawa 4 febbraio 2013 16.28
RE: How to create composite primary key in Liferay6.1 using service builder Raghu k 5 febbraio 2013 2.33
RE: How to create composite primary key in Liferay6.1 using service builder MICHAIL MOUDATSOS 5 febbraio 2013 3.16
RE: How to create composite primary key in Liferay6.1 using service builder David H Nebinger 5 febbraio 2013 5.32
RE: How to create composite primary key in Liferay6.1 using service builder MICHAIL MOUDATSOS 5 febbraio 2013 6.34
RE: How to create composite primary key in Liferay6.1 using service builder Raghu k 5 febbraio 2013 7.25
RE: How to create composite primary key in Liferay6.1 using service builder Raghu k 5 febbraio 2013 7.31
RE: How to create composite primary key in Liferay6.1 using service builder Raghu k 5 febbraio 2013 9.17
RE: How to create composite primary key in Liferay6.1 using service builder MICHAIL MOUDATSOS 5 febbraio 2013 23.45
RE: How to create composite primary key in Liferay6.1 using service builder Raghu k 6 febbraio 2013 0.53
RE: How to create composite primary key in Liferay6.1 using service builder Raghu k 7 febbraio 2013 6.47
RE: How to create composite primary key in Liferay6.1 using service builder David H Nebinger 5 febbraio 2013 10.23
RE: How to create composite primary key in Liferay6.1 using service builder Raghu k 5 febbraio 2013 23.36
RE: How to create composite primary key in Liferay6.1 using service builder David H Nebinger 5 febbraio 2013 5.28
Raghu k
How to create composite primary key in Liferay6.1 using service builder
4 febbraio 2013 6.43
Risposta

Raghu k

Punteggio: Junior Member

Messaggi: 58

Data di Iscrizione: 10 agosto 2012

Messaggi recenti

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
4 febbraio 2013 7.48
Risposta

David H Nebinger

Punteggio: Liferay Legend

Messaggi: 6437

Data di Iscrizione: 1 settembre 2006

Messaggi recenti

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
4 febbraio 2013 16.28
Risposta

Hitoshi Ozawa

Punteggio: Liferay Legend

Messaggi: 7990

Data di Iscrizione: 23 marzo 2010

Messaggi recenti

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
5 febbraio 2013 2.33
Risposta

Raghu k

Punteggio: Junior Member

Messaggi: 58

Data di Iscrizione: 10 agosto 2012

Messaggi recenti

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
5 febbraio 2013 3.16
Risposta

MICHAIL MOUDATSOS

Punteggio: Regular Member

Messaggi: 110

Data di Iscrizione: 4 ottobre 2011

Messaggi recenti

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
5 febbraio 2013 5.28
Risposta

David H Nebinger

Punteggio: Liferay Legend

Messaggi: 6437

Data di Iscrizione: 1 settembre 2006

Messaggi recenti

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
5 febbraio 2013 5.32
Risposta

David H Nebinger

Punteggio: Liferay Legend

Messaggi: 6437

Data di Iscrizione: 1 settembre 2006

Messaggi recenti

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
5 febbraio 2013 6.34
Risposta

MICHAIL MOUDATSOS

Punteggio: Regular Member

Messaggi: 110

Data di Iscrizione: 4 ottobre 2011

Messaggi recenti

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
5 febbraio 2013 7.25
Risposta

Raghu k

Punteggio: Junior Member

Messaggi: 58

Data di Iscrizione: 10 agosto 2012

Messaggi recenti

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
5 febbraio 2013 7.31
Risposta

Raghu k

Punteggio: Junior Member

Messaggi: 58

Data di Iscrizione: 10 agosto 2012

Messaggi recenti

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
5 febbraio 2013 9.17
Risposta

Raghu k

Punteggio: Junior Member

Messaggi: 58

Data di Iscrizione: 10 agosto 2012

Messaggi recenti

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
5 febbraio 2013 10.23
Risposta

David H Nebinger

Punteggio: Liferay Legend

Messaggi: 6437

Data di Iscrizione: 1 settembre 2006

Messaggi recenti

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
5 febbraio 2013 23.36
Risposta

Raghu k

Punteggio: Junior Member

Messaggi: 58

Data di Iscrizione: 10 agosto 2012

Messaggi recenti

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
5 febbraio 2013 23.45
Risposta

MICHAIL MOUDATSOS

Punteggio: Regular Member

Messaggi: 110

Data di Iscrizione: 4 ottobre 2011

Messaggi recenti

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
6 febbraio 2013 0.53
Risposta

Raghu k

Punteggio: Junior Member

Messaggi: 58

Data di Iscrizione: 10 agosto 2012

Messaggi recenti

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
7 febbraio 2013 6.47
Risposta

Raghu k

Punteggio: Junior Member

Messaggi: 58

Data di Iscrizione: 10 agosto 2012

Messaggi recenti

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