OpenJPA
  1. OpenJPA
  2. OPENJPA-807 OpenJPA 2.0 iteration 2 primary task
  3. OPENJPA-851

Support for enhanced map collection (and corresponding annotations)

    Details

    • Type: Sub-task Sub-task
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.0.0-M2
    • Component/s: None
    • Labels:
      None

      Activity

      Fay Wang created issue -
      Hide
      Fay Wang added a comment -

      This subtask will cover the following items:

      (1) Enhanced map collection support 2.7
      (2) Support @MapKeyClass annotation and XML 10.1.27, 10.1.26
      (3) Support @MapKeyColumn annotation and XML 10.1.28, 2.7.1
      (4) Support @MapKeyJoinColumn annotation and XML 10.1.29
      (5) Support @MapKeyJoinColumns annotation and XML 10.1.30
      (6) Support @MappedById annotation and XML 10.1.31
      (7) Support orphanRemoval attribute on relationships 2.9, 10.1.33, 10.1.34

      Show
      Fay Wang added a comment - This subtask will cover the following items: (1) Enhanced map collection support 2.7 (2) Support @MapKeyClass annotation and XML 10.1.27, 10.1.26 (3) Support @MapKeyColumn annotation and XML 10.1.28, 2.7.1 (4) Support @MapKeyJoinColumn annotation and XML 10.1.29 (5) Support @MapKeyJoinColumns annotation and XML 10.1.30 (6) Support @MappedById annotation and XML 10.1.31 (7) Support orphanRemoval attribute on relationships 2.9, 10.1.33, 10.1.34
      Fay Wang committed 734319 (30 files)
      Reviews: none

      OPENJPA-851: enhanced map support for JPA 2.0 (Spec 10.1.26,
      10.1.27, 10.1.28, 10.1.29, 10.1.30, 2.7)

      openjpa trunk
      Hide
      Fay Wang added a comment -

      Enhance map support (spec 2.7, 10.1.26, 10.1.27, 10.1.28, 10.1.29, 10.1.30) is committed r-734319.

      Show
      Fay Wang added a comment - Enhance map support (spec 2.7, 10.1.26, 10.1.27, 10.1.28, 10.1.29, 10.1.30) is committed r-734319.
      Hide
      Fay Wang added a comment -

      More map support is committed r-734617 for bi-directional map in update operation

      Show
      Fay Wang added a comment - More map support is committed r-734617 for bi-directional map in update operation
      Hide
      Fay Wang added a comment -

      Xml orm support for MapKeyClass, MapKeyColumn, MayKeyJoinColumn is checked in r-734926.

      Show
      Fay Wang added a comment - Xml orm support for MapKeyClass, MapKeyColumn, MayKeyJoinColumn is checked in r-734926.
      Hide
      Fay Wang added a comment -

      ManyToMany Map support is checked in r-736245.

      Show
      Fay Wang added a comment - ManyToMany Map support is checked in r-736245.
      Hide
      Fay Wang added a comment -

      Completed:
      ==========
      Item (1) - (6).

      Deferred:
      ========
      Item (7) and (8) .

      Limitation:
      =========
      Bi-directional one-to-many/may-to-one map will not able to accommodate same map value with different map key.

      Spec 2.7.1 indicates that for a bi-directional one-to-many/may-to-one map, by default, the map is mapped in the table of the entity that is the value of the map. Considering the following example:

      @Entity
      public class Company

      { @Id int id; @OneToMany(mappedBy="co") Map<Division, VicePresident> organization = new HashMap<Division, VicePresident>(); ... }

      @Entity
      public class VicePresident

      { @Id int id; String name; @ManyToOne Company co; }

      The table of the VicePresident have the following columns: id, name, CO_ID, KEY_ID. Suppose the map "organization" has the following entries:
      key value
      -------- ---------
      Div1 VP1
      Div2 VP2
      Div3 VP3
      Div4 VP1

      Note that VP1 appears twice in the map table with different keys. However, due to primary key constraint, the VicePresident table can only have the following entries:

      id name CO_ID KEY_ID
      ----- ----------- ----------- -----------
      1 VP1 1 Div1
      2 VP2 1 Div2
      3 VP3 1 Div3

      The limitation is therefore clear that for bi-directional map, it is impossible to have multiple entries with the same map value.

      Open Issues:
      ===========
      Problem with AttributeOverrides on map key/value when any of them are embeddable.

      On page 36 of the Spec, AttributeOverride can be used when map key/value is embeddable. The following examples illustrates the problem of using AttributeOverride when both map key and value are embeddable.

      (1) case 1:

      @ElementCollection
      @AttributeOverrides(

      { @AttributeOverride(name="intVal1", column=@Column(name="intVal1_colA")), @AttributeOverride(name="intVal2", column=@Column(name="intVal2_colA")) })
      Map<EmbeddableA, EmbeddableB> phoneNumbers = new HashMap<AFullPhoneName, PhoneNumber>();


      (1) case 2:
      @ElementCollection
      @AttributeOverrides({ @AttributeOverride(name="intVal1", column=@Column(name="intVal1_colA")), @AttributeOverride(name="intVal2", column=@Column(name="intVal2_colA")) }

      )
      @AttributeOverrides(

      { @AttributeOverride(name="intVal1", column=@Column(name="intVal1_colB")), @AttributeOverride(name="intVal2", column=@Column(name="intVal2_colB")) }

      )
      Map<EmbeddableA, EmbeddableB> phoneNumbers = new HashMap<AFullPhoneName, PhoneNumber>();

      In both case, there is no way to know which embeddable the AttributeOverride applies to. One proposal is to create @EmbeddedKey and @EmbeddedValue annotations to distinguish these situations as follows:

      @EmbeddedKey
      @AttributeOverrides(

      { @AttributeOverride(name="intVal1", column=@Column(name="intVal1_colA")), @AttributeOverride(name="intVal2", column=@Column(name="intVal2_colA")) }

      )

      This feature can not be implemented until this issue is resolved.

      Without the support of AttributeOverrides, the default column names for the embeddables are derived from the field or property names of the embeddable class. In the above example, if EmbeddableA and EmbeddableB have the same field names, there will be column name clashes, causing lost information or sql error.

      Show
      Fay Wang added a comment - Completed: ========== Item (1) - (6). Deferred: ======== Item (7) and (8) . Limitation: ========= Bi-directional one-to-many/may-to-one map will not able to accommodate same map value with different map key. Spec 2.7.1 indicates that for a bi-directional one-to-many/may-to-one map, by default, the map is mapped in the table of the entity that is the value of the map. Considering the following example: @Entity public class Company { @Id int id; @OneToMany(mappedBy="co") Map<Division, VicePresident> organization = new HashMap<Division, VicePresident>(); ... } @Entity public class VicePresident { @Id int id; String name; @ManyToOne Company co; } The table of the VicePresident have the following columns: id, name, CO_ID, KEY_ID. Suppose the map "organization" has the following entries: key value -------- --------- Div1 VP1 Div2 VP2 Div3 VP3 Div4 VP1 Note that VP1 appears twice in the map table with different keys. However, due to primary key constraint, the VicePresident table can only have the following entries: id name CO_ID KEY_ID ----- ----------- ----------- ----------- 1 VP1 1 Div1 2 VP2 1 Div2 3 VP3 1 Div3 The limitation is therefore clear that for bi-directional map, it is impossible to have multiple entries with the same map value. Open Issues: =========== Problem with AttributeOverrides on map key/value when any of them are embeddable. On page 36 of the Spec, AttributeOverride can be used when map key/value is embeddable. The following examples illustrates the problem of using AttributeOverride when both map key and value are embeddable. (1) case 1: @ElementCollection @AttributeOverrides( { @AttributeOverride(name="intVal1", column=@Column(name="intVal1_colA")), @AttributeOverride(name="intVal2", column=@Column(name="intVal2_colA")) }) Map<EmbeddableA, EmbeddableB> phoneNumbers = new HashMap<AFullPhoneName, PhoneNumber>(); (1) case 2: @ElementCollection @AttributeOverrides({ @AttributeOverride(name="intVal1", column=@Column(name="intVal1_colA")), @AttributeOverride(name="intVal2", column=@Column(name="intVal2_colA")) } ) @AttributeOverrides( { @AttributeOverride(name="intVal1", column=@Column(name="intVal1_colB")), @AttributeOverride(name="intVal2", column=@Column(name="intVal2_colB")) } ) Map<EmbeddableA, EmbeddableB> phoneNumbers = new HashMap<AFullPhoneName, PhoneNumber>(); In both case, there is no way to know which embeddable the AttributeOverride applies to. One proposal is to create @EmbeddedKey and @EmbeddedValue annotations to distinguish these situations as follows: @EmbeddedKey @AttributeOverrides( { @AttributeOverride(name="intVal1", column=@Column(name="intVal1_colA")), @AttributeOverride(name="intVal2", column=@Column(name="intVal2_colA")) } ) This feature can not be implemented until this issue is resolved. Without the support of AttributeOverrides, the default column names for the embeddables are derived from the field or property names of the embeddable class. In the above example, if EmbeddableA and EmbeddableB have the same field names, there will be column name clashes, causing lost information or sql error.
      Fay Wang made changes -
      Field Original Value New Value
      Resolution Fixed [ 1 ]
      Fix Version/s 2.0.0 [ 12313483 ]
      Status Open [ 1 ] Resolved [ 5 ]
      Fay Wang committed 737164 (1 file)
      Donald Woods made changes -
      Status Resolved [ 5 ] Closed [ 6 ]

        People

        • Assignee:
          Fay Wang
          Reporter:
          Fay Wang
        • Votes:
          0 Vote for this issue
          Watchers:
          0 Start watching this issue

          Dates

          • Created:
            Updated:
            Resolved:

            Development