This Bugzilla instance is deprecated, and most Eclipse projects now use GitHub or Eclipse GitLab. Please see the deprecation plan for details.
View | Details | Raw Unified | Return to bug 266912 | Differences between
and this patch

Collapse All | Expand All

(-)jpa/eclipselink.jpa.test/src/org/eclipse/persistence/testing/models/jpa/metamodel/Computer.java (-3 / +16 lines)
Lines 86-99 Link Here
86
    // http://wiki.eclipse.org/EclipseLink/Development/JPA_2.0/metamodel_api#DI_58:_20090807:_ManagedType_Attribute_Initialization_must_differentiate_between_Collection_and_List
86
    // http://wiki.eclipse.org/EclipseLink/Development/JPA_2.0/metamodel_api#DI_58:_20090807:_ManagedType_Attribute_Initialization_must_differentiate_between_Collection_and_List
87
    private Collection<Board> circuitBoards;
87
    private Collection<Board> circuitBoards;
88
88
89
    @OneToMany(mappedBy="computer", cascade=ALL, fetch=EAGER)
89
    // UC10:  mapKey defined via generics and is a java class defined as an IdClass on the element(value) class
90
    @OneToMany(mappedBy="computerUC10", cascade=ALL, fetch=EAGER)
90
    @MapKey // key defaults to an instance of the composite pk class
91
    @MapKey // key defaults to an instance of the composite pk class
91
    //@MapKey(name="name")
92
    //@MapKey(name="name")
92
    private Map<EnclosureIdClassPK, Enclosure> enclosures;
93
    private Map<EnclosureIdClassPK, Enclosure> enclosuresUC10;
93
94
95
    // UC12:  mapKey defined via generics and is an Embeddable (EmbeddedId) java class defined as an IdClass on the element(value) class
96
    @OneToMany(mappedBy="computerUC12", cascade=ALL, fetch=EAGER)
97
    @MapKey // key defaults to an instance of the composite pk class
98
    //@MapKey(name="primaryKey")
99
    private Map<EmbeddedPK, GalacticPosition> positionUC12;
100
101
    // UC13:  mapKey defined via generics and is an Embeddable (EmbeddedId) java class defined as an IdClass on the element(value) class
102
    // However, here we make the owning OneToMany - unidirectional and an effective ManyToMany
103
    //@OneToMany(mappedBy="computerUniUC13", cascade=ALL, fetch=EAGER)
104
    @MapKey // key defaults to an instance of the composite pk class
105
    private Map<EmbeddedPK, GalacticPosition> positionUniUC13;
106
    
94
    public void addEnclosure(Enclosure enclosure) {
107
    public void addEnclosure(Enclosure enclosure) {
95
        enclosure.setComputer(this);
108
        enclosure.setComputer(this);
96
        enclosures.put(enclosure.buildPK(), enclosure);
109
        enclosuresUC10.put(enclosure.buildPK(), enclosure);
97
    }
110
    }
98
    
111
    
99
    public Computer() {
112
    public Computer() {
(-)jpa/eclipselink.jpa.test/src/org/eclipse/persistence/testing/models/jpa/metamodel/Enclosure.java (-29 / +28 lines)
Lines 48-54 Link Here
48
            joinColumns = @JoinColumn(name="ENCLOSURE_MAP_ID"), 
48
            joinColumns = @JoinColumn(name="ENCLOSURE_MAP_ID"), 
49
            inverseJoinColumns =@JoinColumn(name="MANUF_ID"))*/   
49
            inverseJoinColumns =@JoinColumn(name="MANUF_ID"))*/   
50
    private Manufacturer mappedManufacturerUC9;
50
    private Manufacturer mappedManufacturerUC9;
51
  
52
/*    @Id
53
    @GeneratedValue(strategy=TABLE, generator="ENCLOSURE_MM_TABLE_GENERATOR")
54
    @TableGenerator(
55
        name="ENCLOSURE_MM_TABLE_GENERATOR", 
56
        table="CMP3_MM_ENCLOSURE_SEQ", 
57
        pkColumnName="SEQ_MM_NAME", 
58
        valueColumnName="SEQ_MM_COUNT",
59
        pkColumnValue="CUST_MM_SEQ"
60
    )
61
    @Column(name="ENCLOSURE_ID")    
62
    private Integer id;
63
*/
51
    
64
    
65
    //@Version
66
    //@Column(name="ENCLOSURE_VERSION")
67
    //private int version;
68
    
69
    // The M:1 side is the owning side for "enclosureUC10"
70
    @ManyToOne(fetch=EAGER)
71
/*    @JoinTable(name="CMP3_MM_COMPUTER_MM_ENCLOSURE", 
72
            joinColumns = @JoinColumn(name="ENCLOSURE_ID"), 
73
            inverseJoinColumns = @JoinColumn(name="COMPUTER_ID"))*/   
74
    private Computer computerUC10;
75
    
76
    public Enclosure() {}
77
52
    public EnclosureIdClassPK buildPK(){
78
    public EnclosureIdClassPK buildPK(){
53
        EnclosureIdClassPK pk = new EnclosureIdClassPK();
79
        EnclosureIdClassPK pk = new EnclosureIdClassPK();
54
        pk.setLength(this.getLength());
80
        pk.setLength(this.getLength());
Lines 98-130 Link Here
98
        this.width = width;
124
        this.width = width;
99
    }
125
    }
100
    
126
    
101
    
102
/*    @Id
103
    @GeneratedValue(strategy=TABLE, generator="ENCLOSURE_MM_TABLE_GENERATOR")
104
    @TableGenerator(
105
        name="ENCLOSURE_MM_TABLE_GENERATOR", 
106
        table="CMP3_MM_ENCLOSURE_SEQ", 
107
        pkColumnName="SEQ_MM_NAME", 
108
        valueColumnName="SEQ_MM_COUNT",
109
        pkColumnValue="CUST_MM_SEQ"
110
    )
111
    @Column(name="ENCLOSURE_ID")    
112
    private Integer id;
113
*/
114
    
115
    //@Version
