public void createBlogItem(final Long blogid, final String title,
final String content) throws HibernateException {
this.getHibernateTemplate().execute(new HibernateCallback() {
public Object doInHibernate(Session session)
throws HibernateException, SQLException {
BlogItem item = new BlogItem();
item.setTitle(title);
item.setContent(content);
item.setCreateTime(Calendar.getInstance());
Blog blog = (Blog) session.load(Blog.class, blogid);
item.setBlog(blog);
blog.getItems().add(item); // no need to fetch the collection!
//P295 say, it will automatically called
//I tested it, cant work yet!
//it's used by EJB2.0 CMP
return null;
}
});
}