我有超类:
@MappedSuperclass
public abstract class BaseEntity {
@Id @GeneratedValue
private Long id;
@Version
private long version;
}
和两个子类:
@Entity
@Table(name = "\"user\"")
public class User extends BaseEntity {
private String username;
@org.hibernate.annotations.Type(type = "yes_no")
private boolean isAdmin;
// constructor/getters/setters etc.
}
@Entity
public class Product extends BaseEntity {
public String name;
public BigDecimal price;
// constructor/getters/setters etc.
}
我可以使用代码查询所有子类:
entityManager.unwrap(Session.class)
.createCriteria(BaseEntity.class)
.list()
.forEach(x -> System.out.println(x));
如何通过JPA获得相同的结果(没有unwrap
,是否可能?)。我尝试使用createQuery("from BaseEntity")
,但获得BaseEntity not mapped
例外。