留言板

Service Builder & Database Foreign Keys

thumbnail
Ignacio Díaz,修改在13 年前。

Service Builder & Database Foreign Keys

Regular Member 帖子: 127 加入日期: 06-7-27 最近的帖子
Hi all!

I have a doubt developing new portlets with ServiceBuilder and service.xml.

I have this code in my service.xml:


<entity name="Company" table="Company">
	...
       <column name="contacts" type="Collection" entity="Contact" mapping-key="idCompany" />
</entity>
<entity name="Contact" table="Contact">
	<column name="idContact" type="int" db-name="idContact" primary="true">
         ...
	<column name="idCompany" type="int" db-name="idCompany"></column>
</column></entity>


When I execute ServiceBuilder, all code is generated, all is ok, but there is no Foreign Key in SQL for column idCompany in table Contact, and it should reference Company Table and idCompany column.

Is the creation of foreign keys in database supported by ServiceBuilder? I have read the DTD and it's not mentioned there.

Thanks.
Nacho.
thumbnail
Tosco Francesco,修改在13 年前。

RE: Service Builder & Database Foreign Keys

New Member 帖子: 15 加入日期: 10-10-28 最近的帖子
Hi,
If you need only a join you just have to use xml-tag <finder> inside your entity.
If you need, instead, a query more articulated, you must implement a custom-sql query in class YourTableFinderImpl.
Goodbye
thumbnail
Ignacio Díaz,修改在13 年前。

RE: Service Builder & Database Foreign Keys

Regular Member 帖子: 127 加入日期: 06-7-27 最近的帖子
Thanks for your answer, but it's not only for the joins and finders. I mean, I need the Foreing-Key Constraint for delete...

If I try to delete a row which is referenced by a foreign key, the database will launch an exception and I could catch and manage it.

But If I have not a foreign key, I don't have this option.
Jens Göring,修改在13 年前。

RE: Service Builder & Database Foreign Keys

New Member 帖子: 22 加入日期: 10-11-18 最近的帖子
As far as I know Liferay does not use foreign key constraints to ensure referential integrity, see http://issues.liferay.com/browse/LPS-13418.
thumbnail
Tosco Francesco,修改在13 年前。

RE: Service Builder & Database Foreign Keys

New Member 帖子: 15 加入日期: 10-10-28 最近的帖子
In your <Table>LocalServiceImpl you have to add a new delete method where you must pick "foreign key" and call <foreignTable>LocalServiceUtil.delete(<foreignKey>Id);
then you can call simply this.delete(<yourRecord>Id)

something like this:

<Table>LocalServiceImpl extend <Table>LocalServiceBaseImpl{

public void myDelete(long id){

<Table> record = get<Table>(id)
<ExtTable>LocalServiceUtil.delete(record.getForeignKey())
delete(id)
}

}

obviously you must recall build services! Then you should see new method in LocalServiceUtil

hope this will help you

goodbye
thumbnail
Ignacio Díaz,修改在13 年前。

RE: Service Builder & Database Foreign Keys

Regular Member 帖子: 127 加入日期: 06-7-27 最近的帖子
Ok. I knew that I could do this programatically. Then, Liferay ServiceBuilder is not an Integrity Reference compliant development tool. It would be useful for next versions.

Thanks all!
Daniel Mueller,修改在12 年前。

RE: Service Builder & Database Foreign Keys

New Member 帖子: 12 加入日期: 11-11-10 最近的帖子
was just trying to solve the same problem... No foreign keys... welcome to the stone age. And thats not even the first step backwards for me so far. Back from facelets to JSPs... I know it supports facelets but its hard to find suppport already.

I thought liferay is using hibernate and spring under the covers, so why oh why is servicebuilder more complicated to use than hibernate but only half as powerful?