openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jeremy Bauer (JIRA)" <>
Subject [jira] Created: (OPENJPA-791) MappedSuperclass inheritance does not work properly with duplicate persistent field names
Date Wed, 26 Nov 2008 18:44:44 GMT
MappedSuperclass inheritance does not work properly with duplicate persistent field names

                 Key: OPENJPA-791
             Project: OpenJPA
          Issue Type: Bug
          Components: jpa
    Affects Versions: 2.0.0
            Reporter: Jeremy Bauer

An inheritance hierarchy which uses MappedSuperclass does not behave as expected when duplicate
persistent field names are in the hierarchy.  (No AttributeOverride is defined.)  The mapping
tool creates a table which contains a single column of the duplicate name.  When an entity
is persisted, only one field value is provided in the update and querying the entity results
in one of the fields being null.

Code to reproduce the problem:

public class SubCls extends MSuperCls {    
    private int id;
    public void setId(int id) { = id;
    public int getId() {
        return id;

public class MSuperCls extends M2SuperCls {
    private String name;
    public void setM1Name(String name) { = name;
    public String getM1Name() {
        return name;

public class M2SuperCls {
    private String name;
    public void setM2Name(String name) { = name;
    public String getM2Name() {
        return name;

        SubCls subcls = new SubCls();
        int id = new Random().nextInt();
        em clear();       
        SubCls subcls2 = em.find(SubCls.class, id);
        System.out.println("id: " + subcls2.getId());
        System.out.println("m1: " + subcls2.getM1Name());
        System.out.println("m2: " + subcls2.getM2Name());
Results in:

id: -1632111518
m1: M1Name
m2: null

The JPA spec does not appear to prescribe a means for dealing with this condition, via issuing
exception or a default naming scheme which handles duplicate persistence names.  The assumption
appears to be that an AttributeOverride should be specified to handle this condition, but
since AttributeOverride must be specified on the entity, it only works for a single instance
override of a duplicate name.  Given the intent of AttributeOverride, it appears that the
appropriate course of action is for OpenJPA to detect the duplicate names in the hierarchy
and throw an appropriate exception.

This message is automatically generated by JIRA.
You can reply to this email to add a comment to the issue online.

View raw message