使用连接继承覆盖hibernate实体的外键约束

时间:2015-10-29 16:35:23

标签: java hibernate jpa

是否可以帮助我使用ForeignKey约束名称覆盖以进行以下设置:

Base.java

@MappedSuperclass
public abstract class Base
{

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    protected Long id;

    public Long getId()
    {
        return id;
    }

}

CreateUpdateTimestampableBase.java

@MappedSuperclass
public abstract class CreateUpdateTimestampableBase extends Base {}

AbstractUser.java

@Entity
@Table(name = "abstract_users")
@Access(AccessType.FIELD)
@Inheritance(strategy = InheritanceType.JOINED)
@DiscriminatorColumn(name = "user_type", discriminatorType = DiscriminatorType.STRING, length = 15)
abstract public class AbstractUser extends CreateUpdateTimestampableBase {}

User.java

@Entity
@Table(name = "users")
@Access(AccessType.FIELD)
@DiscriminatorValue("user")
public class User extends AbstractUser {}

我尝试@PrimaryKeyJoinColumn(name = "id", foreignKey = @ForeignKey(name = "...")),它更改了主键列名称,但它并不尊重外键。我也试过了@AssociationOverride(),但无法让它发挥作用......有什么想法吗?

目前我的FK名称已被破坏,如:fk_ncwxer8x284o9w96xjk9uxfh7

我不想使用自定义命名策略,因为带有错误名称的默认策略使我更容易找到我自己没有声明的外键,并且以后更容易处理liquibase依赖项对我来说。

这基本上是duplicate of this unanswered question

0 个答案:

没有答案