116
    //@Column(name="ENCLOSURE_VERSION")
117
    //private int version;
118
    
119
    // The M:1 side is the owning side for "circuitBoards"
120
    @ManyToOne(fetch=EAGER)
121
/*    @JoinTable(name="CMP3_MM_COMPUTER_MM_ENCLOSURE", 
122
            joinColumns = @JoinColumn(name="ENCLOSURE_ID"), 
123
            inverseJoinColumns = @JoinColumn(name="COMPUTER_ID"))*/   
124
    private Computer computer;
125
    
126
    public Enclosure() {}
127
128
/*    public int getVersion() { 
127
/*    public int getVersion() { 
129
        return version; 
128
        return version; 
130
    }
129
    }
Lines 143-153 Link Here
143
*/
142
*/
144
143
145
    public Computer getComputer() {
144
    public Computer getComputer() {
146
        return computer;
145
        return computerUC10;
147
    }
146
    }
148
147
149
    public void setComputer(Computer computer) {
148
    public void setComputer(Computer computer) {
150
        this.computer = computer;
149
        this.computerUC10 = computer;
151
    }
150
    }
152
151
153
    
152
    
(-)jpa/eclipselink.jpa.test/src/org/eclipse/persistence/testing/models/jpa/metamodel/EnclosureIdClassPK.java (-23 / +24 lines)
Lines 19-24 Link Here
19
    private String width;
19
    private String width;
20
    private Integer mappedManufacturerUC9;
20
    private Integer mappedManufacturerUC9;
21
21
22
    public EnclosureIdClassPK() {}
23
24
    @Override
25
    public boolean equals(Object anEnclosureIdClassPK) {
26
        if (anEnclosureIdClassPK.getClass() != EnclosureIdClassPK.class) {
27
            return false;
28
        }        
29
        EnclosureIdClassPK enclosureIdClassPK = (EnclosureIdClassPK) anEnclosureIdClassPK;        
30
        return (enclosureIdClassPK.getLength().equals(this.getLength()) && 
31
                enclosureIdClassPK.getWidth().equals(this.getWidth()) &&
32
                enclosureIdClassPK.getType().equals(this.getType()) &&
33
                enclosureIdClassPK.getMappedManufacturerUC9().equals(this.mappedManufacturerUC9));
34
    }
35
36
    @Override
37
    public int hashCode() {
38
        if (null != type && null != length && null != width && null != mappedManufacturerUC9) {
39
            return 9232 * type.hashCode() * length.hashCode() * width.hashCode() * mappedManufacturerUC9.hashCode();
40
        } else {
41
            return super.hashCode();
42
        }
43
    }
44
    
22
    public String getType() {
45
    public String getType() {
23
        return type;
46
        return type;
24
    }
47
    }
Lines 51-77 Link Here
51
    public void setMappedManufacturerUC9(Integer mappedManufacturerUC9) {
74
    public void setMappedManufacturerUC9(Integer mappedManufacturerUC9) {
52
        this.mappedManufacturerUC9 = mappedManufacturerUC9;
75
        this.mappedManufacturerUC9 = mappedManufacturerUC9;
53
    }
76
    }
54
77
    
55
    public EnclosureIdClassPK() {}
56
57
    @Override
58
    public boolean equals(Object anEnclosureIdClassPK) {
59
        if (anEnclosureIdClassPK.getClass() != EnclosureIdClassPK.class) {
60
            return false;
61
        }        
62
        EnclosureIdClassPK enclosureIdClassPK = (EnclosureIdClassPK) anEnclosureIdClassPK;        
63
        return (enclosureIdClassPK.getLength().equals(this.getLength()) && 
64
                enclosureIdClassPK.getWidth().equals(this.getWidth()) &&
65
                enclosureIdClassPK.getType().equals(this.getType()) &&
66
                enclosureIdClassPK.getMappedManufacturerUC9().equals(this.mappedManufacturerUC9));
67
    }
68
69
    @Override
70
    public int hashCode() {
71
        if (null != type && null != length && null != width && null != mappedManufacturerUC9) {
72
            return 9232 * type.hashCode() * length.hashCode() * width.hashCode() * mappedManufacturerUC9.hashCode();
73
        } else {
74
            return super.hashCode();
75
        }
76
    }
77
}
78
}
(-)jpa/eclipselink.jpa.test/src/org/eclipse/persistence/testing/models/jpa/metamodel/GalacticPosition.java (+13 lines)
Lines 15-26 Link Here
15
 ******************************************************************************/  
15
 ******************************************************************************/  
16
package org.eclipse.persistence.testing.models.jpa.metamodel;
16
package org.eclipse.persistence.testing.models.jpa.metamodel;
17
17
18
import static javax.persistence.FetchType.EAGER;
18
import static javax.persistence.InheritanceType.JOINED;
19
import static javax.persistence.InheritanceType.JOINED;
19
20
20
import javax.persistence.Column;
21
import javax.persistence.Column;
21
import javax.persistence.EmbeddedId;
22
import javax.persistence.EmbeddedId;
22
import javax.persistence.Entity;
23
import javax.persistence.Entity;
23
import javax.persistence.Inheritance;
24
import javax.persistence.Inheritance;
25
import javax.persistence.ManyToOne;
24
import javax.persistence.Table;
26
import javax.persistence.Table;
25
import javax.persistence.Version;
27
import javax.persistence.Version;
26
28
Lines 52-57 Link Here
52
    @Column(name="GALACTIC_VERSION")
54
    @Column(name="GALACTIC_VERSION")
53
    private int version;
55
    private int version;
54
    
56
    
57
    // The M:1 side is the owning side for "positionUC12"
58
    @ManyToOne(fetch=EAGER)
59
/*    @JoinTable(name="CMP3_MM_COMPUTER_MM_GALACTIC", 
60
            joinColumns = @JoinColumn(name="GALACTIC_ID"), 
61
            inverseJoinColumns = @JoinColumn(name="COMPUTER_ID"))*/   
62
    private Computer computerUC12;
63
64
    // Unidirectional ManyToOne becomes a ManyToMany (no mappedBy on the inverse side)
