The data I am deleting has a parent - child relationship ( OneToMany ) and will
try and give you as much information as possible.
I am using JBoss 4.0.4GA, EJB3 RC7 with Oracle 9I. I create the db tables
myself with the foreign keys and primary keys with a script.
The Parent uses an embedded primary key class
ParentPK class
Long locationId
String recordId
@Column( name = locationId, nullable)
Long getLocationId(){ return locationId; } ( have one for recordId)
Parent class
ParentPK parentPk
Set children
more attributes
@EmbeddedId
ParentPK getPK
@OneToMany( cascade = CascadeType.ALL, fetch = FetchType=Lazy )
@JoinColumns(
@JoinColumn name = "locationId", referencedColumnName="locationId"
@JoinColumn name = "recordId",referencedColumnName="recordId" )
public Set getChild(){ return children; }
The child uses an embeded id as well. It is written the same as above and
has a primary key of recordId, locationId and Timestamp timeCreated attribute.
I do not have a Parent attribute in the child and thus not a ManyToOne
relationship between the child and parent. ( IS this bad? I never reference
the Parent with the child )
When I try and delete the Parent and hope it cascades through, I write this
code. em = EntityManager, deletePrior is a Timestamp object passed in.
Query query = em.createQuery("delete from Parent where lastUpdated <
:deletePrior").setParameter("deletePrior", deletePrior);
int updatedEntities = query.executeUpdate();
When I do this I get:
integrity constraint (SYSTEM.CHILD_FK) violated - child record found.
I also find a message in the exception that says:
AbstractFlushingEventListener] Flushed 0 insertions, 1 updates, 0
deletions to 1 objects
I also tried to get a list with the above query and delete each object
individually.
em.remove( Parent Obj );
I get:
cannot update ("SYSTEM"."CHILD"."LOCATIONID") to NULL;
This is in the exception as well
ERROR could not synchronize database state with session
I hope this helps in explaining what I am doing and if someone could let me
know if I am doing something wrong, I would appreciate it.
allan
View the original post :
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3948102#3948102
Reply to the post :
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3948102
-------------------------------------------------------
All the advantages of Linux Managed Hosting--Without the Cost and Risk!
Fully trained technicians. The highest number of Red Hat certifications in
the hosting industry. Fanatical Support. Click to learn more
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=107521&bid=248729&dat=121642
_______________________________________________
JBoss-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jboss-user