openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Rick Curtis <curti...@gmail.com>
Subject Re: Differences in persisting ForeignKeys between OpenJPA 2.1.0 and 2.2.1
Date Thu, 23 May 2013 14:41:51 GMT
I suspect this change might have been introduced by OPENJPA-1986[1]. Try
setting the
property openjpa.Compatibility=CheckDatabaseForCascadePersistToDetachedEntity=true
to see if this gives you the old behavior.

Thanks,
Rick

[1] https://issues.apache.org/jira/browse/OPENJPA-1986


On Wed, May 22, 2013 at 2:47 AM, angelb <abbaaba@yahoo.com> wrote:

> I have the following 2 Entities
>
> public class UsersStatusCodes implements Serializable {
>       @Id
>       @Column(name="USER_STATUS_CODE")
>       private String userStatusCode;
>       @Column(name="USER_STATUS_NAME")
>       private String userStatusName;
>       @OneToMany(mappedBy="intUserStatusCode")
>       private Set<IntUsers> intUsersCollection;
>      @OneToMany(mappedBy="statusCode")
>      private Set<ExtUsers> extUsersCollection;
> }
>
> /*****/
> public class ExtUsers implements Serializable {
>       @Id
>       @Column(name="EXT_USER_NAME")
>       private String extUserName;
>       @Column(name="FIRST_NAME")
>       private String firstName;
>       @Column(name="LAST_NAME")
>       private String lastName;
>       @Column(name="ADDRESS")
>       private String address;
>       @Column(name="ZIPCODE")
>       private String zipcode;
>      @ManyToOne
>      @JoinColumn(name="EXT_USER_STATUS_CODE")
>      private UsersStatusCodes statusCode;
> }
>
>
> In OpenJPA 2.1.0 I was able to persist ExtUsers object executing the
> following code:
>
> ExtUsers user=new ExtUsers();
> user.setExtUserName(“aaa”);
> user.setFirstName(“Fname”);
> user.setLirstName(“Lname”);
> /**StatusCode with Identity “ACTIVE” ALREADY EXISTS IN database, so there
> is
> no need to persist it */
> user.setStatusCode(new UsersStatusCodes(“ACTIVE”));
> entityManager.persist(user);
> /*this was working perfectly*/
>
> Now in OpenJPA 2.2.1 the abovementioned code generates the following
> exception:
>
> org.apache.openjpa.persistence.InvalidStateException: Encountered unmanaged
> object "gr.bog.it.iris.model.jpa.UsersStatusCodes@4d48ee83" in life cycle
> state  unmanaged while cascading persistence via field
> "gr.bog.it.iris.model.jpa.ExtUsers.statusCode" 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:
> http://openjpa.208410.n2.nabble.com/Differences-in-persisting-ForeignKeys-between-OpenJPA-2-1-0-and-2-2-1-tp7583990.html
> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>



-- 
*Rick Curtis*

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message