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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T03:36:06+00:00 2026-06-08T03:36:06+00:00

I’m running into some frustrating behavior with Hibernate when trying to set up my

  • 0

I’m running into some frustrating behavior with Hibernate when trying to set up my schema using annotations. Let’s say that I have an entity that will have one-to-many relationships to several other types. For example:

@Entity
@Table(name = "clubs")
public class Club {
    private long id;
    private String name;
    //...

    private Collection<ClubLocation> locations;

    public Club() {
        this.name = null;
        //...

        this.locations = Collections.emptyList();
    }

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    public Long getId() {
        return id;
    }
    public void setId(Long id) {
        this.id = id;
    }

    @Column(nullable = false)
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }

    @OneToMany(mappedBy = "club")
    public Collection<ClubLocation> getLocations() {
        return locations;
    }
    public void setLocations(Collection<ClubLocation> locations) {
        this.locations = locations;
    }
}

Now as I mentioned I want to associate this entity with a number of other entities, so it seemed like a good idea to define a superclass entity that manages the relationship back to Club so that I don’t need to set the relationship up in each associated class. I do this using:

@Entity
@Table(name = "clubItems")
@Inheritance(strategy = InheritanceType.JOINED)
public class ClubItem {
    protected Club club;

    public ClubItem() {
        this.club = null;
    }

    @ManyToOne(optional = false)
    public Club getClub() {
        return club;
    }
    public void setClub(Club club) {
        this.club = club;
    }
}

And then I extend that class like:

@Entity
@Table(name = "clubLocations")
public class ClubLocation extends ClubItem {
    private String title;
    //...

    public ClubLocation() {
        this.title = null;
        //...
    }

    @Column(nullable = false)
    public String getTitle() {
        return title;
    }
    public void setTitle(String title) {
        this.title = title;
    }
}

All seems well, except when I try to run and then Hibernate explodes with:

org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: ClubLocation.club in Club.locations
[WARNING] [talledLocalContainer]    at org.hibernate.cfg.annotations.CollectionBinder.bindStarToManySecondPass(CollectionBinder.java:543)
[WARNING] [talledLocalContainer]    at org.hibernate.cfg.annotations.CollectionBinder$1.secondPass(CollectionBinder.java:508)
[WARNING] [talledLocalContainer]    at org.hibernate.cfg.CollectionSecondPass.doSecondPass(CollectionSecondPass.java:43)
[WARNING] [talledLocalContainer]    at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1127)
[WARNING] [talledLocalContainer]    at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:296)
[WARNING] [talledLocalContainer]    at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1112)
[WARNING] [talledLocalContainer]    at org.hibernate.ejb.Ejb3Configuration.buildMappings(Ejb3Configuration.java:1233)
[WARNING] [talledLocalContainer]    at org.hibernate.ejb.EventListenerConfigurator.configure(EventListenerConfigurator.java:154)
[WARNING] [talledLocalContainer]    at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:869)
[WARNING] [talledLocalContainer]    at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:183)
[WARNING] [talledLocalContainer]    at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:240)
[WARNING] [talledLocalContainer]    at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:120)
[WARNING] [talledLocalContainer]    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:83)
[WARNING] [talledLocalContainer]    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:60)

Frustratingly, if I duplicate the getter and setter declarations for the club property inside of the ClubLocation class, all is well. Specifically, it works find if I add:

@Override
@ManyToOne(optional = false)
public Club getClub() {
    return super.getClub();
}
public void setClub(Club club) {
    super.setClub(club);
}

…into the ClubLocation class. But that’s pointless because all it does is delegate to the superclass.

Is Hibernate just not sophisticated enough to handle the inherited mapping field without the getter/setter being redeclared in the subclass? If Hibernate can handle this case more gracefully, how does it need to be set up/what am I doing wrong?

  • 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-08T03:36:08+00:00Added an answer on June 8, 2026 at 3:36 am

    I’ve got a similar setup in a project. I think an easy and more-or-less nice way to solve this is to change

    private Collection<ClubLocation> locations;
    

    into

    private Collection<ClubItem> items;
    

    (and the associated getter, setter, too). This way it surely works.

    If you need a getLocations method in Club for convenience reasons, your are free to create that. If you are sure, that items will contain only locations, you can return the collection as it is, otherwise you’d need to filter it in Java code.

    A disadvantage is that if items contain also non-location elements, filtering in Java takes memory and CPU, so it is potentially slow.

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

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I am currently running into a problem where an element is coming back from
I'm trying to create an if statement in PHP that prevents a single post
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has

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.