openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From angelb <>
Subject Differences in persisting ForeignKeys between OpenJPA 2.1.0 and 2.2.1
Date Wed, 22 May 2013 07:47:19 GMT
I have the following 2 Entities

public class UsersStatusCodes implements Serializable {
      private String userStatusCode;
      private String userStatusName;
      private Set<IntUsers> intUsersCollection;
     private Set<ExtUsers> extUsersCollection;

public class ExtUsers implements Serializable {
      private String extUserName;
      private String firstName;
      private String lastName;
      private String address;
      private String zipcode;
     private UsersStatusCodes statusCode;

In OpenJPA 2.1.0 I was able to persist ExtUsers object executing the
following code:

ExtUsers user=new ExtUsers();
/**StatusCode with Identity “ACTIVE” ALREADY EXISTS IN database, so there is
no need to persist it */
user.setStatusCode(new UsersStatusCodes(“ACTIVE”));
/*this was working perfectly*/

Now in OpenJPA 2.2.1 the abovementioned code generates the following

org.apache.openjpa.persistence.InvalidStateException: Encountered unmanaged
object "" in life cycle
state  unmanaged while cascading persistence via field
"" during flush.  However, this
field does not allow cascade persist. You cannot flush unmanaged objects or
graphs that have persistent associations to unmanaged objects.
Suggested actions: a) Set the cascade attribute for this field to
CascadeType.PERSIST or CascadeType.ALL (JPA annotations) or "persist" or
"all" (JPA orm.xml), 
 b) enable cascade-persist globally,
c) manually persist the related field value prior to flushing.
d) if the reference belongs to another context, allow reference to it by
setting StoreContext.setAllowReferenceToSiblingContext().

What has change between the two OpenJPA versions?
Is it still possible to persist an entity without having to load all
references in advance using find()?

Thank you

View this message in context:
Sent from the OpenJPA Users mailing list archive at

View raw message