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

Related Questions

I have a problem with uninitialized proxies in nhibernate The Domain Model Let's say
I have two classes binded mapped with Hibernate and I can't figure out the
We have an object model being used across three applications. Two programs collect data,
I have one hibernate sequence, that generates all sequence-numbers in my app. When I
I have a hibernate query in grails Book.findAllByRating(4) In the above query i want
The situation is this: You have a Hibernate context with an object graph that
I have the following Hibernate Mapping, which has to be mapped using the Table
Model: I have a model in which one Installation can contain multiple Computer Systems.
I have a database model with two tables: Session and ScriptExecution which are associated
I have a model that has several properties. The properties can be primitive (String)

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.