users@glassfish.java.net

"Non-entity" relationship

From: <glassfish_at_javadesktop.org>
Date: Fri, 24 Aug 2007 22:44:52 PDT

I have the following situation:

@Entity
@Table(name="M")
@Inheritance(strategy=JOINED)
 @DiscriminatorColumn(name="discrim", discriminatorType=INTEGER) class M abstract {
        @Id
        @Column(name="MId")
        private String mId;
        
        private int discrim;
        ...
}

@MappedSuperClass class NM extends M {
        @OneToMany(cascade=REMOVE, mappedBy="namedM")
        protected List<Name> names;
        ...
}

@Entity
@Table(name="E")
@DiscriminatorValue(value="10000")
@PrimaryKeyJoinColumn(name="EId")
public class E extends NM {
}

@Entity
@Table(name="Names")
@DiscriminatorValue(value="10001")
@PrimaryKeyJoinColumn(name="NameId")
public class Name extends M {
        @Column(name="namedMID")
        protected String namedM = "";
}

At runtime their is an exception. I believe this is the relevant portion:

Caused by: Exception [TOPLINK-7250] (Oracle TopLink Essentials - 2.0 (Build SNAPSHOT (08/22/2007))): oracle.toplink.essentials.exceptions.ValidationException
Exception Description: [class E] uses a non-entity [class Name] as target entity in the relationship attribute [protected java.util.List NM.names].
        at oracle.toplink.essentials.exceptions.ValidationException.nonEntityTargetInRelationship(ValidationException.java:1140)
        at oracle.toplink.essentials.internal.ejb.cmp3.metadata.MetadataValidator.throwNonEntityTargetInRelationship(MetadataValidator.java:321)
        at oracle.toplink.essentials.internal.ejb.cmp3.metadata.accessors.RelationshipAccessor.getReferenceDescriptor(RelationshipAccessor.java:164)
        at oracle.toplink.essentials.internal.ejb.cmp3.metadata.accessors.RelationshipAccessor.getOwningMapping(RelationshipAccessor.java:136)
        at oracle.toplink.essentials.internal.ejb.cmp3.metadata.accessors.OneToManyAccessor.process(OneToManyAccessor.java:157)
        at oracle.toplink.essentials.internal.ejb.cmp3.metadata.accessors.RelationshipAccessor.processRelationship(RelationshipAccessor.java:290)
        at oracle.toplink.essentials.internal.ejb.cmp3.metadata.MetadataProject.processRelationshipDescriptors(MetadataProject.java:579)
        at oracle.toplink.essentials.internal.ejb.cmp3.metadata.MetadataProject.process(MetadataProject.java:512)
        at oracle.toplink.essentials.internal.ejb.cmp3.metadata.MetadataProcessor.processAnnotations(MetadataProcessor.java:246)
        at oracle.toplink.essentials.ejb.cmp3.persistence.PersistenceUnitProcessor.processORMetadata(PersistenceUnitProcessor.java:370)
        at oracle.toplink.essentials.internal.ejb.cmp3.EntityManagerSetupImpl.predeploy(EntityManagerSetupImpl.java:608)
        ... 12 more

It appears that an object that is not at the top of the hierarchy cannot be referenced in a relationship. Is that by design or am I doing something wrong?

Also, I found earlier that the NM class cannot be used in a relationship - possibly for the same reason - but I think that problem was identified at compile time.

Brian

P.S. Class names have been changed and details removed, but I think this represents the core of the case. I can supply the actual code if the problem is not obvious.
[Message sent by forum member 'bgladish' (bgladish)]

http://forums.java.net/jive/thread.jspa?messageID=232582