File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Portals and Portlets and the fly likes Liferay EE 6.0.5 ServiceBuilder -- mapping relationship of a custom entity with an existing entity. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Portals and Portlets
Bookmark "Liferay EE 6.0.5 ServiceBuilder -- mapping relationship of a custom entity with an existing entity." Watch "Liferay EE 6.0.5 ServiceBuilder -- mapping relationship of a custom entity with an existing entity." New topic
Author

Liferay EE 6.0.5 ServiceBuilder -- mapping relationship of a custom entity with an existing entity.

Jignesh Gohel
Ranch Hand

Joined: Dec 28, 2004
Posts: 276
Liferay Portal EE 6.0.5 + MySQL

How to map one-to-many or many-to-one relationship between entities in service.xml ?

I am building a Portlet using the Liferay Plugins SDK.

I am need to map a foreign key relationship between database table LAYOUT(default created by Liferay) and a new table I want to create (P_VERSION)

P_VERSION table would be holding a column "plid" which would refer to "plid" column of LAYOUT table.



Following is my service.xml



Now when I run ant "build-service" target the build is successful and the appropriate classes gets generated without any error.

But having a look at docroot/WEB-INF/sql/tables.sql

following can be seen



And in docroot/WEB-INF/service/com/sample/page/service/persistence/PVersionUtil.java I can see the generated method

com.sample.page.service.persistence.PVersionUtil.getLayouts(long)

Questions:

a) I cannot find a setterXXX for associating an existing com.liferay.portal.Layout with my custom entity com.sample.page.PVersion.
I suppose there should be some configuration that should be added to the com.liferay.portal.Layout for making my mapping work.
But com.liferay.portal.Layout is an existing entity configured in <LIFERAY_PORTAL_ROOT>/portal-impl/src/com/liferay/portal/service.xml.
And it is available in my classpath so I cannot modify it.
So how to achieve the above mentioned configuration, in case my assumption is correct? If my assumption is wrong, then please
guide me with the correct approach for achieving my desired requirement as mentioned above.


b) I cannot see any column named "plid" in CREATE STATEMENT in tables.sql shown above.Any specific reason in not including a foreign key constraint in the create clause? If it is not appended in the CREATE clause then how this constraint gets applied?

Regards,
Jignesh

The Art Of Life Is To Know When To Be Useless And When To Be Useful - CHUANG TZU
Ivano Carrara
Greenhorn

Joined: Nov 08, 2010
Posts: 4
I'm having the same problem and I'm looking for the same solution....

Please, anyone can help us ??

Thank you in advance !

Ivano C.

Jignesh Gohel
Ranch Hand

Joined: Dec 28, 2004
Posts: 276
Hi Ivano,

With all the explorings done till date with Liferay what I think is it is a limitation in Liferay' Service Builder framework to define relationships between
user-defined custom entities and Liferay Portal's entities.

Of course, the relationships can be defined between user-defined custom entities in a given service.xml and it would generate the proper code.

http://www.liferay.com/community/forums/-/message_boards/message/1061266

However, what I have found is that though Liferay uses ORM framework (Hibernate) underneath its Persistent mechanism, the relationships and constraints
are not managed in the way it gets managed when using Hibernate itself at the Persistent layer.For instance on deleting a related entity
Liferay doesn't complain that there is an associated record in the related table, please delete that first.Above all looking at the Liferay's
Portal's implemented source code though they define a relationship between tables but sets the foreign key manually in the entity i.e. for instance,

a) EntityA and EntityB are related.
b) EntityB holds the primary key of EntityA as its foriegn key
c) What Liferay implementation does is it sets the foreign key manually which is contrary to the way relationships are managed when using Hibernate directly.


I may be wrong on my above findings but above is what I have observed while implementing portlets using Liferay and thought it would be good to share and
get comments from experts and others who are working on application involving Liferay.If I am wrong that somebody shall correct me and if I am correct then it might help somebody.

Thanks.
Ivano Carrara
Greenhorn

Joined: Nov 08, 2010
Posts: 4
Hi Jignesh,

I posted your thead here: http://www.liferay.com/community/forums/-/message_boards/message/8196632?_19_preview=false

I hope someone form Liferay can comments on it !

Thank you!!!

Ivano C.
 
wood burning stoves
 
subject: Liferay EE 6.0.5 ServiceBuilder -- mapping relationship of a custom entity with an existing entity.
 
Similar Threads
Silly problem: One user sees the information of another!
hbm.xml file does an update instead of an insert- Helppppp
Not-null property references a null or transient value
Liferay Web service