We're updating the issue view to help you get more done. 

NullPointerException querying against inherited properties of a MappedSuperclass.

Description

I have created an Embeddable class that serves as a table key that extends an already defined MappedSuperclass which results in a composite-key for the table.

BaseId.java

1 2 3 4 5 6 @MappedSuperclass public class BaseId implements Serializable { private Long customerId; private Long facilityId; /* getter/setters */ }

MyEntityId.java

1 2 3 4 5 @Embeddable public class MyEntityId extends BaseId { private Long type; /* getter/setters */ }

Now using the JPA Criteria API shown below, the code throws a NullPointerException when attempting to find the records:

TestCase.java

1 2 3 4 5 6 7 8 9 10 11 public List<MyEntity> runTestCase(List<Long> customerIds) { CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<MyEntity> cq = cb.createQuery(MyEntity.class); Root<MyEntity> root = cq.from(MyEntity.class); // this next statement is where the NullPointerException is thrown. Path<Long> customerIdPath = root.get(MyEntity_.id).get(MyEntityId_.customerId); cq.select(root); cq.where(customerIdPath.in(customerIds)); return em.createQuery(cq).getResultList(); }

After fiddling with this, I have determined that if the BaseId class is associated to another class designated as an Entity, then the NullPointerException isn't thrown an the above query works. However, if the BaseId isn't associated to any entity and merely serves as a common class across a series of derived classes, Hibernate will throw the following error:

1 2 java.lang.NullPointerException at org.hibernate.jpa.criteria.path.AbstractPathImpl.get(AbstractPathImpl.java:140)

Environment

Hibernate 4.3.5 Final

Status

Assignee

Unassigned

Reporter

Chris Cranford

Fix versions

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

4.3.5
5.0.4
4.3.7
5.0.2

Priority

Major