MappedSuperclass inheritance does not work properly with duplicate persistent 
field names
-----------------------------------------------------------------------------------------

                 Key: OPENJPA-791
                 URL: https://issues.apache.org/jira/browse/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:

@Entity
public class SubCls extends MSuperCls {    
    @Id
    private int id;
    public void setId(int id) {
        this.id = id;
    }
    public int getId() {
        return id;
    }
}

@MappedSuperclass
public class MSuperCls extends M2SuperCls {
    @Basic
    private String name;
    public void setM1Name(String name) {
        this.name = name;
    }
    public String getM1Name() {
        return name;
    }      
}

@MappedSuperclass
public class M2SuperCls {
    @Basic
    private String name;
    public void setM2Name(String name) {
        this.name = name;
    }
    public String getM2Name() {
        return name;
    }  
}

        SubCls subcls = new SubCls();
        int id = new Random().nextInt();
        subcls.setId(id);
        subcls.setM1Name("M1Name");
        subcls.setM2Name("M2Name");
        em.getTransaction().begin();
        em.persist(subcls);
        em.getTransaction().commit();        
        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.

Reply via email to