2 Replies Latest reply: Nov 13, 2012 9:40 AM by cdelahun RSS

    Data getting inserted into parent table when trying to insert child table

    973683
      Hi,
      I am facing a problem when I try to insert/update the child table. I have parent table with columns

      PARENT Table:

      PCOL1
      PCOL2
      PCOL3
      .......
      LAST_UPDATED_BY
      LAST_UPDATED_ON

      CHILD Table:

      CCOL1
      CCOL2
      CCOL3
      .......
      LAST_UPDATED_BY
      LAST_UPDATED_ON

      Both the parent and Child table are having the fields LAST_UPDATED_BY and LAST_UPDATED_ON. From my application when I try to insert/update the LAST_UPDATED_BY and LAST_UPDATED_ON in child table through persist/merge methods. It inserts/update the parent table instead of child table
      <code>public class Child extends Parent</code>

      Note:
      I cannot change the column name
        • 2. Re: Data getting inserted into parent table when trying to insert child table
          cdelahun
          Looks like my response didn't get through for some reason.

          You didn't post the relevant JPA mapping and inheritance information, so I guess based on the table structure that you have a child entity with no mappings defined inheriting from a parent using a joined table inheritance. Joined table inheritance might be the wrong strategy to use, as each subclass requires a row in the parent table as well as the child table - a one to one relationship. Your child seems to be independent of the parent so you willl either need to use a table per class inheritance strategy and override the field names defined from the mappings on the parent entity ( see http://www.eclipse.org/eclipselink/api/2.0/javax/persistence/AttributeOverride.html )
          or it might be better to make the two classes completely independent and not have them associated through inheritance - the two classes might be better as seperate branches of the same tree instead of directly decending from one another. See http://wiki.eclipse.org/EclipseLink/UserGuide/JPA/Basic_JPA_Development/Entities/Inheritance#Avoiding_Inheritance

          Best Regards,
          Chris