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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T01:55:59+00:00 2026-05-16T01:55:59+00:00

I have an application using Hibernate for data persistence, with Spring on top (for

  • 0

I have an application using Hibernate for data persistence, with Spring on top (for good measure). Until recently, there was one persistent class in the application, A:

@Entity
public class A {
  @Id
  @Column(unique = true, nullable = false, updatable = false)
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  private long id;
  public String name;
}

I have since added a subclass of A, called B:

@Entity
public class B extends A {
  public String description;
}

After adding B, I could now not load A’s. The following exception was thrown:

class org.springframework.orm.hibernate3.HibernateObjectRetrievalFailureException :: Object with id: 1 was not of the specified subclass: A (Discriminator: null); nested exception is org.hibernate.WrongClassException: Object with id: 1 was not of the specified subclass: A (Discriminator: null)

I added the following annotation and property to B, and it seems to have solved the problem. Is this the right way to solve the issue?

...
@DiscriminatorFormula("(CASE WHEN dtype IS NULL THEN 'A' ELSE dtype END)")
public class A {
    private String dtype = this.getClass().getSimpleName();
    ...
  • 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-16T01:56:00+00:00Added an answer on May 16, 2026 at 1:56 am

    (…) Until recently, there was one persistent class in the application, A:

    With the following database representation:

    ID  NAME
    --  ----
     1   foo
     2   bar
    

    I have since added a subclass of A, called B (…)

    And you didn’t specify the Inheritance annotation so the SINGLE_TABLE mapping strategy is used. And In this strategy, all the classes in a hierarchy are mapped to a single table. The table has a column that serves as a “discriminator column”, that is, a column whose value identifies the specific subclass to which the instance that is represented by the row belongs.

    The table then became:

    ID  NAME DTYPE
    --  ---- -----
     1   foo  NULL
     2   bar  NULL
    

    Where DTYPE is the default name of column to be used for the discriminator.

    After adding B, I could now not load A’s. The following exception was thrown (…)

    Indeed, because existing values have a null value in the discriminator column, the provider doesn’t know what subclass to instantiate.

    I added the following annotation and property to B, and it seems to have solved the problem. Is this the right way to solve the issue?

    That’s one way but it is intrusive (your entities shouldn’t be aware of the dtype column) and Hibernate specific. In other words, it’s a hack.

    For me, the “right” way to solve this would be to update the DTYPE column of existing A records to set the value to 'A' (with Hibernate, the value defaults to the entity name):

    UPDATE A SET DTYPE='A' WHERE DTYPE=NULL
    

    This way, Hibernate would be able to load them properly.

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

Sidebar

Ask A Question

Stats

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

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

    • 7 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer It helps by allowing you to use some specific pieces,… May 16, 2026 at 11:44 pm
  • Editorial Team
    Editorial Team added an answer If you want tab page control tutorial then this tutorial… May 16, 2026 at 11:44 pm
  • Editorial Team
    Editorial Team added an answer VS is placing all projects in one output by default,… May 16, 2026 at 11:44 pm

Trending Tags

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

Top Members

Related Questions

I'm using Hibernate with Spring in my application. I have been consistently using detached
I have an application using Tomcat/Spring 3/JPA/Hibernate but my merges do not commit to
I have an application using hibernate 3.1 and JPA annotations. It has a few
I am using Hibernate in a Java application to access my Database and it
I am using Spring MVC for an application that involved a multilevel back end
today I have coded a test case for my application, to see how transactions
I have a small application in C#, and so far I have implemented it
I have a reference application that I use to work through DDD issues, and
I have an object model that I want to store using an embedded database.
Using Hibernate 3.5.1 and MSSQL 2008 Hi trying to implement the typical DateCreated and

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.