openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Beniamin Mazan ...@mazan.pl>
Subject Bug in OpenJPA with cascade delete
Date Wed, 02 Jul 2008 11:51:14 GMT

I got 2 entities like below

@Entity....
class Product {
...
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy =
"product")
private List<SubProduct> children = new ArrayList<SubProduct>();
}

@Entity
class SubProduct {
....

@ManyToOne(cascade = {CascadeType.MERGE, CascadeType.REFRESH}, fetch =
FetchType.EAGER)
@JoinColumn(name = "product_id", nullable = false)
private Product product;

}

2) Database uses constraint on this relation - FOREIGN KEY, ON DELETE
CASCADE ON UPDATE CASCADE

3) persistence.xml has following properties
openjpa.Sequence=>class-table(Table=_SEQ_GENERATOR, UseAliases=true)"
openjpa.jdbc.MappingDefaults=>"ForeignKeyDeleteAction=cascade,JoinForeignKeyDeleteAction=cascade"
openjpa.jdbc.SchemaFactory=>"native(ForeignKeys=true)"
openjpa.jdbc.SynchronizeMappings=>"buildSchema(SchemaAction=refresh)"
openjpa.jdbc.DBDictionary=>"postgres"
openjpa.Multithreaded=>"true"
openjpa.TransactionMode=>"managed"
openjpa.AutoDetach=>"commit"
openjpa.RestoreState=>"all"
openjpa.Optimistic"=>"true"

And what is the issue?

CASE I
Thing that I do in _one_ transaction:
1) get entity using remote interfejs of Fasade and make it "detached"
2) modify entity
3) return entity using method on facade's remote interface, that:
        a) merges changes and makes entity "attached"
        b) deletes entity from em

Any SQL statements are executed on transaction commit. There's no UPDATEs,
but only DELETEs.
What does go wrong?
At first are executed statements for entity Product and then for Subproduct.
As a result I get OptimisticLockException for SubProduct - because (I
suspect) of database's execution delete for "FOREIGN KEY ON DELETE CASCADE".

When I remove FK constraints, all works fine.


CASE II
Thing that I do in _one_ transaction:
1) get entity using remote interfejs of Fasade and make it "detached"
2) return entity (unmodified) using method on facade's remote interface,
that:
        a) merges changes and makes entity "attached"
        b) deletes entity from em
Everyting goes OK, cause At first are executed statements for entity
SunProduct and then for Product.

Is there any workaround or I have to wait for patch for this issue ? 

-----
--
thanks
Beniamin
-- 
View this message in context: http://n2.nabble.com/Bug-in-OpenJPA-with-cascade-delete-tp219621p219621.html
Sent from the OpenJPA Developers mailing list archive at Nabble.com.


Mime
View raw message