openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "C N Davies" <...@cndavies.com>
Subject Unmanaged Object Problems
Date Sun, 04 Apr 2010 16:12:21 GMT
Hi,

 

This is a problem that continues to haunt me intermittently since I first
started using OpenJPA and cannot understand why it comes up from time to
time for no apparent reason.

 

I have an Entity like this:

 

@Entity

public class DataLoad {

  ..

      @ManyToOne(cascade={CascadeType.REFRESH})

      private LoadConfig loadConfig;

  ...

}

 

@Entity

public class LoadConfig {

  ..

      private String name;

 

      private Date createDate;

  ...

}

 

 

If I create a new DataLoad entity and use em.save(dataload) is all works
fine, but if later use em.merge(dataload); since I made some changes to the
entity  I get this stack trace:

 

<openjpa-2.0.0-beta-r422266:903062M nonfatal user error>
org.apache.openjpa.persistence.InvalidStateException: Encountered unmanaged
object in persistent field "com.trm.core.DataLoad.loadConfig" during flush.
However, this field does not allow cascade persist. Set the cascade
attribute for this field to CascadeType.PERSIST or CascadeType.ALL (JPA
annotations) or "persist" or "all" (JPA orm.xml), or enable cascade-persist
globally, or manually persist the related field value prior to flushing. You
cannot flush unmanaged objects or graphs that have persistent associations
to unmanaged objects.

FailedObject:
org.apache.openjpa.enhance.com$trm$core$LoadConfig$pcsubclass-00000126A871C0
E8

      at
org.apache.openjpa.kernel.SingleFieldManager.preFlushPC(SingleFieldManager.j
ava:767)

      at
org.apache.openjpa.kernel.SingleFieldManager.preFlush(SingleFieldManager.jav
a:607)

      at
org.apache.openjpa.kernel.SingleFieldManager.preFlush(SingleFieldManager.jav
a:575)

      at
org.apache.openjpa.kernel.SingleFieldManager.preFlush(SingleFieldManager.jav
a:491)

      at
org.apache.openjpa.kernel.StateManagerImpl.preFlush(StateManagerImpl.java:29
56)

      at org.apache.openjpa.kernel.PNewState.beforeFlush(PNewState.java:40)

      at
org.apache.openjpa.kernel.StateManagerImpl.beforeFlush(StateManagerImpl.java
:1048)

      at org.apache.openjpa.kernel.BrokerImpl.flush(BrokerImpl.java:2053)

      at
org.apache.openjpa.kernel.BrokerImpl.flushSafe(BrokerImpl.java:2013)

      at
org.apache.openjpa.kernel.BrokerImpl.beforeCompletion(BrokerImpl.java:1931)

      at
org.apache.openjpa.kernel.LocalManagedRuntime.commit(LocalManagedRuntime.jav
a:81)

      at org.apache.openjpa.kernel.BrokerImpl.commit(BrokerImpl.java:1455)

      at
org.apache.openjpa.kernel.DelegatingBroker.commit(DelegatingBroker.java:903)

      at
org.apache.openjpa.persistence.EntityManagerImpl.commit(EntityManagerImpl.ja
va:551)

 

I do not want to persist anything in the loadConfig field, I am only using
cascade={CascadeType.REFRESH} so that OpenJPA will create the joins, so why
is OpenJPA complaining that I need to turn on CascadeType.PERSIST etc and
why does it only happen when I use merge?

 

Using OpenJPA 2.0.0 Beta 2 and also getting the same issue on 1.2.2 as well.

 

 

Thanks for any pointers J 

 

Chris


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