You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@openjpa.apache.org by "Albert Lee (JIRA)" <ji...@apache.org> on 2007/02/16 19:40:05 UTC
[jira] Commented: (OPENJPA-150) @Column in @AttributeOverride not
honoring table attribute that maps to a secondary table in mappedsuperclass
entity
[ https://issues.apache.org/jira/browse/OPENJPA-150?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12473784 ]
Albert Lee commented on OPENJPA-150:
------------------------------------
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.
> @Column in @AttributeOverride not honoring table attribute that maps to a secondary table in mappedsuperclass entity
> --------------------------------------------------------------------------------------------------------------------
>
> Key: OPENJPA-150
> URL: https://issues.apache.org/jira/browse/OPENJPA-150
> Project: OpenJPA
> Issue Type: Bug
> Components: jdbc, sql
> Environment: Any
> Reporter: Albert Lee
>
> 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,
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.