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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T15:34:47+00:00 2026-06-02T15:34:47+00:00

I’m at a loss here, and perhaps it’s something obvious because my Hibernate expertise

  • 0

I’m at a loss here, and perhaps it’s something obvious because my Hibernate expertise is weaker than other areas.

In legacy code there is a Hibernate @Entity class Foo. One of the its properties is this:

private OldBar bar = new OldBar();

OldBar is an @Embeddable class that uses a single column, foobar:

@Embeddable
public class OldBar {

  private String fooBar;

  @Column(length = 10, nullable = false)
  private String getFooBar() {
    return fooBar;
  }

  @SuppressWarnings("unused")
  private void setFooBar(String fooBar) {
    this.fooBar = fooBar;
  }
}

The original problem is that I needed to do something with OldBar.fooBar, but the original design had limitations and had this field private, preventing me from subclassing it, so I had to create a whole other class, NewBar, to replace the other one and get access to the private field. I thought that since NewBar is also Embeddable and has the same @Column designation, I could just swap out the field in the class Foo:

private NewBar bar = new NewBar();

I wanted to do this because I have existing data in the foobar column, and I wanted to transparently use this data with NewBar instead of OldBar.

Through trace logs I’ve seen that Foo() is created, with its default version of NewBar(), as one would expect, when the constructor is called. However, by the time code calls Foo.getBar(), for some reason bar is null! I’m supposing Hibernate is setting it to null for some reason—but why isn’t Hibernate reading the data from the foobar column and creating an instance of NewBar? Why does it star working again when I put OldBar back in in place of NewBar? Surely there’s nothing in the database itself that says which of the @Embeddable classes is mapped to the column, is there?

Update: This gets stranger and stranger. Sometimes I’ll let the code overnight, and the next day it works! Or the next day it doesn’t work! Just now it didn’t work (that is, the foobar property was set to null instead of the value in the database), so I made class ExactCopyOfOldBar and put it in the place of OldBar. It worked fine! So I switch back to NewBar—merely undoing my temporary changes. It still worked, when it hadn’t before! Is there some sort of cache where Hibernate serializes values and doesn’t get them from the database? This is very odd.

Update: Now I can no longer get NewBar to work at all. I create OtherBar, which is basically identical to NewBar except that it has a different name, and I plug it in and it works, correctly reading the embedded string. I switch back out to NewBar, and I get null again. What is going on?

Note that Foo is being loaded through net.databinder.auth.hib.AuthDataApplication.getUser(String username), which is simple enough:

return (DataUser) Databinder.getHibernateSession().createCriteria(getUserClass())
    .add(Restrictions.eq("username", username)).uniqueResult();

I’ve verified over and over again that the Foo (user) table has a single row with the correct data, and most importantly that the foobar field has data. Why is Hibernate returning me a Foo with a null foobar field? Why does simply switching from NewBar to OtherBar make it start working again? Why does it work all day and then stop working after I’ve left it overnight?

  • 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-06-02T15:34:49+00:00Added an answer on June 2, 2026 at 3:34 pm

    This may be the answer; I’ll have to wait several days to see if it indeed fixes the problem. There are actually two parts.

    First, for full disclosure, my NewBar class was actually a subclass of AbstractBar. I eventually wanted to have different type of embeddable bars, so I placed @Embeddable at the AbstractBar level, not at the NewBar level, and placed the private foobar field at the AbstractBar level as well. The funny thing is, this worked some of the time. And as I mentioned, sometimes I would come back the next day and Hibernate wouldn’t load the foobar field. I don’t understand why it didn’t either work all the time or work none of the time.

    Secondly, when I tried to get rid of this hierarchy so as to eliminate one source of the problem, I conflated AbstractBar and NewBar but forgot to bring the @Embeddable up from AbstractBar to NewBar, so Hibernate didn’t see that was an embeddable class, and didn’t know how to load a string into a NewBar field without an @Embeddable designation. This is why OtherBar (with an @Embeddable annotation) worked, but not NewBar (with no @Embeddable annotation). This much I understand. Why Hibernate didn’t warn me that it couldn’t figure out how to load a field, I don’t know.

    So to summarize, Hibernate won’t load an embeddable field if you’ve left the @Embeddable annotation off the class. As for the original problem, I can only guess that @Embeddable is flaky when trying to use it on a class hierarchy, and that you’re best off keeping all your embeddable fields at one level in the embeddable class. I hope that’s the issue. We’ll see if it continues to work tomorrow.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I know there's a lot of other questions out there that deal with this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
Let's say I'm outputting a post title and in our database, it's Hello Y’all

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.