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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:10:33+00:00 2026-05-25T17:10:33+00:00

I am trying to extend an entity into a non-entity which is used to

  • 0

I am trying to extend an entity into a non-entity which is used to fill the superclass’s fields. The problem is that when I try to save it Hibernate throws a MappingException. This is because even though I cast ReportParser to Report, the runtime instance is still a ReportParser so Hibernate complains that it is an unknown entity.

@Entity
@Table(name = "TB_Reports")
public class Report
{
   Long id;
   String name;
   String value;

   @Id
   @GeneratedValue
   @Column(name = "cReportID")
   public Long getId()
   {
      return this.id;
   }

   public void setId(Long id)
   {
      this.id = id;
   }

   @Column(name = "cCompanyName")
   public String getname()
   {
      return this.name;
   }

   public void setName(String name)
   {
      this.name = name;
   }

   @Column(name = "cCompanyValue")
   public String getValue()
   {
      return this.name;
   }

   public void setValue(String value)
   {
      this.value = value;
   }
}

ReportParser is only used to fill in fields.

public class ReportParser extends report
{
   public void setName(String htmlstring)
   {
      ...
   }

   public void setValue(String htmlstring)
   {
      ...
   }
}

Attempt to cast it to a Report and save it

...
ReportParser rp = new ReportParser();
rp.setName(unparsed_string);
rp.setValue(unparsed_string);
Report r = (Report)rp;
this.dao.saveReport(r);

I’ve used this pattern before I moved to an ORM, but I can’t figure out how to do this with Hibernate. Is it possible?

  • 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-25T17:10:34+00:00Added an answer on May 25, 2026 at 5:10 pm

    Is it absolutely necessary to subclass the entity? You could use the builder pattern:

    public class ReportBuilder {
        private Report report;
        public ReportBuilder() {
            this.report = new Report();
        }
        public ReportBuilder setName(String unparsedString) {
            // do the parsing
            report.setName(parsedString);
            return this;
        }
        public ReportBuilder setValue(String unparsedString) {
            // do the parsing
            report.setValue(parsedString);
            return this;
        }
        public Report build() {
            return report;
        }
    }
    
    Report report = new ReportBuilder()
                       .setName(unparsedString)
                       .setValue(unparsedString)
                       .build();
    dao.saveReport(report);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to extend the partial classes that the entity framework creates so
I'm trying to extend JButton with Clojure, but I ran into a problem when
I am trying to extend the mysqli class to make a helper class that
I've an Entity Framework model (v.1.0) that I'm trying to extends with a calculated
I have following kinds of classes for hibernate entity hierarchy. I am trying to
I'm running into a ConstraintViolationException when I try to save an object with a
I thought hibernate takes into consideration only instance variables that are annotated with @Column
Hallo all. I'm trying to map an association one-to-many to an entity that is
I'm trying to use HibernateDaoSupport but I'm getting stuck with a org.hibernate.LazyInitializationException problem. This
I have a hierarchy of classes mapped into hibernate that looks kind of like

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.