Issue Details (XML | Word | Printable)

Key: OPENJPA-150
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Unassigned
Reporter: Albert Lee
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
OpenJPA

@Column in @AttributeOverride not honoring table attribute that maps to a secondary table in mappedsuperclass entity

Created: 15/Feb/07 02:38 PM   Updated: 30/Oct/07 02:45 PM
Return to search
Component/s: jdbc, sql
Affects Version/s: None
Fix Version/s: 0.9.7

Time Tracking:
Not Specified

Environment: Any

Resolution Date: 20/Feb/07 05:38 PM


 Description  « Hide
I have the following scenario mapping entity to 2 tables:

- a mapped super class that has a field
- a subclass with a pk and a field.
- trying to map all the fields (except the pk (id) ) to a secondary table (SEC_TABLE2MSC)
  - use @Column in the sub-class to override (name) to the secondary table
  - use @AttributeOverride to override the field (street) in the mapped super class to the secondary table.

===============
@MappedSuperclass
public abstract class AnnMSCMultiTable
implements IMultiTableEntity
{
    // @Column(table="SEC_TABLE2MSC")
    private String street;
    public String getStreet() {
        return street;
    }
   public void setStreet(String street) {
        this.street = street;
    }
}
===============
@Entity
@SecondaryTable(name="SEC_TABLE2MSC", pkJoinColumns=@PrimaryKeyJoinColumn(name="id"))
@AttributeOverrides(
        {
            @AttributeOverride(name="street", column=@Column(name="street", table="SEC_TABLE2MSC")),
        })
public class AnnMSCMultiTableEnt
extends AnnMSCMultiTable
{
    @Id
    private int id;

    @Column(name="name2", table="SEC_TABLE2MSC")
    private String name;
}
===============

From examining JPA spec, there is no specific in the @Column and @AttributeOverride that this should not be allow. So I believe this is a valid scenario.

Using the MappingTool, the attribute override does not map the street field to the SEC_TABLE2MSC as I would expect:

CREATE TABLE AnnMSCMultiTableEnt (id INTEGER NOT NULL, street VARCHAR(254), PRIMARY KEY (id));
CREATE TABLE SEC_TABLE2MSC (id INTEGER, name2 VARCHAR(254));
CREATE INDEX I_SC_TMSC_ID ON SEC_TABLE2MSC (id);

I experiment this a little bit and the only way I can map the street field to SEC_TABLE2MSC is
to add the @Column against the "street" attribute in the super class. (the commented @Column in the example).
The expected SQL are:

CREATE TABLE AnnMSCMultiTableEnt (id INTEGER NOT NULL, PRIMARY KEY (id));
CREATE TABLE SEC_TABLE2MSC (id INTEGER, street VARCHAR(254), name2 VARCHAR(254));
CREATE INDEX I_SC_TMSC_ID ON SEC_TABLE2MSC (id);

I tried to create the tables manually using the expected layout, but the runtime still using the incorrect tables structure. I would suspect the MappingTool and the runtime are using the same mapping strategy.

Albert Lee,

 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Albert Lee added a comment - 16/Feb/07 06:38 PM
I investigated into this problem and the following changes has corrected the problem scenarios:

public class org.apache.openjpa.persistence.jdbc.AnnotationPersistenceMappingParser
{
    .......
    private void parseAttributeOverrides(ClassMapping cm,
        AttributeOverride... attrs) {
        .......
        for (AttributeOverride attr : attrs) {
            ...........
// unique = (scol.unique()) ? TRUE : FALSE;
// setColumns(sup, sup.getValueInfo(), Arrays.asList
// (new Column[]{ newColumn(scol) }), unique);
            // *** Replace the above statements by parseColumns()
            parseColumns( sup, scol);
        }
    }

    private void parseAttributeOverrides(FieldMapping fm,
        AttributeOverride... attrs) {
        ..........
        for (AttributeOverride attr : attrs) {
            ...........
// unique = (ecol.unique()) ? TRUE : FALSE;
// setColumns(efm, efm.getValueInfo(), Arrays.asList
// (new Column[]{ newColumn(ecol) }), unique);
            // *** Replace the above statements by parseColumns()
            parseColumns( efm, ecol);
        }
    }
}

Basically, the changes are to re-use the parseColumns() method to process the @Column defintion(s) in @AttributeOverride to handle all the @Column attributes.

I ran some basic tests and there is no regression.

I am new to the openjpa code base and still have a long way to fully understand all the the ins and outs.

Can someone, who has more thorough knowledge of this code path, review these changes to ensure I am not "way-off"?

Thanks.
Albert Lee.

Repository Revision Date User Message
ASF #509674 Tue Feb 20 17:37:18 UTC 2007 awhite OPENJPA-150 : Re-use parseColumns method when parsing AttributeOverride columns
so that we get secondary table information.
Files Changed
MODIFY /incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/AnnotationPersistenceMappingParser.java

Abe White added a comment - 20/Feb/07 05:38 PM
Committed suggested changes (with very minor modifications) in revision 509674. Thanks for the fix.

Abe White made changes - 20/Feb/07 05:38 PM
Field Original Value New Value
Resolution Fixed [ 1 ]
Status Open [ 1 ] Resolved [ 5 ]
Patrick Linskey made changes - 01/Mar/07 02:13 AM
Fix Version/s 0.9.7 [ 12312340 ]
Albert Lee made changes - 30/Oct/07 02:45 PM
Status Resolved [ 5 ] Closed [ 6 ]