[
https://issues.apache.org/jira/browse/OPENJPA-851?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12666384#action_12666384
]
Fay Wang commented on OPENJPA-851:
----------------------------------
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", colu...@column(name="intVal1_colA")),
@AttributeOverride(name="intVal2", colu...@column(name="intVal2_colA"))
})
Map<EmbeddableA, EmbeddableB> phoneNumbers = new HashMap<AFullPhoneName,
PhoneNumber>();
(1) case 2:
@ElementCollection
@AttributeOverrides({
@AttributeOverride(name="intVal1", colu...@column(name="intVal1_colA")),
@AttributeOverride(name="intVal2", colu...@column(name="intVal2_colA"))
})
@AttributeOverrides({
@AttributeOverride(name="intVal1", colu...@column(name="intVal1_colB")),
@AttributeOverride(name="intVal2", colu...@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", colu...@column(name="intVal1_colA")),
@AttributeOverride(name="intVal2", colu...@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.
> Support for enhanced map collection (and corresponding annotations)
> -------------------------------------------------------------------
>
> Key: OPENJPA-851
> URL: https://issues.apache.org/jira/browse/OPENJPA-851
> Project: OpenJPA
> Issue Type: Sub-task
> Reporter: Fay Wang
> Assignee: Fay Wang
> Fix For: 2.0.0
>
>
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.