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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:06:43+00:00 2026-05-26T09:06:43+00:00

I have a many-to-many relation on a single object with itself: <set name=relatedPersons lazy=false

  • 0

I have a many-to-many relation on a single object with itself:

    <set name="relatedPersons" lazy="false"  table="PersonRelatedPerson" 
           cascade="none" >
    <key column="personId" foreign-key="fk_related_person" not-
        null="false"/>
       <many-to-many column="relatedPersonId" class="Person" not-found="ignore"/>
    </set>

as you can see I have set cascade to “none” because, when i delete one person, ofcourse i just would like to delete the relations from the table PersonRelatedPerson, and not the related Persons them selves. When i try to do delete with this mapping, i get the
ConstraintViolationException: Could not execute JDBC batch update….

I am guessing that it is somehow possible to delete this by hibernate by properly setting some mapping flags (or do i have to do some weird workarounds eg. first delete second person from set of first person, delete first person from set of second, and then delete first…. i really dont wanna do this :D)

Appreciate all the help!!!

  • 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-26T09:06:44+00:00Added an answer on May 26, 2026 at 9:06 am

    You’ll just have to remove the relationships yourself. To do this, before removing the person A, you’ll have to find all the persons who have A in their set of related persons, and remove A from these sets. If you don’t, then of course you can’t delete A because other persons still reference A.

    Either do this with a HQL query and remove A from the sets of the found persons in Java, or use a dedicated SQL delete query to remove all the rows from the join table. But be aware that this SQL query will bypass the caches (first-level and second-level, if any), and your session might thus hold an incorrect view of the database.

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

Sidebar

Related Questions

I have a one-many relation: Object ReportCategory: Table("RCA_REPORT_CATEGORY"); Id(r => r.Id, "RCA_ID"); Map(r =>
I have two classes with many-to-many relation so I created a join table in-between
I have two table Company and Employee. And there relation is Company(one) - Employee(many).
I have many table in my database it contain many key relation. i need
I have 3 table in SQL that have many-to-many relation.The first table account have
I have 2 tables (say parent and child table and 1 to many relation),
I have a many-to-many relation with a linked table. See (simplified) schema below. Created
I have 2 tables having many to many relation and hence there is junction
I have a simple SQL relational model with a many to many relation. Here
I have a question about Criteria method, one-to-many relation to the database, 'one' is

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.