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:
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.
© Copyright IBM Corporation 2007,2010. All Rights Reserved.