openjpa seems always to load parent on delete of child if mappedBy is used.
in parent-entity with mappedBy
@OneToMany(targetEntity=entities.APP.TestChild.class,
mappedBy="testParentField",cascade=CascadeType.PERSIST,orphanRemoval=true)
if using JoinColumn instead of mappedBy and nullifying @ManyToOne
parent-field in child, load of parent is avoided.
in parent:
@OneToMany(targetEntity=entities.APP.TestChild.class,cascade=CascadeType.PERSIST,orphanRemoval=true)
@JoinColumn(name="TESTPARENT",updatable=false)
in child:
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name="TESTPARENT",referencedColumnName="ID",nullable=false,unique=true,updatable=false)
@PreRemove
protected void onPreRemove()
{
LoadState loadstate=OpenJPAPersistenceUtil.isLoaded(this,"sites");
logger.info(this+" "+this.getId()+" loadstate
sites="+loadstate.toString());
if(loadstate==LoadState.NOT_LOADED){
logger.info("preventing unneccesary get/load/fetch of parent on delete of
child,does not seem to work if mappedBy instead of JoinColumn!");
this.setSites(null);
}
}//onPreRemove
derby sql:
CREATE TABLE "APP"."TESTPARENT" ("ID" INTEGER NOT NULL GENERATED BY DEFAULT
AS IDENTITY (START WITH 1, INCREMENT BY 1), "REMARKS" VARCHAR(255));
ALTER TABLE "APP"."TESTPARENT" ADD CONSTRAINT "SQL131021142503580" PRIMARY
KEY ("ID");
CREATE TABLE "APP"."TESTCHILD" ("ID" INTEGER NOT NULL GENERATED BY DEFAULT
AS IDENTITY (START WITH 1, INCREMENT BY 1), "TESTPARENT" INTEGER NOT NULL,
"REMARKS" VARCHAR(255));
ALTER TABLE "APP"."TESTCHILD" ADD CONSTRAINT "SQL131021142514460" PRIMARY
KEY ("ID");
ALTER TABLE "APP"."TESTCHILD" ADD CONSTRAINT "SQL131021142514461" FOREIGN
KEY ("TESTPARENT") REFERENCES "APP"."TESTPARENT" ("ID") ON DELETE NO ACTION
ON UPDATE NO ACTION;
--
View this message in context:
http://openjpa.208410.n2.nabble.com/openjpa-entity-remove-does-unnecessary-load-of-ManyToOne-field-tp7581482p7585439.html
Sent from the OpenJPA Developers mailing list archive at Nabble.com.