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 8197047
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T05:39:34+00:00 2026-06-07T05:39:34+00:00

When I delete a record in a table, related record should be deleted in

  • 0

When I delete a record in a table, related record should be deleted in another table. But I receive instead:

java.sql.BatchUpdateException: Batch entry 0 update child_table set parent_table_id=null where parent_table_id=63 was aborted

The exception above is thrown against the following settings:

@OneToMany(cascade = javax.persistence.CascadeType.ALL, targetEntity = ChildTable.class)
@JoinColumn(name = "parent_table_id")
@org.hibernate.annotations.Fetch(FetchMode.SUBSELECT)
public List<ChildTable> getTables() {
    return tables;
}

If I’m not mistaken, with such annotations, when a record is deleted in ParentTable, corresponding relation should be deleted in Child one. It tries to become “null” (because corresponding record exists no more) before complete deletion. This id column is “not null”. When I make it be “null” (just for testing this case) everything works correctly.

Could you help me understand what is the real problem behind this?

Thank you in advance.

  • 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-06-07T05:39:35+00:00Added an answer on June 7, 2026 at 5:39 am

    One of the responders gave correct answer, but he deleted it.
    I had to use hibernate Cascade annotation instead of JPA one. It didn’t work for me because the problem was a little bit deeper than just usage of JPA and hibernate annotations together. Mapper class for ChildTable had parent_table_id of int type instead of a ParentTable class type the id field is mapped in. So I changed it from:

    @Entity
    @Table(name = "child_table")
    public class ChildTable {
    
    private int id;
    private int parent_table_id;
    ...
    

    to

    @Entity
    @Table(name = "child_table")
    public class ChildTable {
    
    private int id;
    private ParentTable parent_table;
    ...
    

    Surely some additional changes (connected to this one) were made and deletion started to work as expected.

    So, if you have corresponding error during deletion of an entity in one-to-many relation and everything is correct with annotations usage, check the types, your fields are of, in mapper-classes 🙂

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

Sidebar

Related Questions

If I delete a record from the Parent table I want the corresponding records
I want to have an 'updateinfo' table in order to record every update/insert/delete operations
Using PHP, I am trying to delete a record, but I want to check
I need to delete a record from the table For one CategoryId I will
I have table [HTML Table] on page I want to delete record from table
I have HTML something like this: <table> <tr> <td><div class='record'>Record Link</div></td> <td><div class='delete' style='display:none;'>Delete
The MSDN claims that the order is : Child table: delete records. Parent table:
What is the simplest way to delete records with duplicate name in a table?
I have a table with about 100k records and I want to delete some
Is there any way to check if it is safe to delete record from

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.