后面试着加了一下transaction的annotation,就发现存入数据库了。
具体为什么,不清楚。但感觉貌似dao中的方法必须加了transaction的annotation
它才能正常执行。
@Component("bookmarkDao") public class BookmarkDao extends GenericDao<Bookmark, Long>{ public BookmarkDao(){ super(); this.entityClass = Bookmark.class; } @Transactional(propagation=Propagation.REQUIRED, readOnly=false) public Bookmark distinctSave(Bookmark entity){ String hql = "from Bookmark where url = ?"; List list = this.find(hql, entity.getUrl()); if(list == null || list.size() == 0){ return this.save(entity); } else { return (Bookmark)list.get(0); } } }
想看具体点的信息
可以看 http://www.189works.com/article-81234-1.html