Hi,
If an embeddable contains persistent field names which clashes with other
persistent field names (either in the owner class, other embeddables, or nested
embeddables), openjpa currently maps these fields to the same column, resulting
in lost data in some situation or SQL exception in others. JIRA-793 is open to
fix this problem. The patch attached in this JIRA is to detect name clashes and
throw an exception. In most cases, application developers can either change the
field name or use @AttributeOverrides to change the column name as a
workaround. However, in situations that involved inheritance or multiple
embeddable instances of the same type, there is no workaround:
(1) in the case of inheritance: see
org.apache.openjpa.persistence.embed.Address (Entity),
org.apache.openjpa.persistence.embed.BaseEntity (MappedSuperclass),
org.apache.openjpa.persistence.embed.Geocode (Embeddable)
Both Address and Geocode inherits from BaseEntity. Address contains
Geocode. This results in the same field name for the embeddable (Geocode) and
entity class (Address).
(2) in the case of multiple embeddables of the same type:
Suppose EntityA contains:
private Embeddable1 embedObj1;
private Embeddable1 embedObj2;
Throwing an exception in these situations can prevent data loss or sql error
from occurring, but leave the application no way to fix the problem. However,
it is not appropriate for openjpa to provide unique column names automatically
without applications knowing it.
To address this issue, one proposal is to make this an option which can be
configured by adding an openjpa property, say,
openjpa.jdbc.createUniqueColumnNameIfNameClashes (any other idea?).
If this option is on, and there is name clash, openjpa will automatically
create unique column names for the duplicate field names. If this option is
off, and there is name clash, an exception will be thrown.
It is likely this proposal may break some existing applications, which may
either need to change the field name, use @AttributeOverrides, or turn
openjpa.jdbc.createUniqueColumnNameIfNameClashes on.
Any suggestions on the resolution of this issue is mostly appreciated.
Regards,
Fay