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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T19:14:21+00:00 2026-05-15T19:14:21+00:00

In my model I have an abstract User class, and multiple subclasses such as

  • 0

In my model I have an abstract “User” class, and multiple subclasses such as Applicant, HiringManager, and Interviewer. They are in a single table, and I have a single DAO to manage them all.

User:

@Entity
@Table(name="User")
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(
    name="role",
    discriminatorType=DiscriminatorType.STRING
)
public abstract class User extends BaseObject implements Identifiable<Long> ...

HiringManager (for example):

@Entity
@DiscriminatorValue("HIRING_MANAGER")
public class HiringManager extends User ...

Now if I wanted to, say, get all the hiring managers that are not associated with a department, how would I do that? I imagine it would look something like:

DetachedCriteria c = DetachedCriteria.forClass(User.class);
c.add(Restrictions.eq("role", "HIRING_MANAGER"));
c.add(Restrictions.isNull("department"));
List<User> results = getHibernateTemplate().findByCriteria(c);

But when I run this, Hibernate complains “could not resolve property: role” (Which actually makes sense because the User class really doesn’t have an explicit role property)
So what’s the right way to do what I’m trying to do?

  • 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-15T19:14:22+00:00Added an answer on May 15, 2026 at 7:14 pm

    I may be missing something obvious but since you want to find hiring managers, why don’t you just pass the HiringManager subclass as the class to the Criteria?

    Just in case, there is a special class property that you can use to restrict a query to a subtype. From the Hibernate reference documentation:

    14.9. The where clause

    …

    The special property class accesses
    the discriminator value of an instance
    in the case of polymorphic
    persistence. A Java class name
    embedded in the where clause will be
    translated to its discriminator value.

    from Cat cat where cat.class = DomesticCat
    

    You can use this special class property with the Criteria API too, but with a minor change: you have to use the discriminator value as value.

    c.add(Restrictions.eq("class", "HIRING_MANAGER"));
    

    Unlike with HQL, it looks like Hibernate is not doing the translation with the Criteria API. I don’t really like the idea of using the discriminator value in the code and there is maybe another cleaner way but I’m not aware of it. But it works.

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

Sidebar

Related Questions

I have the following abstract Django models: class Food(models.Model): name = models.CharField(max_length=100) class Meta:
I have a model that looks something like this: public abstract class Parent {
I have the following Model pattern: public abstract class PARENTCLASS {...} public class CHILD_A_CLASS
I have the following classes in my Model: public abstract class Entity : IEntity
I have two classes (MVC view model) which inherits from one abstract base class.
In Grails 1.3.7, I have a domain model like this: abstract class A {
I have a code: Model.java: public abstract class Model <T> { public static <T>
I have this in my models.py: class AuditableTable(models.Model): class Meta: abstract = True created_by
I have this classes interface UserInterface Then abstract class user implements UserInterface Then i
I have some models like that: class BaseModel(models.Model): created_by = models.ForeignKey(User, related_name=%(app_label)s_%(class)s_created) created_date =

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.