65
    @ManyToOne(fetch=EAGER)
66
    private Computer computerUniUC13;
67
    
55
    // Unidirectional OneToOne
68
    // Unidirectional OneToOne
56
    // There is no get/set method on purpose - for testing
69
    // There is no get/set method on purpose - for testing
57
//    @OneToOne(fetch=EAGER)
70
//    @OneToOne(fetch=EAGER)
(-)jpa/eclipselink.jpa.test/src/org/eclipse/persistence/testing/models/jpa/metamodel/Manufacturer.java (+4 lines)
Lines 65-74 Link Here
65
    // UC 1a: Generics KV set, no @MapKey present, PK is singular field
65
    // UC 1a: Generics KV set, no @MapKey present, PK is singular field
66
    @OneToMany(cascade=ALL, mappedBy="mappedEmployerUC1a")
66
    @OneToMany(cascade=ALL, mappedBy="mappedEmployerUC1a")
67
    private Map<String, HardwareDesigner> hardwareDesignersMapUC1a;
67
    private Map<String, HardwareDesigner> hardwareDesignersMapUC1a;
68
    
68
    // UC 2: Generics KV set, @MapKey is present
69
    // UC 2: Generics KV set, @MapKey is present
69
    @OneToMany(cascade=ALL, mappedBy="mappedEmployerUC2")
70
    @OneToMany(cascade=ALL, mappedBy="mappedEmployerUC2")
70
    @MapKey(name="name")
71
    @MapKey(name="name")
71
    private Map<String, HardwareDesigner> hardwareDesignersMapUC2;
72
    private Map<String, HardwareDesigner> hardwareDesignersMapUC2;
73
    
72
    // UC 4: No Generics KV set, @MapKey is present
74
    // UC 4: No Generics KV set, @MapKey is present
73
    @OneToMany(targetEntity=HardwareDesigner.class, cascade=ALL, mappedBy="mappedEmployerUC4")
75
    @OneToMany(targetEntity=HardwareDesigner.class, cascade=ALL, mappedBy="mappedEmployerUC4")
74
    @MapKey(name="name")
76
    @MapKey(name="name")
Lines 93-98 Link Here
93
    @OneToMany(cascade=CascadeType.ALL, mappedBy="mappedManufacturerUC9")
95
    @OneToMany(cascade=CascadeType.ALL, mappedBy="mappedManufacturerUC9")
94
    private Map<Board, Enclosure> enclosureByBoardMapUC9;
96
    private Map<Board, Enclosure> enclosureByBoardMapUC9;
95
    
97
    
98
    // UC12:  mapKey defined via generics and is a java class defined as an IdClass on the element(value) class 
99
    
96
    // Define Uppercase Object non-java.lang Basic types
100
    // Define Uppercase Object non-java.lang Basic types
97
    //private Object anObject; // Not supported in JPA
101
    //private Object anObject; // Not supported in JPA
98
    private Boolean aBooleanObject;
102
    private Boolean aBooleanObject;
(-)jpa/eclipselink.jpa.test/src/org/eclipse/persistence/testing/tests/jpa/metamodel/MetamodelMetamodelTest.java (-23 / +19 lines)
Lines 110-116 Link Here
110
 */
110
 */
