Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] JPQL does not do cascading delete

Within the confines of the JPA spec, your two options are the ones you have likely already discovered.

1. Read the objects and delete them individually (by iterating, for instance)

2. Run a set of Delete and Update queries to fix relationships

EclipseLink provides some other options

1. You can enable cascading at the database level if your database permits it and tell EclipseLink about it and EclipseLink will handle that

2. We have some EclipseLink specific APIs that will delete collections of objects (however for the most part, these just do the iteration for you)

3. EclipseLink allows stored procedure calls. You could do your deletes in a stored procedure.

-Tom

On 13/10/2011 12:04 PM, Warren Tang wrote:
Hi, Tom

Thanks for the info.

I think I can iterate through each record and delete one by one, but the
performance is a big concern.

Are there other options? I'm a JPA beginner so I would really appreciate it if
you could elaborate.

Regards,
Warren Tang <http://blog.tangcs.com>

On 10/13/2011 11:44 PM, Tom Ware wrote:
Hi,

From the JPA spec:

"A delete operation only applies to entities of the specified class and its
subclasses. It does not cascade to
related entities."

And:

"Bulk update maps directly to a database update operation, bypassing
optimistic locking checks. Portable
applications must manually update the value of the version column, if desired,
and/or manually validate
the value of the version column."

Bottom line, you have to manage relationships and locking when you using bulk
delete. The reason is that in order for us to manage relationships, we have to
have read the entities already and know what the relationships are. This
statement goes directly to the DB and may delete entities that have not been
read.

-Tom

On 13/10/2011 11:39 AM, Warren Tang wrote:
t does not do cascading de
_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users


_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users


Back to the top