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: 



你可能感兴趣的:(Service Builder entity relationship)