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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:52:09+00:00 2026-05-26T11:52:09+00:00

I have two classes, Employee and Manager. Manager extends Employee, as it is a

  • 0

I have two classes, Employee and Manager. Manager extends Employee, as it is a type of employee. Employee has an instance of Manager, which represents the idea of an employee having one manager. Conversely, manager has a set of Employees. There are two tables, EMPLOYEE and MANAGER:

table EMPLOYEE
  long ID
  varchar NAME
  long MANAGERID

table MANAGER
  long ID
  long EMPLOYEEID //a join on this field enables inheritance

The classes look like this:

Employee.java (setters and getters omitted for brevity):

@Entity
@Inheritance(strategy = InheritanceType.JOINED)
@Table(name = "EMPLOYEE", schema = "TEST01")
public class Employee extends hata.util.Entity implements java.io.Serializable {

    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    @Column(name = "ID", unique = true, nullable = false)   
    protected Long id;

    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "MANAGERID")
    protected Manager manager;

    @Column(name = "FIRSTNAME", nullable = false, length = 50)
    protected String firstname;

Manager.java

@Entity
@PrimaryKeyJoinColumn(name="EMPLOYEEID")
@Table(name = "MANAGER", schema = "TEST01")
public class Manager extends Employee implements java.io.Serializable {

    @OneToMany(fetch = FetchType.LAZY, mappedBy = "manager")
    private Set<Employee> employees = new HashSet<Employee>(0);

I have filled the tables with a few employees, and all of those employees have the same manager, except for one employee – the one who is the manager. He himself has no manager. (If you’re following me correctly, then it should be obvious that I have 1 row in the manager table, with and EMPLOYEEID referring back to a row in the EMPLOYEE table that has null as it’s MANAGERID).

So, this setup looked correct to me, however when I tried to query all Employee objects with:

Query q = em.createQuery("select em from Employee em");
result = (List<Employee>) q.getResultList();

I get a nasty stack trace:

Caused by: org.hibernate.PropertyAccessException: could not set a field value by reflection setter of hata.staff.entity.Employee.manager
at org.hibernate.property.DirectPropertyAccessor$DirectSetter.set(DirectPropertyAccessor.java:151)
at org.hibernate.tuple.entity.AbstractEntityTuplizer.setPropertyValues(AbstractEntityTuplizer.java:586)
at org.hibernate.tuple.entity.PojoEntityTuplizer.setPropertyValues(PojoEntityTuplizer.java:231)
at org.hibernate.persister.entity.AbstractEntityPersister.setPropertyValues(AbstractEntityPersister.java:3824)
at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:153)
at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:898)
at org.hibernate.loader.Loader.doQuery(Loader.java:773)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:270)
at org.hibernate.loader.Loader.doList(Loader.java:2294)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2172)
at org.hibernate.loader.Loader.list(Loader.java:2167)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:448)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:363)
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:196)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1258)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:102)
at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:236)
… 108 more
Caused by: java.lang.IllegalArgumentException: Can not set hata.staff.entity.Manager field hata.staff.entity.Employee.manager to hata.staff.entity.Employee
at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:164)
at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:168)
at sun.reflect.UnsafeObjectFieldAccessorImpl.set(UnsafeObjectFieldAccessorImpl.java:81)
at java.lang.reflect.Field.set(Field.java:680)
at org.hibernate.property.DirectPropertyAccessor$DirectSetter.set(DirectPropertyAccessor.java:139)
… 124 more

Did I code this wrong, or can hibernate simply not handle this scenario? I’d appreciate any assistance.

  • 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-26T11:52:10+00:00Added an answer on May 26, 2026 at 11:52 am

    The EMPLOYEEID column in manager shouldn’t be there. @PrimaryKeyJoinColumn means that the primary key is also the join column. So, the ID column in MANAGER is both the primary key and the foreign key to EMPLOYEE.

    And the annotation should of course be changed to @PrimaryKeyJoinColumn(name="ID") (or it must be removed, since the default is to use the same column name as in the parent table)

    See http://download.oracle.com/javaee/6/api/javax/persistence/PrimaryKeyJoinColumn.html.

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

Sidebar

Related Questions

I have two classes. One is called Employee and the other EmployeeDetails that has
I have two classes in Grails application , Employee has hasMany(one To Many relations)
I have two classes, and want to include a static instance of one class
I have two classes Event and Review. The event has an instance object Review
I have two classes: Employee and EmployeeGridViewAdapter . Employee is composed of several complex
I have two classes Address and Employee as follows: public class Address { public
I have two classes that each need an instance of each other to function.
I am currently working on a project which has Employee, Manager entities. At the
I have two java classes. One is NewFrame.java where the forms(buttons, textfields) are located.
I have 3 classes, two inherit from 1: public class Employee { private virtual

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.