1
私は複数のID列を持つ@Entityクラスを持っていて、それらはすべて外部キーです。私はNews
エンティティのdate
コラムでCriteria
にRestriction
を追加したい@Idである@JoinColumnに参加できません
@Entity
@Immutable
@Table(name = "AnyNews")
public class AnyNews implements Serializable {
private static final long serialVersionUID = 43876852L;
@Id
@Column(name = "id")
private int id;
@Id
@OneToOne
@JoinColumn(name = "news_id")
private News news;
.....
}
:クラスのコードは次のようになります。だから私はこのような基準を作っ:
Criteria criteria = sessionFactory.getCurrentSession()
.createCriteria(AnyNews.class, "any")
.createCriteria("news", "news");
.add(Restrictions.eq("news.id", id))
.add(Restrictions.ge("news.date", from.getTime()));
コードがよさそうだが、それはのようなエラーになります:
org.hibernate.exception.SQLGrammarException: could not execute query
...
問題が原因で文を参加行方不明の原因とされました。クエリにJoin文がありませんでした。
select
this_.id as news4_5_0_,
this_.news_id as keyword1_5_0_,
this_.board_no as board2_5_0_,
this_.seq as seq5_0_
from
AnyNews this_
where
this_.news_id=?
and news1_.date>=?
なぜHibernateはこのようなクエリを作成しますか?同じ列で@Idと@JoinColumnアノテーションを使用することはできませんか?