Skip to main content

"Non-entity" relationship

3 replies [Last post]
bgladish
Offline
Joined: 2007-04-12

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 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.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
mvatkina
Offline
Joined: 2005-04-04

Hi Brian,

Did you make it working? I think there was a bug in TopLink Essentials, where a subclass couldn't be used in a relationship. A Mapped Superclass can't be target of a relationship according to the spec (see 2.1.9.2 Mapped Superclasses).

Also, I'm wondering if it works to map a discrim field and designate it a @DiscriminatorColumn?

Regards,
-marina

smshashi
Offline
Joined: 2009-03-24

I had a similar error. The main cause for "non-entity" is no entry for the entity in the persistence.xml. Add the entry and it should work.

abinmd
Offline
Joined: 2011-11-22

i had the same error in Eclipselink



Exception Description: [CLASS] uses a non-entity [CLASS] as target entity in the relationship attribute [field crossoverCarrier].

at org.eclipse.persistence.exceptions.ValidationException.nonEntityTargetInRelationship(ValidationException.java:1343)

at org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.RelationshipAccessor.getReferenceDescriptor(RelationshipAccessor.java:485)

at org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.ObjectAccessor.processOneToOneForeignKeyRelationship(ObjectAccessor.java:627)

at org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.ObjectAccessor.processOwningMappingKeys(ObjectAccessor.java:686)

at org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.OneToOneAccessor.process(OneToOneAccessor.java:156)

at org.eclipse.persistence.internal.jpa.metadata.MetadataProject.processOwningRelationshipAccessors(MetadataProject.java:1432)

at org.eclipse.persistence.internal.jpa.metadata.MetadataProject.processStage3(MetadataProject.java:1667)

at org.eclipse.persistence.internal.jpa.metadata.MetadataProcessor.processORMMetadata(MetadataProcessor.java:521)

at org.eclipse.persistence.internal.jpa.deployment.PersistenceUnitProcessor.processORMetadata(PersistenceUnitProcessor.java:526)