代碼一:
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"));
兩段代碼唯一的區(qū)別就是第二句是使用"purePeptide"還是"p.purePeptide"。
代碼一產(chǎn)生的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
運(yùn)行會報Unknown column name:Y1_
代碼二產(chǎn)生的正確的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