2
鉴于有关的风险:休眠:不断变化的DiscriminatorValue
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name="postType", discriminatorType=DiscriminatorType.STRING)
public class Post {}
@DiscriminatorValue(value = PostType.BUG)
public class BugReport extends Post {}
这是...错误在这个系统中作为后重新开始生活。之后,他们可以被提升(?)成为BugReport。
我用下面的方法来更新这个:
@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;
}
虽然这工作,(岗位类型改变,并从数据库返回的BugReport
)。我很好奇,如果有任何副作用或与此方法相关的风险。