Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Andy Moora
SQL generated by service builder & relationships
October 18, 2012 7:55 AM
Answer

Andy Moora

Rank: New Member

Posts: 3

Join Date: October 18, 2012

Recent Posts

Hi all,

I'm trying to understand how service builder works. I have my service.xml file

 1
 2<?xml version="1.0" encoding="UTF-8" ?>
 3<!DOCTYPE service-builder PUBLIC "-//Liferay//DTD Service Builder 6.0.0//EN" "http://www.liferay.com/dtd/liferay-service-builder_6_0_0.dtd">
 4<service-builder package-path="com.my.company">
 5
 6    <author>I</author>
 7    <namespace>MY</namespace>
 8
 9    <entity name="One" local-service="true" remote-service="false">
10<column name="oneId" type="long" primary="true" />
11    </entity>
12    <entity name="Two" local-service="true" remote-service="false">
13<column name="twoId" type="long" primary="true" />
14        <column name="name" type="String" />
15        <column name="oneId" type="Collection" entity="One mapping-key="oneId" />
16    </entity>
17</service-builder>


and this gave me such sql tables file:

 1
 2create table MY_One(
 3    oneId LONG not null primary key
 4);
 5
 6create table MY_Two(
 7    twoId LONG not null primary key,
 8    name VARCHAR(75) null
 9);

where is information about relationship in this sql? Is tere some service builder bug or I made some mistake with this one to many relationship?

Liferay 6.1
Ant 1.8.4
liferay-plugins-sdk-6.1.1
Liferay IDE 1.6.0

Edit:

Or maybe it is correct? Can anyone provide working one to many example?
David H Nebinger
RE: SQL generated by service builder & relationships
October 18, 2012 8:09 AM
Answer

David H Nebinger

Community Moderator

Rank: Liferay Legend

Posts: 11102

Join Date: September 1, 2006

Recent Posts

SB does not handle relationships. You must manually manage the relationships yourself.

For your child entities you can define a finder based upon the parent id to retrieve the list of children for the parent id.
Andy Moora
RE: SQL generated by service builder & relationships
October 18, 2012 8:20 AM
Answer

Andy Moora

Rank: New Member

Posts: 3

Join Date: October 18, 2012

Recent Posts

Can You provide example so I will be sure to make this right?
Hitoshi Ozawa
RE: SQL generated by service builder & relationships
October 18, 2012 5:03 PM
Answer

Hitoshi Ozawa

Rank: Liferay Legend

Posts: 7949

Join Date: March 23, 2010

Recent Posts

I think you're missing the main point of service builder. I think it's because Brian Chan hasn't explained it too well yet.

Developers are mistaking service builder as a tool to generating database entities. Service builder as the name implies is used to generate "service". "Service" here implies interfaces. "Entities" in service.xml are entities in interface definition.

Service builder, however, also generates "standard" set of database entities by default. However, it's really up to the developer to use these "default" set of database entities or to use some external entities. It's also possible to customize how these database entities are created.

As service builder is about interfaces and interfaces doesn't have relationships, there's no concept of relationship supported by service builder. If you want to add relationship to the "default" database entities, you'll have to do it on your own.

Furthermore, liferay is designed to be a high performance platform. Database entities by "default" doesn't have relationships because they're designed to be transactional database entities instead of applicational or data mining database entities. Remember that liferay can be clustered and entities are cached in each server in a cluster before they are written to a database.
ron rei
RE: SQL generated by service builder & relationships
November 4, 2012 3:59 AM
Answer

ron rei

Rank: New Member

Posts: 1

Join Date: November 4, 2012

Recent Posts

Hey guys, thanks for all the input.
But I still don't get it.
In the case above, how do we make the tables so that they
do have the collection inside them?
could someone please post some directions?
Thanks!