我的模特是这样的:
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
@DiscriminatorColumn(name = "resourceType", discriminatorType = DiscriminatorType.INTEGER)
public abstract class Resource {
@Id
@GeneratedValue(strategy = GenerationType.TABLE)
Long id;
String foo;
}
@MappedSuperclass
public abstract class NetworkResource extends Resource {
String bar;
}
@Entity
@DiscriminatorValue(value = "1")
public class URL extends NetworkResource {
String url;
}
我将歧视值放在所有更具体的实现中,因为我不想在大多数时间加入所有扩展资源的表,我将仅加入networkresource
表,例如。 / p>
所以,我想知道我该怎么做。
我已尝试过类似的内容:
SELECT c FROM URL c LEFT JOIN c.resource r where r.resourceType = 1 and r.url = :ip
但是当我添加r.resourceType = 1
时,我收到了编译错误。
那么,我该怎么做?
感谢。
答案 0 :(得分:0)
基于对你要做什么的一些假设,我认为你只是想要:
select c from URL c where c.url = :ip
Hibernate将负责添加连接和限制器的限制。这就是Hibernate的用途。