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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T22:54:32+00:00 2026-05-24T22:54:32+00:00

Sometimes it’s quite difficult (or a performance problem) to clean delete all references to

  • 0

Sometimes it’s quite difficult (or a performance problem) to clean delete all references to an entity.

For example, I’ve got a Person object which has relationships to another Person objects.

When I delete a Person, I don’t want to delete this Person in all relations she can have simply because sometimes this Person object does not know where it is referenced. So, if I would like to clean delete all references, I must do extra sql work that can result in performance problem.

In an ideal world, I would like to delete the Person object and when another Person do a reference to this Person (because it has its id in its relations), simply return null.

The fact is JPA complains that

javax.persistence.EntityNotFoundException: No row with the given identifier exists

Is there a way to force JPA to return a null reference and not an exception in this case ?

  • 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-24T22:54:33+00:00Added an answer on May 24, 2026 at 10:54 pm

    You can use the @NotFound annotation with the value NotFoundAction.IGNORE, which will return null if an associated entity doesn’t exist.

    A word of caution: if you use this in a collections and hibernate doesn’t find one of the entries, it will add a null value in the collection, which is very annoying. To avoid this, you can wrap the collection in a Collection that skips nulls.

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

Sidebar

Related Questions

Sometimes FINDSTR with multiple literal search strings fails to find all matches. For example,
Sometimes for example I change a word in line 100 and delete last 4
Sometimes I got a crash of my application with the following stack trace :
Sometimes I'm getting the FB is not defined issue when loading the http://connect.facebook.net/en_US/all.js I've
Sometimes one has to refer to another method when commenting. Here some example in
Sometimes, game-like features in an application can make work fun. For example, Stack Overflow
Sometimes I got error saying that unrecognized selector objcType was sent to an NSDate
Sometimes I need to set some string values from code, for example: Page.Title =
Sometimes it's very difficult to find an error in an application because of static
Sometimes when I'm editing page or control the .designer files stop being updated with

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.