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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T18:35:16+00:00 2026-05-13T18:35:16+00:00

I would like to override a constraint in hibernate validator. Here is my base

  • 0

I would like to override a constraint in hibernate validator. Here is my base class:

@Entity
@Table(name = "Value")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "valueType", discriminatorType = DiscriminatorType.STRING)
public abstract class Value extends CommonTable
{
    private String              equation;

    @SimpleEquation(equationType = EquationType.EQUATION)
    public String getEquation()
    {
        return equation;
    }

    public void setEquation(String equation)
    {
        this.equation = equation;
    }
}

I’ve got a child class where I want to specify that the equationType for equation field is EquationType.ANOTHER_EQUATION, something like this:

@Entity(name = "CharacteristicUpgradeValue")
@DiscriminatorValue("CharacteristicUpgradeValue")
public class CharacteristicUpgradeValue extends Value
{    
    @Override
    @SimpleEquation(equationType = EquationType.COST_VALUE)
    public String getEquation()
    {
        return super.getEquation();
    }

}

this code throw an exception saying that I’ve got a org.hibernate.MappingException: Repeated column in mapping for entity (normal, due to the duplicate getter)

There is an @AttributeOverride in Hibernate/jpa but it seems to run only with column override and not this kind of attribute.

How can I do it ?

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-13T18:35:16+00:00Added an answer on May 13, 2026 at 6:35 pm

    Well… I’ve found a tip to achieve it… That’s not very clean… but it runs:

    here is my base class:

    @Entity
    @Table(name = "Value")
    @Inheritance(strategy = InheritanceType.SINGLE_TABLE)
    @DiscriminatorColumn(name = "valueType", discriminatorType = DiscriminatorType.STRING)
    public abstract class Value extends CommonTable
    {
        protected String                equation;
    
        @Transient
        public abstract String getEquation();
    
        public void setEquation(String equation)
        {
            this.equation = equation;
        }
    }
    

    You need to specify the getter as @Transient because if not, Hibernate will throw a duplicate definition for the equation field. My equation field is now protected and not private.

    And now, on each of your subclass, you override the getEquation by specifying the constraint (and as @Transient is not inherited by subclasses, the overriden getEquation will be use for the equation field mapping).

    Here is a subclass example:

    @Entity(name = "CharacteristicUpgradeValue")
    @DiscriminatorValue("CharacteristicUpgradeValue")
    public class CharacteristicUpgradeValue extends Value
    {    
        @Override
        @SimpleEquation(equationType = EquationType.COST_VALUE)
        public String getEquation()
        {
            return equation;
        }
    
    }
    

    I haven’t found better…

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

Sidebar

Related Questions

I have a class MyClass, and I would like to override the method ToString()
My django model looks like this: class Entity(models.Model): name = models.CharField(max_length=40) examples = models.ManyToManyField(Example,
I would like to override operator * for my class. I know how to
I would like to temporarily override the kill-new function. I have a way I
I would like to override object.ToString() for struct in runtime using reflection? I need
I would like to override bool 's TryParse method to accept yes and no.
I would like to override the buttons of a datepickerdialog case START_DATE_DIALOG_ID: DatePickerDialog datePicker
I would like to override a generic function in a subclass, as follows: Superclass:
I would like to override custom user template in my Drupal 7 installation. The
I would like to override the default behavior of the offsetParent member of 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.