Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3220248
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T15:44:22+00:00 2026-05-17T15:44:22+00:00

I am having trouble working out how to do a bulk delete of a

  • 0

I am having trouble working out how to do a bulk delete of a Person object using JPA, when the Person objects contain data stored using an @ElementCollection. Any ideas on how to do this would be much appreciated.

@Entity
@Table(name="at_person")
public class Person implements Comparable<Person> {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name="id")
    private long id = 0;

    @Column(name="name", nullable = true, length = 128)
    private String name = "";

    @ElementCollection
    @Column(name = "email")
    @CollectionTable(name = "person_email", joinColumns = @JoinColumn(name = "person_id"))
    private Set<String> email = new HashSet<String>();
}

What I am doing at the moment is this, and it fails with a foreign key constraint error:

Query query=em.createQuery("DELETE FROM Person");

Caused by: java.sql.SQLException: integrity constraint violation:
foreign key no action; FKCEC6E942485388AB table: PERSON_EMAIL

If it can be a pure JPA annotation rather than a Hibernate annotation that would be a bonus!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T15:44:23+00:00Added an answer on May 17, 2026 at 3:44 pm

    I’ll let you interpret the part of the JPA 2.0 specification that mentions that a bulk delete operation is not cascaded:

    4.10 Bulk Update and Delete Operations

    …

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

    And the fact is that Hibernate won’t cascade a delete to a collection table either. This has been reported in HHH-5529 and the suggested approaches are:

    You could also (a) clean up the collection table yourself or (b) use cascading foreign keys in the schema.

    In other words, (a) use native SQL or (b) use a cascade delete constraint at the database level – and you’ll have to add it manually, I don’t think you can use @OnDelete with the @ElementCollection annotation (same story as HHH-4301 IMO).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using Mongokit with Python. Having some trouble working out get the last n number
I'm having trouble working out how to pass in arguments into transactions when using
I am having trouble working out how to get a simple fade in fade
I'm having trouble working out the best way to repaint a JxTreeTable when the
I'm currently battling through some memory leaks and having some serious trouble working out
I'm having trouble getting Tire working using ElasticSearch with the Bonsai addon on the
I'm having trouble with getting a named scope working using using an attribute of
i'm having trouble working out the returned values of the below code pMeasure =
I'm having trouble working this out. Basically my program has a standard input, I
I'm having trouble working out why the following code doesn't catch the exception. It's

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.