you can also look at this
http://openjpa.apache.org/docs/latest/manual/manual.html#jpa_overview_pc_identity_hierarchy
On Wed, Jul 9, 2008 at 1:19 PM, Dain Sundstrom <[EMAIL PROTECTED]> wrote:
> On Jul 9, 2008, at 9:08 AM, Rick McGuire wrote:
>
> Found another thing I'm trying to understand. In the mapClass1x() method
>> of CmpJpaConversion, there's the following code:
>>
>> pkClass = classLoader.loadClass(bean.getPrimKeyClass());
>> MappedSuperclass superclass = null;
>> for (java.lang.reflect.Field pkField : pkClass.getFields()) {
>> String fieldName = pkField.getName();
>> int modifiers = pkField.getModifiers();
>> // the primary key fields must be public, non-static,
>> must be defined as a CMP field,
>> // AND must also exist in the class hierarchy (not
>> enforced by mapFields());
>> if (Modifier.isPublic(modifiers) &&
>> !Modifier.isStatic(modifiers) && allFields.contains(fieldName)) {
>> superclass = superclassByField.get(fieldName);
>> if (superclass == null) {
>> throw new IllegalStateException("Primary key
>> field " + fieldName + " is not defined in class " + ejbClassName + " or any
>> super classes");
>> }
>> superclass.addField(new Id(fieldName));
>> mapping.addField(new AttributeOverride(fieldName));
>> primaryKeyFields.add(fieldName);
>> }
>> }
>> if (superclass != null) {
>> superclass.setIdClass(new
>> IdClass(bean.getPrimKeyClass()));
>> }
>>
>> I have a question about the last couple of lines. If I'm reading what
>> this (and previously executed) is doing correctly, it's setting the
>> IdClass() attribute on the class that happens to define the last of the
>> primary key fields. However, if I'm reading things properly, the primary
>> key fields might not all be implemented at the same level of the class
>> hierarchy. Is there potentially a problem here if that's the case? Would
>> defining this attribute too early in the class hierarchy be a problem? That
>> is, it's possible that it might be defined at a level where not all of the
>> required fields exist yet.
>>
>
> Ya, that seems weird to me. I don't think any of the OpenEJB itests or TCK
> tests have code where the fields of the primary key class are split over the
> inheritance hierarchy. I believe it is an error if you set the IdClass is
> set in the wrong mapped superclass. I wonder if it is possible to declare
> the IdClass on the last bean in the hierarchy. Anyway, you will have to
> check the spec on this one, and may have to experiment (see JpaTest).
>
> -dain
>
--
Karan Singh Malhi