Skip to main content
 
developerworks > Community >  Dashboard > WebSphere eXtreme Scale V6.1 User Guide > ... > ObjectGrid 6.1 cumulative fix 3 contents > NotSerializableException thrown when finding entity key classes
developerWorks
Log In   View a printable version of the current page.
Overview New to Forums Wikis
NotSerializableException thrown when finding entity key classes
Added by Chris.D.Johnson, last edited by Chris.D.Johnson on Dec 19, 2007  (view change)
Labels: 
(None)

Getting Started Examples Reference API documentation
See the WebSphere eXtreme Scale Wiki for links to up-to-date eXtreme Scale Version 7.x documentation.

If you log in with your developerWorks ID, you can leave comments and feedback for the development team.

Component EntityManager API
Software Version 6.1

Problem

Exception java.io.NotSerializableException may be thrown from the EntityManager.find method when the key class contains an entity association.

The ObjectGrid EntityManager API allows composite keys to have one or more single valued references to other entities. Composite key classes are used to allow lookups of the entities using the EntityManager.find API method and are specified using the @IdClass annotation. If the entity key contains an association to another entity using the @OneToOne or @ManyToOne annotation or XML equivalent attributes and an @IdClass is specified on the entity type, the following exception may be thrown:

com.ibm.websphere.projector.ProjectorException: Unexpected Exception retrieving value from attribute:null.
   Entity: null, Name: keyAttributeName, position: 1, expected type: class EntityClassName, actual type: KeyClassName
        at com.ibm.ws.projector.ProjectorImpl.getValueFromAttribute(ProjectorImpl.java:1160)
        at com.ibm.ws.projector.ProjectorImpl.getTupleFromEntity(ProjectorImpl.java:991)
        at com.ibm.ws.projector.ProjectorImpl.getKeyFromEntityInternal(ProjectorImpl.java:1091)
        at com.ibm.ws.projector.ProjectorImpl$4.run(ProjectorImpl.java:1085)
        at java.security.AccessController.doPrivileged(AccessController.java:193)
        at com.ibm.ws.projector.ProjectorImpl.getKeyFromEntity(ProjectorImpl.java:1083)
        ...
Caused by: java.io.NotSerializableException: EntityClassName
        at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1108)
        at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:324)
        at com.ibm.ws.projector.ProjectorUtil.reSerialize(ProjectorUtil.java:340)
        at com.ibm.ws.projector.ProjectorImpl.cloneAttribute(ProjectorImpl.java:1327)
        at com.ibm.ws.projector.ProjectorImpl.getValueFromAttribute(ProjectorImpl.java:1126)
        ... 24 more

An example of using a key class with a key association:

@Entity
@IdClass(KeyClass.class}
public class EntityClass {
  @Id String key1;
  @Id @OneToOne TargetEntity key2;
}

public class KeyClass {
  String key1;
  TargetEntity key2;
}

Cause

The EntityManager is not correctly correlating the attribute in the key class as an association type.

Workaround

Add the @OneToOne or @ManyToOne annotation to the key class attribute to match the association annotation defined on the referring entity.

public class KeyClass {
  String key1;
  @OneToOne TargetEntity key2;
}

Solution

Apply ObjectGrid cumulative intermediate fix 3.

Wiki Disclaimer and License
© Copyright IBM Corporation 2007,2010. All Rights Reserved.