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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T19:09:43+00:00 2026-05-12T19:09:43+00:00

I have a hibernate model with two classes, let’s say A and B. B

  • 0

I have a hibernate model with two classes, let’s say A and B. B has a many-to-one reference to A.

I query a single A and a single B object. These are detached from the Session and they get processed somewhere/used else. The B.A property is a lazy proxy. Sometime later A and B both need to be deleted. I create a new Session and call .delete(A) and .delete(B).

Deleting A is ok, but then deleting B causes the following exception,

Caused by: org.hibernate.PropertyValueException: not-null property references a null or transient value: com.xxx.hibernate.objects.B.A
    at org.hibernate.engine.Nullability.checkNullability(Nullability.java:95) [hibernate3.jar:na]
    at org.hibernate.event.def.DefaultDeleteEventListener.deleteEntity(DefaultDeleteEventListener.java:272) [hibernate3.jar:na]
    at org.hibernate.event.def.DefaultDeleteEventListener.onDelete(DefaultDeleteEventListener.java:163) [hibernate3.jar:na]
    at org.hibernate.event.def.DefaultDeleteEventListener.onDelete(DefaultDeleteEventListener.java:74) [hibernate3.jar:na]
    at org.hibernate.impl.SessionImpl.fireDelete(SessionImpl.java:794) [hibernate3.jar:na]
    at org.hibernate.impl.SessionImpl.delete(SessionImpl.java:772) [hibernate3.jar:na]

Diggin in the code it looks as tho during the deletion a nullability check is done, and because A was deleted first, deletion of B fails the null check. It thinks it’s A reference is “null” even tho the B object I pass in it is set to not-null. Looks like it does some lookup in the internal Session state and finds the deleted A instance.

Anyone know how I can work round this? I would prefer not to rely on the ordering of the deletion if possible, unless deleting A before B is fundamentally wrong for some reason I’m not seeing.

I’m also not entirely sure why a null check is required on a delete.

  • 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-12T19:09:44+00:00Added an answer on May 12, 2026 at 7:09 pm

    I think you have to delete all the “children” before you delete the “parent”. I realise you don’t want to be at the mercy of the order of deletions, but I don’t think there’s any other way around this.

    Just an idea, but have a look at what is actually arriving in the database at each step of the delete. If Hibernate is setup to create a DELETE command using all the columns of the table, including the foreign key linking to A, then the DELETE command won’t find anything if it’s looking for a NULL value of the A key.

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

Sidebar

Ask A Question

Stats

  • Questions 207k
  • Answers 207k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You can grant the SELECT right directly on sys.database_principals, as… May 12, 2026 at 9:27 pm
  • Editorial Team
    Editorial Team added an answer mono's C# compiler is written in C#. If you need… May 12, 2026 at 9:27 pm
  • Editorial Team
    Editorial Team added an answer \1 will contain your first match, so you could do… May 12, 2026 at 9:27 pm

Related Questions

I have a problem with uninitialized proxies in nhibernate The Domain Model Let's say
I have a class in my domain model root that looks like this: namespace
I have a somewhat ridiculous question regarding DDD, Repository Patterns and ORM. In this
I'm new to Hibernate, and while there are literally tons of examples to look
I have an application A with a domain-model which is mapped to a database

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.