java继承主键_java – 使用不同主键的Hibernate继承

我正在尝试使用TABLE_PER_CLASS策略创建继承,但我想为每个表创建不同的主键是否可能?

我有一个类Register,它有数百万个实例,其中一些实例是“特殊的”,并且对于它们的列和额外的列有不同的规则.

@MappedSuperclass

public abstract class Register {

@Id

@Column(nullable = false, unique = true, updatable = false)

private Long userId;

private Date checked;

@Column(nullable = false)

private RegisterState tipo;

}

@Entity

@AttributeOverrides({ @AttributeOverride(name = "userId", column = @Column(nullable = false, unique = false, updatable = false)) })

public class PotencialRegister extends Register implements Serializable {

@Id

@GeneratedValue(strategy = GenerationType.IDENTITY)

private Integer id;

@Column(length = 64, nullable = false, unique = false)

private String referer;

}

对于基本寄存器,我不需要Id属性,因为我有一个唯一的列,但对于专用实体,该列不是唯一的,所以我添加了一个额外的属性.

问题是hibernate使用父id创建了一个复合主键(生成的模式是):

create table PotencialRegister (

id integer not null,

userId bigint not null,

checked datetime(6),

tipo integer not null,

referer varchar(64) not null,

primary key (id, userId)

)

create table Register (

userId bigint not null,

checked datetime(6),

tipo integer not null,

primary key (userId)

)

列是正确的,schama是我想要的,但我想从PotencialRegister主键中删除“id”成员.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值