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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:08:14+00:00 2026-05-26T03:08:14+00:00

Consider the following example: public interface Bar { } @Entity @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) public

  • 0

Consider the following example:

public interface Bar {
}

@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public DefaultBar implements Bar {

  @Id
  @GeneratedValue(strategy = GenerationType.TABLE)
  private long id;

}

@Entity
public class Foo {

  @Id
  @GeneratedValue(strategy = GenerationType.TABLE)
  private long id;

  @OneToMany(cascade = CascadeType.ALL, targetEntity = DefaultBar.class)
  @JoinColumn(name = "FOO_ID")
  private Collection<Bar> bars;

  public Collection<Bar> getBars() {
    return bars;
  }
}

That’ll work all right. BUT – suppose I’ll make a subclass of Foo; say FooFoo. And I want the “bars” association to point to a new implementation of Bar too. Say:

@Entity
public NewBar extends DefaultBar {

}

And now I would like to annotate FooFoo so it sets the target entity of the “bars” field to the NewBar class.

@Entity
@AssociationOverride(name="bars", ???????)
public class FooFoo extends Foo {

}

I noticed the annotation @AssociationOverride, but at first sight it doesn’t allow the target entity to be overriden. Or does it ?

  • 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-26T03:08:14+00:00Added an answer on May 26, 2026 at 3:08 am

    There seems to be no way to do this in context of JPA. Hibernate has specific meta-annotations to override a OneToMany annotation of a superclass.

    In the meantime it appears the @AssociationOverride annotation only applies to classes marked with @MappedSuperclass. But then they can’t be used as target entity in the OneToMany association.

    Chicken and egg problem really… Or is it ?

    Java does not allow the override of fields. But it does for methods. If the superclass uses property access, THEN is works. Let the subclass override the getter and there you go ! 🙂

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

Sidebar

Related Questions

Consider the following code. public interface IFoo { } public class Bar { public
Consider the following example: public interface ITask { void Execute(); } public class LoggingTaskRunner
Consider the following simple RESTEasy (JAX-RS) service: @Path(/example-service) public interface ExampleService { @Path(/ping) @GET
Consider the following example: interface IPropertyCollection { public MethodWrapper GetPropertySetterByName(string name); //<<-- I want
Consider the following example code: class Foo { }; class Bar : public Foo
Consider the following example: public class Sandbox { public interface Listener<T extends JComponent> {
Consider following example : public class SomeBusinessLayerService : DataService<MyEntityContainer> { [WebInvoke] void DoSomething(string someParam)
Consider the following example. I have an interface MyInterface, and then two abstract classes
consider the following example: public IEnumerable<String> Test () { IEnumerable<String> lexicalStrings = new List<String>
Consider the following example: <!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Strict//EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd> <html xmlns=http://www.w3.org/1999/xhtml

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.