Say I have a class with a subclass:
@Entity
@Table(name = "TABLE_A")
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public class ClassA {
// columns
@Entity
@Table(name = "TABLE_B")
public static class ClassB extends ClassA {
// extra columns
}
}
When I want to query TABLE_A I try session.createCriteria(ClassA.class)
, but it ends up giving me results from both TABLE_A and TABLE_B. How can I make it only get results from TABLE_A (ie the parent class only)?
使用type
函数:
select a from ClassA a where type(a) not in (ClassB)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.