Forums de discussion

Liferay Service Builder 6.2 : one to many ??

Stephane Franchamp, modifié il y a 9 années.

Liferay Service Builder 6.2 : one to many ??

New Member Publications: 19 Date d'inscription: 07/08/14 Publications récentes
Hi,

Any Ideas how to get liferay service builder one to many relationship with liferay 6.2 and not many to many ??

Thanks
thumbnail
M J, modifié il y a 9 années.

RE: Liferay Service Builder 6.2 : one to many ??

Regular Member Publications: 184 Date d'inscription: 01/03/13 Publications récentes
Implementation of one-to-many and many-to-many in Service Builder is useless. You should use CustomSQL to do any table joins.
thumbnail
Jack Bakker, modifié il y a 9 années.

RE: Liferay Service Builder 6.2 : one to many ??

Liferay Master Publications: 978 Date d'inscription: 03/01/10 Publications récentes
M J:
Implementation of one-to-many and many-to-many in Service Builder is useless. You should use CustomSQL to do any table joins.


I disagree with M J here, one-to-many and many-to-many is straight forward to implement while using service builder and without needing Custom SQL

Stephane Franchamp:

Any Ideas how to get liferay service builder one to many relationship with liferay 6.2 and not many to many ??


Hi Stephane,

By example and generally described, the approach I take for one-to-many, given XXXEntity which has many YYYEntity.

(I apologize in advance for inaccuracies as I am quickly typing this...)

In your service.xml, create the entities similar to below (note how YYYEntity references xXXEntityId and has a finder)


<entity name="XXXEntity" ...>
    <column name="xXXEntityId" ... primary="true" type="long" />
...
</entity>



<entity name="YYYEntity" ...>
    <column name="yYYEntityId" ... primary="true" type="long" />
    <column name="xXXEntityId" type="long" />
...
    <finder name="XXXEntityId" return-type="Collection">
            <finder-column name="xXXEntityId" />
     </finder>
</entity>


Build the services, then in YYYEntityLocalServiceImpl put in a method like:


public List<yyyentity> findByXXXEntityId(long xXXEntityId)
        throws *Exception {
    List<yyyentity> result = null;
    try{
        result = yYYPersistence.findByXXXEntityId(xXXEntityId);
    }catch(*Exception here like perhaps NotFound exceptions){
        ...
    } 
    return result;
}
</yyyentity></yyyentity>


And put in XXXEntityImpl:


public List<yyyentity> getYYYEntitys() throws *Exception{
    return YYYEntityLocalServiceUtil.findByXXXEntityId(super.getXXXEntityId());
}
</yyyentity>


from then on you can just use xXXEntity.getYYYEntitys() which is ... one-to-many
thumbnail
Olaf Kock, modifié il y a 9 années.

RE: Liferay Service Builder 6.2 : one to many ??

Liferay Legend Publications: 6403 Date d'inscription: 23/09/08 Publications récentes
Do like Jack says.

I'm typically more lazy and just point to xmlportletfactory - create the basic services/entities there, generate and make the code yours. Good source of documentation that you can debug/step through.
thumbnail
Jack Bakker, modifié il y a 9 années.

RE: Liferay Service Builder 6.2 : one to many ??

Liferay Master Publications: 978 Date d'inscription: 03/01/10 Publications récentes
Olaf Kock:

I'm typically more lazy and just point to xmlportletfactory - create the basic services/entities there, generate and make the code yours. Good source of documentation that you can debug/step through.

I'm all for Lazy Velocity, will check xmlportletfactory
thumbnail
Olaf Kock, modifié il y a 9 années.

RE: Liferay Service Builder 6.2 : one to many ??

Liferay Legend Publications: 6403 Date d'inscription: 23/09/08 Publications récentes
I totally forgot to link the Radio Liferay episode for the commute, where you can hear about it.
Vishal Patel, modifié il y a 9 années.

RE: Liferay Service Builder 6.2 : one to many ??

Junior Member Publications: 83 Date d'inscription: 24/11/14 Publications récentes
HI,

I already know about one to many implmentation and many to one implementation through service.xml and XXXLocalServiceImpl.java.nnd using them throughout my projects.


But Thanks to pointing out. Adding to parent's Impl class, that is what I was not aware of.

And put in XXXEntityImpl:


public List<YYYEntity> getYYYEntitys() throws *Exception{
return YYYEntityLocalServiceUtil.findByXXXEntityId(super.getXXXEntityId());
}


from then on you can just use xXXEntity.getYYYEntitys() which is ... one-to-many


Thanks Again.
thumbnail
Jack Bakker, modifié il y a 9 années.

RE: Liferay Service Builder 6.2 : one to many ??

Liferay Master Publications: 978 Date d'inscription: 03/01/10 Publications récentes
Hi Vishal, glad something useful shared

a similar approach can also be used for many-to-many including with association tables (including with additional fields) - where the association table has its own XXXYYYEntity in service.xml
thumbnail
Robin Nagpal, modifié il y a 9 années.

RE: Liferay Service Builder 6.2 : one to many ??

Junior Member Publications: 44 Date d'inscription: 18/11/14 Publications récentes
This is one of the main problems of SB. Its not possible to do it.

I guess the most important thing to consider is whether you need to share your services within different protlet projects.If yes, then SB is your best bet. If you are 200% sure that one portlet project can suffice your needs, you can use other technologies like Spring JPA , or JPA which does provide more flexibility but requires indepth knowledge of these.