111
public class MetamodelMetamodelTest extends MetamodelTest {
111
public class MetamodelMetamodelTest extends MetamodelTest {
112
112
113
    public static final int METAMODEL_ALL_ATTRIBUTES_SIZE = 102;//100;//94;
113
    public static final int METAMODEL_ALL_ATTRIBUTES_SIZE = 108;//102;//100;//94;
114
    public static final int METAMODEL_ALL_TYPES = 40;//37;
114
    public static final int METAMODEL_ALL_TYPES = 40;//37;
115
    public static final int METAMODEL_MANUFACTURER_DECLARED_TYPES = 28;    
115
    public static final int METAMODEL_MANUFACTURER_DECLARED_TYPES = 28;    
116
    
116
    
Lines 3222-3229 Link Here
3222
                // http://wiki.eclipse.org/EclipseLink/Development/JPA_2.0/metamodel_api#DI_63:_20090824:_Add_Map_support_for_.40MapKey_to_MapAttribute
3222
                // http://wiki.eclipse.org/EclipseLink/Development/JPA_2.0/metamodel_api#DI_63:_20090824:_Add_Map_support_for_.40MapKey_to_MapAttribute
3223
                // Key is the primary key (PK) of the target entity - in this case HardwareDesigner which inherits its @Id from the Person @MappedSuperclass as '''Integer'''.
3223
                // Key is the primary key (PK) of the target entity - in this case HardwareDesigner which inherits its @Id from the Person @MappedSuperclass as '''Integer'''.
3224
                Type keyType = anAttribute.getKeyType(); 
3224
                Type keyType = anAttribute.getKeyType(); 
3225
                //assertEquals(String.class, keyJavaType); // When @MapKey(name="name") is present
3225
                assertEquals(String.class, keyJavaType); // When @MapKey(name="name") is present - or generics are set
3226
                assertEquals(Integer.class, keyJavaType); // When @MapKey is not present - we default to the PK
3226
                //assertEquals(Integer.class, keyJavaType); // When @MapKey or generics are not present - we default to the PK
3227
                assertNotNull(keyType);
3227
                assertNotNull(keyType);
3228
                assertTrue(keyType instanceof Type);
3228
                assertTrue(keyType instanceof Type);
3229
                assertEquals(Type.PersistenceType.BASIC, keyType.getPersistenceType());
3229
                assertEquals(Type.PersistenceType.BASIC, keyType.getPersistenceType());
Lines 3290-3297 Link Here
3290
                // http://wiki.eclipse.org/EclipseLink/Development/JPA_2.0/metamodel_api#DI_63:_20090824:_Add_Map_support_for_.40MapKey_to_MapAttribute
3290
                // http://wiki.eclipse.org/EclipseLink/Development/JPA_2.0/metamodel_api#DI_63:_20090824:_Add_Map_support_for_.40MapKey_to_MapAttribute
3291
                // Key is the primary key (PK) of the target entity - in this case HardwareDesigner which inherits its @Id from the Person @MappedSuperclass as '''Integer'''.
3291
                // Key is the primary key (PK) of the target entity - in this case HardwareDesigner which inherits its @Id from the Person @MappedSuperclass as '''Integer'''.
3292
                Type keyType = anAttribute.getKeyType(); 
3292
                Type keyType = anAttribute.getKeyType(); 
3293
                //assertEquals(String.class, keyJavaType); // When @MapKey(name="name") is present
3293
                assertEquals(String.class, keyJavaType); // When @MapKey(name="name") is present - or generics are set
3294
                assertEquals(Integer.class, keyJavaType); // When @MapKey is not present - we default to the PK
3294
                //assertEquals(Integer.class, keyJavaType); // When @MapKey or generics are not present - we default to the PK
3295
                assertNotNull(keyType);
3295
                assertNotNull(keyType);
3296
                assertTrue(keyType instanceof Type);
3296
                assertTrue(keyType instanceof Type);
3297
                assertEquals(Type.PersistenceType.BASIC, keyType.getPersistenceType());                
3297
                assertEquals(Type.PersistenceType.BASIC, keyType.getPersistenceType());                
Lines 4241-4248 Link Here
4241
                // http://wiki.eclipse.org/EclipseLink/Development/JPA_2.0/metamodel_api#DI_63:_20090824:_Add_Map_support_for_.40MapKey_to_MapAttribute
4241
                // http://wiki.eclipse.org/EclipseLink/Development/JPA_2.0/metamodel_api#DI_63:_20090824:_Add_Map_support_for_.40MapKey_to_MapAttribute
4242
                // Key is the primary key (PK) of the target entity - in this case HardwareDesigner which inherits its @Id from the Person @MappedSuperclass as '''Integer'''.
4242
                // Key is the primary key (PK) of the target entity - in this case HardwareDesigner which inherits its @Id from the Person @MappedSuperclass as '''Integer'''.
4243
                Type keyType = anAttribute.getKeyType(); 
4243
                Type keyType = anAttribute.getKeyType(); 
4244
                //assertEquals(String.class, keyJavaType); // When @MapKey(name="name") is present
4244
                assertEquals(String.class, keyJavaType); // When @MapKey(name="name") is present - or generics are set
4245
                assertEquals(Integer.class, keyJavaType); // When @MapKey is not present - we default to the PK
4245
                //assertEquals(Integer.class, keyJavaType); // When @MapKey or generics are not present - we default to the PK
4246
                assertNotNull(keyType);
4246
                assertNotNull(keyType);
4247
                assertTrue(keyType instanceof Type);
4247
                assertTrue(keyType instanceof Type);
4248
                assertEquals(Type.PersistenceType.BASIC, keyType.getPersistenceType());
4248
                assertEquals(Type.PersistenceType.BASIC, keyType.getPersistenceType());
Lines 4283-4290 Link Here
4283
                //@OneToMany(cascade=ALL, mappedBy="mappedEmployerUC1a")
4283
                //@OneToMany(cascade=ALL, mappedBy="mappedEmployerUC1a")
4284
                //private Map<String, HardwareDesigner> hardwareDesignersMapUC1a;
4284
                //private Map<String, HardwareDesigner> hardwareDesignersMapUC1a;
4285
                Type keyType = anAttribute.getKeyType(); 
4285
                Type keyType = anAttribute.getKeyType(); 
4286
                //assertEquals(String.class, keyJavaType); // When @MapKey(name="name") is present
4286
                assertEquals(String.class, keyJavaType); // When @MapKey(name="name") is present - or generics are set
4287
                assertEquals(Integer.class, keyJavaType); // When @MapKey is not present - we default to the PK
4287
                //assertEquals(Integer.class, keyJavaType); // When @MapKey or generics are not present - we default to the PK
4288
                assertNotNull(keyType);
4288
                assertNotNull(keyType);
4289
                assertTrue(keyType instanceof Type);
4289
                assertTrue(keyType instanceof Type);
4290
                assertEquals(Type.PersistenceType.BASIC, keyType.getPersistenceType());
4290
                assertEquals(Type.PersistenceType.BASIC, keyType.getPersistenceType());
Lines 4412-4419 Link Here
4412
                // Same as UC1a - that is missing the @MapKey
4412
                // Same as UC1a - that is missing the @MapKey
4413
                //private Map<String, HardwareDesigner> hardwareDesignersMapUC7;
4413
                //private Map<String, HardwareDesigner> hardwareDesignersMapUC7;
4414
                Type keyType = anAttribute.getKeyType(); 
4414
                Type keyType = anAttribute.getKeyType(); 
4415
                //assertEquals(String.class, keyJavaType); // When @MapKey(name="name") is present
4415
                assertEquals(String.class, keyJavaType); // When @MapKey(name="name") is present - or generics are set
4416
                assertEquals(Integer.class, keyJavaType); // When @MapKey is not present - we default to the PK
4416
                //assertEquals(Integer.class, keyJavaType); // When @MapKey or generics are not present - we default to the PK
4417
                assertNotNull(keyType);
4417
                assertNotNull(keyType);
4418
                assertTrue(keyType instanceof Type);
4418
                assertTrue(keyType instanceof Type);
4419
                assertEquals(Type.PersistenceType.BASIC, keyType.getPersistenceType());
4419
                assertEquals(Type.PersistenceType.BASIC, keyType.getPersistenceType());
Lines 4455-4462 Link Here
4455
                // Same as UC1a - that is missing the @MapKey name attribute
4455
                // Same as UC1a - that is missing the @MapKey name attribute
4456
                //private Map<String, HardwareDesigner> hardwareDesignersMapUC8;
4456
                //private Map<String, HardwareDesigner> hardwareDesignersMapUC8;
4457
                Type keyType = anAttribute.getKeyType(); 
4457
                Type keyType = anAttribute.getKeyType(); 
4458
                //assertEquals(String.class, keyJavaType); // When @MapKey(name="name") is present
4458
                //assertEquals(String.class, keyJavaType); // When @MapKey(name="name") is present - or generics are set
4459
                assertEquals(Integer.class, keyJavaType); // When @MapKey is not present or missing name attribute - we default to the PK
4459
                assertEquals(Integer.class, keyJavaType); // When @MapKey or generics are not present - we default to the PK
4460
                assertNotNull(keyType);
4460
                assertNotNull(keyType);
4461
                assertTrue(keyType instanceof Type);
4461
                assertTrue(keyType instanceof Type);
4462
                assertEquals(Type.PersistenceType.BASIC, keyType.getPersistenceType());
4462
                assertEquals(Type.PersistenceType.BASIC, keyType.getPersistenceType());
Lines 4542-4549 Link Here
4542
                // http://wiki.eclipse.org/EclipseLink/Development/JPA_2.0/metamodel_api#DI_63:_20090824:_Add_Map_support_for_.40MapKey_to_MapAttribute
4542
                // http://wiki.eclipse.org/EclipseLink/Development/JPA_2.0/metamodel_api#DI_63:_20090824:_Add_Map_support_for_.40MapKey_to_MapAttribute
4543
                // Key is the primary key (PK) of the target entity - in this case HardwareDesigner which inherits its @Id from the Person @MappedSuperclass as '''Integer'''.
4543
                // Key is the primary key (PK) of the target entity - in this case HardwareDesigner which inherits its @Id from the Person @MappedSuperclass as '''Integer'''.
4544
                Type keyType = anAttribute.getKeyType(); 
4544
                Type keyType = anAttribute.getKeyType(); 
4545
                //assertEquals(String.class, keyJavaType); // When @MapKey(name="name") is present
4545
                assertEquals(String.class, keyJavaType); // When @MapKey(name="name") is present - or generics are set
4546
                assertEquals(Integer.class, keyJavaType); // When @MapKey is not present - we default to the PK
4546
                //assertEquals(Integer.class, keyJavaType); // When @MapKey or generics are not present - we default to the PK
4547
                assertNotNull(keyType);
4547
                assertNotNull(keyType);
4548
                assertTrue(keyType instanceof Type);
4548
                assertTrue(keyType instanceof Type);
4549
                assertEquals(Type.PersistenceType.BASIC, keyType.getPersistenceType());
4549
                assertEquals(Type.PersistenceType.BASIC, keyType.getPersistenceType());
Lines 4585-4592 Link Here
4585
                //@OneToMany(cascade=ALL, mappedBy="mappedEmployerUC1a")
4585
                //@OneToMany(cascade=ALL, mappedBy="mappedEmployerUC1a")
4586
                //private Map<String, HardwareDesigner> hardwareDesignersMapUC1a;
4586
                //private Map<String, HardwareDesigner> hardwareDesignersMapUC1a;
4587
                Type keyType = anAttribute.getKeyType(); 
4587
                Type keyType = anAttribute.getKeyType(); 
4588
                //assertEquals(String.class, keyJavaType); // When @MapKey(name="name") is present
4588
                assertEquals(String.class, keyJavaType); // When @MapKey(name="name") is present - or generics are set
4589
                assertEquals(Integer.class, keyJavaType); // When @MapKey is not present - we default to the PK
4589
                //assertEquals(Integer.class, keyJavaType); // When @MapKey or generics are not present - we default to the PK
4590
                assertNotNull(keyType);
4590
                assertNotNull(keyType);
4591
                assertTrue(keyType instanceof Type);
4591
                assertTrue(keyType instanceof Type);
4592
                assertEquals(Type.PersistenceType.BASIC, keyType.getPersistenceType());
4592
                assertEquals(Type.PersistenceType.BASIC, keyType.getPersistenceType());
Lines 4674-4681 Link Here
4674
                assertNotNull(keyType);
4674
                assertNotNull(keyType);
4675
                assertTrue(keyType instanceof Type);
4675
                assertTrue(keyType instanceof Type);
4676
                assertEquals(Type.PersistenceType.BASIC, keyType.getPersistenceType());
4676
                assertEquals(Type.PersistenceType.BASIC, keyType.getPersistenceType());
4677
                
4678
                
4679
            } catch (IllegalArgumentException iae) {
4677
            } catch (IllegalArgumentException iae) {
4680
                //iae.printStackTrace();
4678
                //iae.printStackTrace();
4681
                exceptionThrown = true;
4679
                exceptionThrown = true;
Lines 4713-4725 Link Here
4713
                // Same as UC1a - that is missing the @MapKey
4711
                // Same as UC1a - that is missing the @MapKey
4714
                //private Map<String, HardwareDesigner> hardwareDesignersMapUC7;
4712
                //private Map<String, HardwareDesigner> hardwareDesignersMapUC7;
4715
                Type keyType = anAttribute.getKeyType(); 
4713
                Type keyType = anAttribute.getKeyType(); 
4716
                //assertEquals(String.class, keyJavaType); // When @MapKey(name="name") is present
4714
                assertEquals(String.class, keyJavaType); // When @MapKey(name="name") is present - or generics are set
4717
                assertEquals(Integer.class, keyJavaType); // When @MapKey is not present - we default to the PK
4715
                //assertEquals(Integer.class, keyJavaType); // When @MapKey or generics are not present - we default to the PK
4718
                assertNotNull(keyType);
4716
                assertNotNull(keyType);
4719
                assertTrue(keyType instanceof Type);
4717
                assertTrue(keyType instanceof Type);
4720
                assertEquals(Type.PersistenceType.BASIC, keyType.getPersistenceType());
4718
                assertEquals(Type.PersistenceType.BASIC, keyType.getPersistenceType());
4721
                
4722
                
4723
            } catch (IllegalArgumentException iae) {
4719
            } catch (IllegalArgumentException iae) {
4724
                //iae.printStackTrace();
4720
                //iae.printStackTrace();
4725
                exceptionThrown = true;
4721
                exceptionThrown = true;
(-)jpa/eclipselink.jpa.test/src/org/eclipse/persistence/testing/tests/jpa/metamodel/MetamodelTableCreator.java (+24 lines)
Lines 1100-1106 Link Here
1100
        field13.setIsIdentity(false);
1100
        field13.setIsIdentity(false);
1101
        table.addField(field13);
1101
        table.addField(field13);
1102
        
1102
        
1103
        // 1:m does not require a JoinTable - only a JoinColumn
1104
        FieldDefinition field6 = new FieldDefinition();
1105
        field6.setName("COMPUTERUC12_COMPUTER_ID");
1106
        field6.setTypeName("NUMERIC");
1107
        field6.setSize(15);
1108
        field6.setShouldAllowNull(false);
1109
        field6.setIsPrimaryKey(false);
1110
        field6.setUnique(false);
1111
        field6.setIsIdentity(false);
1112
        field6.setForeignKeyFieldName("CMP3_MM_COMPUTER.COMPUTER_ID");
1113
        table.addField(field6);        
1114
1115
        // 1:m does not require a JoinTable - only a JoinColumn
1116
        FieldDefinition field7 = new FieldDefinition();
1117
        field7.setName("COMPUTERUNIUC13_COMPUTER_ID");
1118
        field7.setTypeName("NUMERIC");
1119
        field7.setSize(15);
1120
        field7.setShouldAllowNull(false);
1121
        field7.setIsPrimaryKey(false);
1122
        field7.setUnique(false);
1123
        field7.setIsIdentity(false);
1124
        field7.setForeignKeyFieldName("CMP3_MM_COMPUTER.COMPUTER_ID");
1125
        table.addField(field7);        
1103
        
1126
        
1127
        
1104
        return table;
1128
        return table;
1105
    }
1129
    }
