我在 MySQL 中创建了一个表:
'object_label' 与列 'id' 和 'name'。我在这个表中插入了值。
在java中我创建了新类-'ObjectLabel':
import javax.persistence.*;
@Entity
@Table(name = "object_label")
public class ObjectLabel implements Serializable {
private static final long serialVersionUID = 3475812350796110403L;
private String name;
public Long getId() { return id; }
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(precision = 10, unique = true, nullable = false, updatable = false)
public Long getId() {
return id;
}
public void setId( Long id ) {
this.id = id;
}
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @param name the name to set
*/
public void setName(String name) {
this.name = name;
}
}
在 hibernate.cfg.xml 中定义:
<mapping class="com.myCompany.model.ObjectLabel" />
我想从桌子上得到价值,我定义了服务:
@SuppressWarnings( "unchecked" )
@Transactional( readOnly = true, propagation = Propagation.SUPPORTS )
public Collection<T> findAll() {
Session session = getSessionFactory().getCurrentSession();
return
session.createCriteria( persistentClass
).setResultTransformer( Criteria.DISTINCT_ROOT_ENTITY
).list();
}
我得到空列表。
在数据库 'select * from 'object_label'' 返回值)
我的代码有什么问题?
谢谢!