问题是当我应该获取一些元素时,我在查询中得到空结果。这是代码:
DetachedCriteria criteria = DetachedCriteria.forClass(Article.class);
DetachedCriteria authorCriteria = criteria.createCriteria("author");
authorCriteria.add(Restrictions.eq("id",((User)session.getAttribute("user")).getId()));
List<Article> articles = articleManager.findArticleByCriteria(criteria);
@Entity
@Table(name = "ARTICLES")
public class Article {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
Integer id;
@ManyToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "author_fk")
Writer author;
@Column(length = 10000)
String content;
String title;
@Transient
String shortContent;
...
}
我希望得到特定作者的文章。
@编辑
id content date flagEditor flagWriter title author_fk editor_fk
30 nweINSERT INTO `WRITERS` (`USER_ID`) VALUES<br>(9)... 2013-06-02 13:14:55 0 0 new 9 NULL
31 INSERT INTO `WRITERS` (`USER_ID`) VALUES<br>(9);IN... 2013-06-02 13:20:04 0 0 dsfsafadsf 9 NULL
32 sdf((User)session.getAttribute("user"))((User)sess... 2013-06-02 13:35:33 0 0 frefds 9 NULL
休眠 SQL: http: //pastebin.com/yfPz6aDb
好的,我发现了问题:
public List<Article> findByCriteria(DetachedCriteria criteria){
List<Article> articles = null;
articles = criteria.getExecutableCriteria(HibernateUtil.getSession()).list();
//return value wasn't assignet do articles
return articles;
}
谢谢大家的承诺:)