1106
1130
(-)jpa/org.eclipse.persistence.jpa/src/org/eclipse/persistence/internal/jpa/metamodel/ManagedTypeImpl.java (-3 / +3 lines)
Lines 1109-1115 Link Here
1109
     * Initialization should occur after all types in the metamodel have been created already.
1109
     * Initialization should occur after all types in the metamodel have been created already.
1110
     * 
1110
     * 
1111
     */
1111
     */
1112
    protected void initialize() { // TODO: Check all is*Policy() calls
1112
    protected void initialize() { // Future: Check all is*Policy() calls
1113
        /*
1113
        /*
1114
         * Design Issue 37 and 58:
1114
         * Design Issue 37 and 58:
1115
         * http://wiki.eclipse.org/EclipseLink/Development/JPA_2.0/metamodel_api#DI_37:_20090708:_CollectionAttribute_acts_as_a_peer_of_Map.2C_Set.2C_List_but_should_be_a_super_interface
1115
         * http://wiki.eclipse.org/EclipseLink/Development/JPA_2.0/metamodel_api#DI_37:_20090708:_CollectionAttribute_acts_as_a_peer_of_Map.2C_Set.2C_List_but_should_be_a_super_interface
Lines 1148-1155 Link Here
1148
                CollectionMapping colMapping = (CollectionMapping) mapping;
1148
                CollectionMapping colMapping = (CollectionMapping) mapping;
1149
                ContainerPolicy collectionContainerPolicy = colMapping.getContainerPolicy();
1149
                ContainerPolicy collectionContainerPolicy = colMapping.getContainerPolicy();
1150
                if (collectionContainerPolicy.isMapPolicy() || collectionContainerPolicy.isDirectMapPolicy()) {
1150
                if (collectionContainerPolicy.isMapPolicy() || collectionContainerPolicy.isDirectMapPolicy()) {
1151
                    // Handle Map type mappings
1151
                    // Handle the 3 Map type mappings (policy.isMappedKeyMapPolicy()) is handled by isMapPolicy())
1152
                    member = new MapAttributeImpl(this, colMapping, true);
1152
                    member = new MapAttributeImpl((IdentifiableTypeImpl)this, colMapping, true);
1153
                    // check mapping.attributeAcessor.attributeField.type=Collection
1153
                    // check mapping.attributeAcessor.attributeField.type=Collection
1154
                } else if (collectionContainerPolicy.isListPolicy()) { 
1154
                } else if (collectionContainerPolicy.isListPolicy()) { 
1155
                    /**
1155
                    /**
(-)jpa/org.eclipse.persistence.jpa/src/org/eclipse/persistence/internal/jpa/metamodel/MapAttributeImpl.java (-28 / +133 lines)
Lines 14-20 Link Here
14
 *       Map, ElementCollection and Embeddable types on MappedSuperclass descriptors
14
 *       Map, ElementCollection and Embeddable types on MappedSuperclass descriptors
15
 *       - 266912: JPA 2.0 Metamodel API (part of the JSR-317 EJB 3.1 Criteria API)
15
 *       - 266912: JPA 2.0 Metamodel API (part of the JSR-317 EJB 3.1 Criteria API)
16
 *     11/05/2009-2.0  mobrien - DI 86: MapKey support when only generics
16
 *     11/05/2009-2.0  mobrien - DI 86: MapKey support when only generics
17
 *         are used to determine the keyType for an IdClass that used an embeddable   
17
 *         are used to determine the keyType for an IdClass that used an embeddable 
18
 *     11/10/2009-2.0  mobrien - DI 98: Use keyMapping on MappedKeyMappedContainerPolicy
19
 *         keep workaround for bug# 294765 for Basic keyType when MapKey annotation not specified.
20
 *         keep workaround for bug# 294811 for Entity, Embeddable, Transient keyType support 
21
 *           when MapKey name attribute not specified (MapContainerPolicy) 
22
 *         add BasicMap support via DirectMapContainerPolicy         
18
 ******************************************************************************/
23
 ******************************************************************************/
19
package org.eclipse.persistence.internal.jpa.metamodel;
24
package org.eclipse.persistence.internal.jpa.metamodel;
20
25
Lines 60-115 Link Here
60
     * @param managedType
65
     * @param managedType
61
     * @param mapping
66
     * @param mapping
62
     */
67
     */
63
    protected MapAttributeImpl(ManagedTypeImpl<X> managedType, CollectionMapping mapping) {
68
    protected MapAttributeImpl(IdentifiableTypeImpl<X> managedType, CollectionMapping mapping) {
64
        this(managedType, mapping, false);
69
        this(managedType, mapping, false);
65
    }
70
    }
66
71
67
    /**
72
    /**
68
     * INTERNAL:
73
     * INTERNAL:
69
     * @param managedType
74
     * Create a new MapAttribute instance.
70
     * @param mapping
75
     * The elementType field is instantiated in the superclass.
71
     * @param validationEnabled
76
     * The keyType field is instantiated in this constructor by using one of the following
77
     * A) MapContainerPolicy by consulting the keyField or PK class
78
     * B) MappedKeyMapContainerPolicy by using the mapKeyTargetType on the keyMapping or the attributeClassification on the attributeAccessor 
79
     * @param managedType - the owning type (EmbeddableTypes do not support mappings)
80
     * @param mapping - contains the mapping policy
81
     * @param validationEnabled - report errors in the metamodel
72
     */
82
     */
73
    protected MapAttributeImpl(ManagedTypeImpl<X> managedType, CollectionMapping mapping, boolean validationEnabled) {
83
    protected MapAttributeImpl(IdentifiableTypeImpl<X> managedType, CollectionMapping mapping, boolean validationEnabled) {
74
        // Set the managedType (X or owning Type)
84
        // Set the managedType (X or owning Type) - Note: EmbeddableTypes are only supported as Map keys here
75
        super(managedType, mapping, validationEnabled);
85
        super(managedType, mapping, validationEnabled);
76
        // Override the elementType (V or Map value)
77
        // We need to set the keyType Type that represents the type of the Map key for this mapping
86
        // We need to set the keyType Type that represents the type of the Map key for this mapping
78
        ContainerPolicy policy = mapping.getContainerPolicy();
87
        ContainerPolicy policy = mapping.getContainerPolicy();
88
        Class<?> javaClass = null;
89
        MapKeyMapping keyMapping = null; 
79
        ClassDescriptor policyElementDescriptor = policy.getElementDescriptor();
90
        ClassDescriptor policyElementDescriptor = policy.getElementDescriptor();
80
        Object policyKeyType = policy.getKeyType(); // returns a Class<?> or descriptor (via AggregateObjectMapping)        
91
        Object policyKeyType = null;
81
        Type<?> aKeyType = null;
92
  
82
        // Default to Object class for any variant cases that are not handled
93
        /**
83
        Class<?> javaClass = null;
94
         * Note: the (at) sign for annotations has been replaced by the & sign for javadoc processing.
95
         * 
96
         * We have the following policy structure and behavior
97
         * ContainerPolicy (A)
98
         *    +=== InterfaceContainerPolicy (A)
99
         *             +=== DirectMapContainerPolicy
100
         *             +=== MapContainerPolicy (use keyField or PK class)
101
         *                      +=== MappedKeyMapContainerPolicy (use keyMapping.mapKeyTargetType or attributeClassification) 
102
         *   
103
         *   Use Case segmentation for keyType 
104
                A) MapContainerPolicy 
105
                    A1) keyField set (lazy loaded) 
106
                        UC2 - name attribute defines mapKey, generics are not required and are secondary 
107
                            &OneToMany(cascade=ALL, mappedBy="mappedEmployerUC2") 
108
                            &MapKey(name="name") 
109
                            private Map<String, HardwareDesigner> hardwareDesignersMapUC2; 
110
                        UC4 - name attribute defines mapKey, generics are not required 
111
                            &OneToMany(targetEntity=HardwareDesigner.class, cascade=ALL, mappedBy="mappedEmployerUC4") 
112
                            &MapKey(name="name") 
113
                            private Map hardwareDesignersMapUC4; 
114
                        UC8 - mapKey defined via generics  
115
                            &OneToMany(cascade=ALL, mappedBy="mappedEmployerUC8") 
116
                            &MapKey // name attribute will default to "id" 
117
                            private Map<Integer, HardwareDesigner> hardwareDesignersMapUC8; 
118
                    A2) Use mapPolicy.elementDescriptor.cmppolicy.pkClass (since KeyField == null) 
119
                        UC10 - mapKey defined via generics and is a java class defined as an IdClass on the element(value) class - here Enclosure 
120
                            &OneToMany(mappedBy="computer", cascade=ALL, fetch=EAGER) 
121
                            &MapKey // key defaults to an instance of the composite pk class 
122
                            private Map<EnclosureIdClassPK, Enclosure> enclosures;
123
                            &Entity &IdClass(EnclosureIdClassPK.class) public class Enclosure {}
124
                        UC11 - or (get keyClass from mapping if the Id is a get() function) 
125
                            TBD - use reflection 
126
                B) MappedKeyMapContainerPolicy 
127
                    B1) mapKeyTargetType set on the keyMapping - normal processing 
128
                        UC9 - mapKey defined by generics in the absence of a MapKey annotation
129
                            &OneToMany(cascade=CascadeType.ALL, mappedBy="mappedManufacturerUC9") 
130
                            private Map<Board, Enclosure> enclosureByBoardMapUC9; 
131
                        UC13 - mapKey defined by generics in the absence of a MapKey name attribute (unidirectional M:1 becomes M:M)                        
132
                           &MapKey // on Computer inverse
133
                           private Map<EmbeddedPK, GalacticPosition> position;
134
                           &ManyToOne(fetch=EAGER) // on GalacticPosition owner
135
                           private Computer computer;
136
                    B2) - secondary processing for Basic (DirectToField) mappings
137
                    Use AttributeClassification (since keyMapping.attributeAccessor.attributeClass == null) 
138
                        UC1a - mapKey defined by generics in the absence of a MapKey annotation
139
                            &OneToMany(cascade=ALL, mappedBy="mappedEmployerUC1a") 
140
                            private Map<String, HardwareDesigner> hardwareDesignersMapUC1a; 
141
                        UC7 - mapKey defined by generics in the absence of a MapKey annotation 
142
                            &OneToMany(targetEntity=HardwareDesigner.class, cascade=ALL, mappedBy="mappedEmployerUC7") 
143
                            private Map<String, HardwareDesigner> hardwareDesignersMapUC7; 
144
         */        
145
        // Step 1: We check via the ContainerPolicy interface for a mapPolicy for the keyMapping (covers MappedKeyMapContainerPolicy and its superclass MapContainerPolicy
146
        if(policy.isMapPolicy() || policy.isDirectMapPolicy()) {
147
            // check for Either a generic Map (MapContainerPolicy) or specific MappedKeyMapContainerPolicy subclass
148
            if(policy.isMappedKeyMapPolicy()) {
149
                // See UC9
150
                // The cast below is unavoidable because getKeyMapping() is not overridden from the MapContainerPolicy superclass
151
                keyMapping = ((MappedKeyMapContainerPolicy)policy).getKeyMapping();
152
                policyKeyType = keyMapping.getMapKeyTargetType();
153
                /**
154
                 * If the policyKeyType is not found - it is because the keyMapping is a Basic (DirectToFieldMapping implements MapKeyMapping).
155
                 * Normally we get the pk type via the referenceClass on a OneToOneMapping for example.
156
                 * However, in this case MappedKeyMapContainerPolicy.keyMapping.attributeAccessor.attributeField is null - 
157
                 * we workaround this by getting the key from the attributeClassification instead.
158
                 * See UC1a, UC7
159
                 */
160
                if(null == policyKeyType) {
161
                    // This workaround for bug# 294765 should be moved up into AbstractDirectMapping.getMapKeyTargetType
162
                    policyKeyType = ((DatabaseMapping)keyMapping).getAttributeClassification();
163
                }
164
            } else {
165
                /**
166
                 * Assume we have a MapContainerPolicy general superclass with a lazy-loaded keyType 
167
                 *   or a DirectMapContainerPolicy using a &BasicMap
168
                 * See UC2, UC4, UC8, UC13 (unidirectional ManyToOne becomes ManyToMany)
169
                 * returns a Class<?> or descriptor (via AggregateObjectMapping) or null in 2 cases -
170
                 *   1 - if the ContainerPolicy does not support maps
171
                 *   2 - If the keyField is null (we handle this below by consulting the CMPPolicy)
172
                 */
173
                policyKeyType = policy.getKeyType(); 
174
            }
175
        }
176
        
177
        /**
178
         * Step 2: We determine the java class from the policyKeyType (class or ClassDecriptor) 
179
         * We also perform alternate keyType lookup for the case where 
180
         * the name attribute is not specified in a MapKey annotation where 
181
         * the map key is one of the following (via the MapContainerPolicy superclass of MappedKeyMapContainerPolicy)
182
         * - map key is an Entity with an IdClass
183
         * - map key is Java class that is defined as the IdClass of an Entity (above)
184
         */
84
        if(null == policyKeyType) {
185
        if(null == policyKeyType) {
85
            // No policy key type = IdClass (use CMP3Policy.pkClass)
186
            // The keyType will be null on a MapContainerPolicy when the keyField is null - usually a composite key
86
            if(managedType.isIdentifiableType()) {
187
            // Use the PK of the element - not the one on the managedType
87
                // Use the CMPPolicy on the element not the one on the managedType
188
            // Case: @MapKey private Map<K,V> // no name column specified
88
                if(policyElementDescriptor != null && 
189
            if(policyElementDescriptor != null && policyElementDescriptor.getCMPPolicy() != null) {
89
                        policyElementDescriptor.getCMPPolicy() != null) {
190
                // See UC9, UC10, UC12(embeddable), UC13
90
                    javaClass = policy.getElementDescriptor().getCMPPolicy().getPKClass();
191
                // This workaround for bug# 294811 should be moved up into the MapKeyMapping.getMapKeyTargetType() interface method
192
                javaClass = policy.getElementDescriptor().getCMPPolicy().getPKClass();
193
            }
194
            // Pending reproduction case: @MapKey private Map<K,V> // no name column specified and the PK is defined by a method
195
            if(null == javaClass) {
196
                if(policy.isMappedKeyMapPolicy()) {
197
                    // See UC10, UC11
198
                    javaClass = getOwningPKTypeWhenMapKeyAnnotationMissingOrDefaulted(
199
                            (MappedKeyMapContainerPolicy)policy);
91
                }
200
                }
92
                if(null == javaClass) {
93
                    // check for a @MapKeyClass annotation
94
                    if(policy.isMappedKeyMapPolicy()) {                            
95
                        javaClass = getOwningPKTypeWhenMapKeyAnnotationMissingOrDefaulted(
96
                                (MappedKeyMapContainerPolicy)policy);
97
                    }
98
                }
99
            }
201
            }
100
        } else {            
202
        } else {
203
            // Process the policyKeyType normally
101
            if(policyKeyType instanceof ClassDescriptor) { // from AggregateObjectMapping
204
            if(policyKeyType instanceof ClassDescriptor) { // from AggregateObjectMapping
102
                javaClass = ((ClassDescriptor)policyKeyType).getJavaClass();
205
                javaClass = ((ClassDescriptor)policyKeyType).getJavaClass();
103
            } else {
206
            } else {
104
                javaClass = (Class<?>)policyKeyType;
207
                javaClass = (Class<?>)policyKeyType;
105
            }            
208
            }            
106
        }
209
        }
210
 
211
        // Optional: catch any holes in our keyType logic (8 hits in clover coverage)
107
        if(null == javaClass) {
212
        if(null == javaClass) {
108
            javaClass = Object.class;
213
            javaClass = Object.class;
109
        }                                
214
        }                                
110
        
215
        
111
        aKeyType = getMetamodel().getType(javaClass);
216
        // Step 3: We wrap the java type in a Metamodel Type instance or retrieve an existing Type
112
        this.keyType = (Type<K>) aKeyType;
217
        this.keyType = (Type<K>) getMetamodel().getType(javaClass);
113
    }
218
    }
114
219
115
    /**
220
    /**

Return to bug 266912