I'm trying to access a property defined in @MappedSuperclass
in a Criteria Query
with JPA meta-model (Hibernate 4.2.8):
@MappedSuperclass
public class BaseEntity {
private DateTime createdOn;
}
My Entity:
@Entity
@Table(name = "HISTORY")
public class History extends BaseEntity implements Serializable {
private Long id;
}
How to access createdOn
?
CriteriaBuilder cb = getEntityManager().getCriteriaBuilder();
CriteriaQuery<History> c = cb.createQuery(History.class);
Root<History> h = c.from(History.class);
h.orderBy(cb.asc(a.get(History_.createdOn)));
History_:
@Generated(value = "org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor")
@StaticMetamodel(History.class)
public abstract class History_ extends com.test.BaseEntity_ {
public static volatile SingularAttribute<History, Long> id;
}
Is there a way to access base class' properties?
Of course there is a way. As I see in your code, you already access it:
History_.createdOn
is a property of the MappedSuperclass. If by "to access" you mean to select, than you simply do: