我们有一个Phone
类,它使用Role
s,即
@Entity
public class Phone{
@Id...
private Integer id;
@Column(name="role_id")
private IRole role;
...
和界面
public interface IRole extends Serializable {
public abstract Integer getId();
...
因此,当我尝试将Phone
保留在我的软件包中时,IRole
不再是抽象的,它已经是一个具体的实体。我之所以不能直接使用具体的类,是因为我们在项目中实现了Role
的不同方式。
当我尝试启动休眠模式时,出现异常:
org.hibernate.tool.schema.spi.SchemaManagementException: Schema-validation: wrong column type encountered in column [role_id
] in table [phone]; found [int4 (Types#INTEGER)], but expecting [bytea (Types#VARBINARY)]
我认为IRole
引起了问题。它应该存储id
中的Role
-在我们所有的实现中都可用。如何告诉Hibernate应该使用Integer
类型而不是某些interface
插值?
正在寻找一种在Postgres
和MariaDB
中都适用的解决方案。
答案 0 :(得分:1)
您可以为IRole
接口的每个特定实现实现一个attribute converter,然后使用它们。
@Convert(converter=RoleA.class)
@Column(name="role_id_a")
private IRole roleA;
@Convert(converter=RoleB.class)
@Column(name="role_id_b")
private IRole roleB;