Hibernate中DetachedCriteria使用注意点-1

Hibernate中DetachedCriteria使用注意点-1
代码一:
    DetachedCriteria dc  =  DetachedCriteria.forClass(classT,  " p " );
    dc.add(Restrictions.eq(
" purePeptide " , purePeptide));
    dc.add(Restrictions.eq(
" project.id " , projectId));
    dc.addOrder(Order.asc(
" peptide " ));

代码二:
    DetachedCriteria dc  =  DetachedCriteria.forClass(classT,  " p " );
    dc.add(Restrictions.eq(
" p.purePeptide " , purePeptide));
    dc.add(Restrictions.eq(
" project.id " , projectId));
    dc.addOrder(Order.asc(
" peptide " ));

两段代码唯一的区别就是第二句是使用"purePeptide"还是"p.purePeptide"。
代码一产生的sql语句:
select this_.purePeptide as y1_, this_.peptide as y2_ from SequestPeptide this_ where y1_ = 'NASILLEELDLEK' and this_.project_id=1 order by y2_ asc
运行会报Unknown column name:Y1_

代码二产生的正确的sql语句:
select this_.purePeptide as y1_, this_.peptide as y2_ from SequestPeptide this_ where this_.purePeptide='NASILLEELDLEK' and this_.project_id=1 order by y2_ asc


你可能感兴趣的:(Hibernate中DetachedCriteria使用注意点-1)