hibernate - How can I change DiscriminatorValue of entity
问题描述
I would ask you about opportunity to change DiscriminatorValue for some entyty. For example I have 2 entity:
@Entity
@Table(name = "user")
@Inheritance(strategy=InheritanceType.JOINED)
@DiscriminatorColumn(name = "user_type")
@DiscriminatorValue("CUSTOMER")
public class User
and
@Entity
@Table(name = "businessUser")
@DiscriminatorValue("FOUNDER")
public class BusinessUser extends User
I have repos:
@NoRepositoryBean
public interface UserBaseRepository<T extends User> extends JpaRepository<User, Long> {
T findByEmail(String email);
}
@Transactional
@Repository("UserRepository")
public interface UserRepository extends UserBaseRepository<User> {
}
@Transactional
@Repository("BusinessUserRepository")
public interface BusinessUserRepository extends UserBaseRepository<BusinessUser> {
}
At first I created simple user. This entity has user_type CUSTOMER. Then I would like to expand that entity and modify it to BusinessCustomer. When I tried to do it the following: find user entity and to cast to businessUser entity I get IllegalCastException. I cannot to cast User to BusinessUser.
Help me please, How I can change user_type or or update user to businessUser.
Have a nice day, Thanks
解决方案
为了做这样的事情,我认为你不得不使用原生查询。实际上,我确实认为在所描述的情况下使用继承并不是最好的选择,但那是另一回事了。
推荐阅读
- html - 如何使用 html div 和 css 制作形状
- visual-studio-2015 - 将 VS2015 迁移到 VS2019 参考缺失
- php - 为什么我会在批量删除中获得 DataProvider\Document 实例?
- amazon-web-services - Aws Dynamodb - 如何在 cloudformation 中重用自动缩放的 ScalableTarget
- ffmpeg - ffmpeg 如何确定图像的大小并拉伸视频以适合它?
- cordova - Ionic 4:从另一个应用程序(图库/文件浏览器)向应用程序发送文件
- html - 如何让我的 CSS 媒体查询正常工作?
- javascript - 更新用户个人资料,而无需将任何内容更新到 Firestore
- python - Jupyter:InvocationException:未找到 GraphViz 的可执行文件
- scala - 如何将Scala Dataframe从宽转长并从宽转回长