Service Builder entity relationship

When we use Service Builder, we might create relationships between entities. Our demand is that Service Builder could create relationships between entities for us. But that's just our dream. Actually Service Builder doesn't build relationship for us.

For example:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE service-builder PUBLIC "-//Liferay//DTD Service Builder 6.0.0//EN" "http://www.liferay.com/dtd/liferay-service-builder_6_0_0.dtd">


<service-builder package-path="com.rujuan.book">
<author>Rujuan Xing</author>
<namespace>BookList</namespace>
<entity name="Book" local-service="true" remote-service="false" uuid="true">
<column name="bookid" type="int" primary="true" />
<column name="title" type="String" />
<column name="authorname" type="String" />
<column name="isbn" type="String" />
<column name="summary" type="String" />
<column name="status" type="int"></column>
<column name="statusByUserId" type="long"></column>
<column name="statusByUserName" type="String"></column>
<column name="statusDate" type="Date"></column>
<column name="author" type="Collection" entity="Author"
mapping-key="authorid" />

<column name="companyId" type="long"></column>
<column name="groupId" type="long"></column>
<column name="userId" type="long"></column>

<reference package-path="com.liferay.portal" entity="User" />
<reference package-path="com.liferay.asset" entity="AssetEntry"/>
<reference package-path="com.liferay.ratings" entity="RatingsStats"/>
<reference package-path="com.liferay.portal" entity="Resource" />
<reference package-path="com.liferay.portal" entity="WorkflowInstanceLink" />
</entity>


<entity name="Author" local-service="true" remote-service="false">
<column name="authorid" type="int" primary="true"></column>
<column name="authorname" type="String"></column>
<finder return-type="Author" name="getAuthorByName">
<finder-column name="authorname"></finder-column>
</finder>
</entity>
</service-builder>

This is my service.xml. I define two entities Book and Author. I just define a  many-to-one unidirectional relationship. An author can write many book. A book is only written by one author.

Service Builder just creates two tables for me. It won't create FK for me. For FK, we need to add by ourselves. Another thing is that when we add book to database, we need to add Author to database too. This is no method like setAuthor(Author author).

For more info about service builder relationship, see the link: 



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值