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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T22:18:55+00:00 2026-05-23T22:18:55+00:00

I am developing an application using Hibernate and am trying to model the following

  • 0

I am developing an application using Hibernate and am trying to model the following scenario:

I have an Activity Abstract class, defined as follows:

@Entity
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name="activityType")
@Table(name = "BF_ACTIVITY")
public abstract class Activity extends PersistableObject {

    @ManyToOne
    @JoinColumn(name = "ASSIGNED_TO")
    protected  Contactable assignedTo;

    @ManyToOne
    @JoinColumn(name = "RAISED_BY")
    protected  Contactable raisedBy;

Note I am using Single Table inheritance (so all implementing objects will use the same table) and have set a DiscriminatorColumn.

Now I have two objects that extend Activity: ToDo and Status:

@Entity
@Table(name = "BF_TODO")
@DiscriminatorValue("Todo")
public class ToDo extends Activity {
...


@Entity
@Table(name = "BF_STATUS")
@DiscriminatorValue("Status")
public class Status extends Activity {
...

Again note that for both implementations i have set a DiscriminatorValue.

Finally, I want to have a Person object, and the person can have a list of Status and a list of ToDo – I also want to capture the bi-directional relationship, so am modelling it using the mappedBy configuration, but in both cases using the “raisedBy” field that exists in the super class “Activity”:

public abstract class Person {

    @ManyToMany(mappedBy="raisedBy", targetEntity=Activity.class)
    private List<ToDo> todoItems = new ArrayList<ToDo>();

As i am using mappedBy with the member variable “raisedBy” from the super class I have also specified the targetEntity (otherwise it is not able to find the field in the ToDo object).

The problem is when I try to call getTodoItems() – it is actually just returning all “Activity” objects linked by “raisedBy” to the current person. e.g. it throws a cast exception because it is expecting the list of ToDos but Hibernate is returning Status objects in the list as well.

I was hoping the mappedBy config along with DiscriminatorValue would be enough to make this work – has anyone come across this or resolved it?

Thanks


EDIT

I have just found this post:

Can someone point me in the direction of a good @Where overview and example? could I just update my person as follows to use @Where with the discriminator column?

public abstract class Person {

    @ManyToMany(mappedBy="raisedBy", targetEntity=Activity.class)
    @Where(clause="activityType=Todo")
    private List<ToDo> todoItems = new ArrayList<ToDo>();
  • 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-23T22:18:56+00:00Added an answer on May 23, 2026 at 10:18 pm

    Add the annotation :
    @Where(clause = “activityType= ‘Todo'”)

    But it’s a hibernate annotation, not JPA

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

Sidebar

Related Questions

Hey I am developing an desktop application using Spring and Hibernate, and I have
I am developing a web application using Struts 2.1.2 and Hibernate 3.2.6.GA. I have
I am developing an application using oracle 11g, Java(struts2) and Hibernate. I have table
I am developing an application using MVC Preview 5. I have used typed views.
I am developing a java web application using hibernate as ORM. Is it possible
I am developing an application using SPRING 3.0.4, JPA 2, Hibernate 3.5.5. I an
I am developing an application and using in-app purchases in it. i have created
I'm developing a web application using Wicket+Spring+JPA+Hibernate. This is my first project with this
I'm developing an example web-application, using JPA 2.0 entities, Hibernate 3.6.2 and Spring 3.
I'm currently developping an application in java using Hibernate as a persistence manager 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.