Given:
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name="postType", discriminatorType=DiscriminatorType.STRING)
public class Post {}
@DiscriminatorValue(value = PostType.BUG)
public class BugReport extends Post {}
That is ... Bugs start life in this system as a Post. Later, they can be promoted(?) to being a BugReport.
I'm using the following approach to update this:
@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;
}
Although this works, (the post type is changed, and returned from the db as a BugReport
). I'm curious if there are any side effects or risks associated with this approach.