学生のエイリアス(user_name)が一意であることを確認するための休止状態のクエリがあります。これは非常にうまく機能しています。これは私のコードです。
public Boolean isAliasUniqueInStudent(String alias)
{
Session session = getHibernateTemplate().getSessionFactory().openSession();
ProjectionList p = Projections.projectionList().add(Projections.rowCount());
org.hibernate.criterion.Conjunction exist=(Conjunction)Restrictions.conjunction().add(Restrictions.isNotNull("username")).add(Restrictions.eq("username",alias));
Criteria criteria = session().createCriteria(Student.class).setProjection(p).add(exist);
Long result=(Long)criteria.uniqueResult();
closeSession(session);
return result.intValue()==0;
}
これは、このような選択を作成しています。
select count(*) as y0_ from student this_ where (this_.username is not null and this_.username=?)
これはとても良いですが、次のような選択を試すことができるのではないかと思っていました
select count(username) as y0_ from student this_ where (this_.username is not null and this_.username=?)
これは私のよりも良いアプローチですか?
より良いものはありますか?
プロパティがnullではないことを確認していることは知っていますが、休止状態でこれを行うことは可能ですか。
select count(name)
どうもありがとう。