System.out.println("p"+mo.getUser());
这是我的代码
List<MyObject> lp = (List<MyObject>) sessionFactory.getCurrentSession().createCriteria(MyObject.class).list();
for (MyObject mo: lp) {
System.out.println("p"+mo.getUser());
}
你知道什么可能导致这种行为吗? 这可能是愚蠢的,但我找不到解决方案。 感谢
MyObject代码:
package soc.entities;
import java.math.BigDecimal;
import java.util.Date;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Column;
/**
* Part generated by hbm2java
*/
@Entity
@Table(name="Part")
public class MyObcejet {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private Integer id;
@Column
private String user
public Part() {
}
public Integer getId() {
return this.id;
}
public void setId(Integer id) {
this.id = id;
}
public String getUser() {
return this.user;
}
public void setUser(String user) {
this.user = user;
}
}
答案 0 :(得分:0)
请使用以下行以避免重复的对象
criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
答案 1 :(得分:0)
我设法解决了这个问题。实际上MyObject实例变量与我的表列名不对应。谢谢!