Hi Paul,
Yes you are correct about "unmanaged".
Using cascadeAll on account and calling entityManager.persist(voucher) will
make the account object also persistent.
So, I am guessing my suggestion should work fine.
Regards,
Ravi.
"unmanaged" means the Account object assigned to the ManyToOne field is
new and not yet persistent, removed, or detached.
On 4/11/2009 7:46 AM, rpalache wrote:
> Hi,
>
> "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. "
>
> In your example, can you please try the following and see if it resolves the
> issue:
>
> @ManyToOne(cascade=CascadeType.ALL)
> @JoinColumn(name = "account_id")
> private Account account;
> }
>
> Regards,
> Ravi.
>
>
> We have a critical problem in our application, we have multiple enterprise
> applications and we have to use distributed transactions to ensure ACID
> operations on entire system.
> Our Application server is Glassfish V9 update 5 on SUSE 10 and database is
> Oracle 10.2.0.1.0.
> The problem is when we use oracle.jdbc.xa.client.OracleXADataSource as JDBC
> driver and javax.sql.XADataSource as resource type, we get following error in
> persisting an entity with a ManyToOne relationship and it complains the other
> side of relationship is unmanaged!!! However the other side of the
> relationship (here account entity) is already existed in database and with
> typical JDBC driver, no error we encounter. I have tested all other OpenJPA
> versions but the problem still exists. I don’t know whether this is OpenJPA
> issue or JDBC driver, please share your experience on this matter.
>
>
> javax.ejb.TransactionRolledbackLocalException: Exception thrown from bean;
> nested exception is: <openjpa-2.0.0-M1-SNAPSHOT-r422266:725770 fatal user
> error> org.apache.openjpa.persistence.InvalidStateException: Encountered
> unmanaged object in persistent field
> "com.kishware.core.gl.data.Voucher.account" 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:
> com.kishware.core.gl.data.Account-com.kishware.core.gl.data.Account-215
>
>
> This is our entity classes and simple test case:
>
> public class Voucher {
> @Id
> @Column(name = "id")
> @GeneratedValue(strategy = GenerationType.SEQUENCE ,generator =
> "VoucherSequenceGenerator")
> private Long id;
>
> @ManyToOne
> @JoinColumn(name = "account_id")
> private Account account;
> }
>
> public class Account {
> @Id
> @Column(name = "id")
> @GeneratedValue(strategy = GenerationType.SEQUENCE, generator =
> "AccountSequenceGenerator")
> private Long id;
> }
>
> Account account = entityManager.find(Account.class, 215L);
> Voucher voucher = new Voucher();
> Voucher.setAccount(account);
> entityManager.persist(voucher);
>
>
>
>
>
--
View this message in context:
http://n2.nabble.com/persistence-problem-in-distributed-environment-tp2619875p2622747.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.