鉴于:
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name="postType", discriminatorType=DiscriminatorType.STRING)
public class Post {}
@DiscriminatorValue(value = PostType.BUG)
public class BugReport extends Post {}
那是…bug在这个系统中作为一个帖子开始生命。以后可以升职(?)成为一个错误报告。
我使用以下方法更新此:
@Transactional
public Post setPostType(Post post, String postType)
{
SQLQuery sql = getSession().createSQLQuery("UPDATE post SET postType = :postType where id = :id");
sql.setString("postType", postType);
sql.setInteger("id", post.getId());
sql.executeUpdate();
getSession().evict(post);
getSession().flush();
Post newPost = get(post.getId());
return newPost;
}
尽管这样做有效,(post类型被更改,并作为
BugReport
)我很好奇这种方法是否有任何副作用或风险。