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

  • Home
  • SEARCH
  • 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 865825
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T09:42:02+00:00 2026-05-15T09:42:02+00:00

Hibernate does not allow me to persist an object that contains an null embedded

  • 0

Hibernate does not allow me to persist an object that contains an null embedded object with an integer field. For example, if I have a class called Thing that looks like this

@Entity
public class Thing {

    @Id
    public String id;

    public Part part;

}

where Part is an embeddable class that looks like this

@Embeddable
public class Part {

    public String a;    

    public int b;

}

then trying to persist a Thing object with a null Part causes Hibernate to throw an Exception. In particular, this code

Thing th = new Thing();
th.id = "thing.1";
th.part = null;
session.saveOrUpdate(th);

causes Hibernate to throw this Exception

org.hibernate.PropertyValueException: not-null property references a null or transient value: com.ace.moab.api.jobs.Thing.part

My guess is that this is happening because Part is an embedded class and so Part.a and Part.b are simply columns in the Thing database table. Since the Thing.part is null Hibernate wants to set the Part.a and Part.b column values to null for the row for thing.1. However, Part.b is an integer and Hibernate will not allow integer columns in the database to be null. This is what causes the Exception, right?

So I am looking for workarounds for this problem. I noticed making Part.b an Integer instead of an int seems to work, but for reasons I won’t bore you with this is not a good option for us. Thanks!

  • 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-15T09:42:03+00:00Added an answer on May 15, 2026 at 9:42 am

    I found another workaround and thought I’d share it. Turns out that if you make the int column nullable then Hibernate doesn’t throw the PropertyValueException.

    @Column(nullable = true)
    public Integer b;
    

    This works for us because our hibernate enabled application is the only thing that touched the database and so we can guarantee that b is null only when the part is null. Although the null part suggestion and the use of the Integer wrapper type are great suggestions, due to lots of reasons I don’t really have control over, setting the column to nullable works best for us. Thanks though and I hope this helps someone else.

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

Sidebar

Related Questions

Does the Hibernate API support object result sets in the form of a collection
Does anyone have any experience getting MSTest to copy hibernate.cfg.xml properly to the output
Hibernate has a handful of methods that, one way or another, takes your object
Does hibernate HQL queries support using select min, max, count and other sql functions?
I know this is a subjective question, but why does Hibernate seem to be
Does anybody know what's going on here: I run hibernate 3.2.6 against a PostgreSQL
does anyone know if you can do something like this using the (N)Hibernate criteria
Does anyone know why NHibernate generates a field named 'elt' of type int for
I'm using NHibernate 2 and PostgreSQL in my project. SchemaExport class does a great
Does anyone know if NHibernate supports returning output parameters from stored procedures? I've had

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.