プロバイダーとして Hibernate 4.2.0-Final で JPA 2 を使用しており、次のエンティティがあります。
@Entity
@Inheritance(strategy=InheritanceType.JOINED)
public class Person {
@Id
private String id;
.. Person attributes ..
.. Getters/Setters ..
}
@Entity
@Table(uniqueConstraints={@UniqueConstraint(name="UniqueCode", columnNames="code")})
public class Customer extends Person {
@Column(nullable=false)
private String code;
.. Other Customer attributes ..
.. Getters/Setters ..
}
そして、私は次のJPQLを持っています:
SELECT count(distinct c.code) FROM Customer c
どの Hibernate が次の SQL を生成しているか:
select
count(distinct customer0_.code) as col_0_0_
from
Customer customer0_
inner join
Person customer0_1_
on customer0_.id=customer0_1_.id
しかし、Customer に固有のフィールドである個別のコードで Customers をカウントするだけでよいため、「Person」への内部結合は必要ありません。Hibernate に次のような SQL を生成してもらいたい (つまり、テーブル 'Person' を結合せずに):
select
count(distinct customer0_.code) as col_0_0_
from
Customer customer0_
不要な内部結合を避けるように Hibernate に指示する方法はありますか? たぶん、Hibernate 固有のクエリ ヒントでしょうか。