如果下的类:
public class Sample {
private String indexId; // 主键
private String id; // 非主键
public String getIndexId() {}
public String setIndexId() {}
public String getId() {}
public String setId() {}
}
如下查询时将出现问题:
from Sample s where s.id=?
在Hibernate执行的时候,后面的where条件将翻译为:
where s.indexId
因为在给一个映射类定义私有成员的时候,如果该成员不是主键,则避免将其命名为id。
另外,映射类中避免将boolean类型的私有成员命名以is开头,比如isChecked,这样也会出现问题。