Thursday, August 4, 2011

Table Relationships

15 comments:

  1. Thank you Rohit ,but i don't know why it is not working properly .I have five tables 1st table is related to all table i.e it contains some fields which are defined as foreign key for other four tables .I want to know is it possible to have only one service.xml file for creating any number of tables.

    ReplyDelete
  2. Yes for every project that you create , you must have one service.xml. You can have multiple entity tags between the service-builder tags. The above example that i have given is assuming that both the entity tags are within one service-builder tag.

    ReplyDelete
  3. Hello Rohit,
    Just want to ask that in above post,
    both entites have same name Parent,

    It it ok having same name of multiple entities?

    Thanks & Regards
    Vipin Bardia

    ReplyDelete
  4. Hello Rohit when adding relationship as you suggested,the database tables remains same.i.e no foreign constraint is there .Iam having one classified table which conatins one field categoryid ,and that column i want to use in category table as a foreign key .Now can you please give me some idea how to add foreign key in category table.
    Thanks in advance

    ReplyDelete
  5. @Vipin
    My Bad, The second entity is the Child entity.
    You cannot have 2 entities with the same name.

    ReplyDelete
  6. @Sunny ,
    I am not sure as to why the database relationship is persisting alongwith the mapping in the service.xml.
    One reason probably would be that Hibernate must be taking care of it. Like , the only reason why this facility has been given is that , in your ChildLocalServiceUtil , a parent object will injected. So you can use both to create your own operations.

    ReplyDelete
  7. Hello Rohit,
    I want to know is it possible to define relationship between liferay tables and our own custom tables.I want to use user table in my custom table .So is it possible to relate liferay tables with custom tables ? If it possible than please suggest me solution.

    ReplyDelete
  8. @Sunny ,

    You see all the underlying database stuff happens through hibernate. I havent really worked on hibernate so dont know how it happens.
    But, i guess liferay is independent of what you do in your database. If you any table is missing it automatically creates a fresh new one. Offcourse the data is lost. So you can just give it a try , by creating a Trigger on the User Table and them Modifying contents of your own table depending on the requirement.

    ReplyDelete
  9. This comment has been removed by the author.

    ReplyDelete
  10. Hi, Rohit

    i try to implement that in my project. build service successfully. but not able to access parent function from the child as u said above???

    ReplyDelete
    Replies
    1. This comment has been removed by the author.

      Delete
  11. Hi rohit ,It seems like it is very difficult to create the related tables in liferay ..May be there will be some type of solution is available ,but i don't want to spend much time on this topic .Thank you for suggesting me .
    I am facing problem in creating the MVCPortlet can you help me for this .I want to create a struts portlet which interact with database using AUI or YUI..
    Thanks in Advance

    ReplyDelete
  12. This comment has been removed by the author.

    ReplyDelete
  13. @ Sunny , you can start from the page liferay Development on my blog to learn MVCPortlet. Liferay guys suggest to make the portlets with that framework only. Struts i havnt tried so cannot really comment on the same.

    ReplyDelete
  14. Hi Rohit Salecha

    Why you mention parentId as collection in child entity...?

    ReplyDelete