I'm trying to create a inheritance with TABLE_PER_CLASS strategy, but i want to have different primary key for each table is it possible?
I've one class Register which has millions of instances, some of these instances are "special" and have different rules for theirs columns and extra columns.
@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;
}
For the basic register I dont need an Id attribute because I've one unique column, but for the specialized entity that column is not unique so I added an extra attribute.
the problem is that hibernate is using the parent id to created a composite primary key (the generated schema is):
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)
)
The columns are right and the schama is what i want, but I would like to remove the "id" member from PotencialRegister primary key.