Здравствуйте!
Как можно сделать общий первичный ключ для нескольких таблиц в Hibernate?
например у меня есть Entity классы:
@Data
@Entity
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Table(schema = "info")
public class BaseEntity {
@Id
@GeneratedValue(generator = "UUID")
@GenericGenerator(
name="UUID",
strategy = "org.hibernate.id.UUIDGenerator"
)
@JsonIgnore
private UUID id;
@OneToOne(mappedBy = "information")
private UserDto userDto;
@OneToOne(mappedBy = "information")
private Address address;
}
@Data
@Entity
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class UserDto{
@Id
@GeneratedValue(generator = "UUID")
@GenericGenerator(
name="UUID",
strategy = "org.hibernate.id.UUIDGenerator"
)
@JsonIgnore
private UUID id;
@Column(name = "users_name")
private String name;
@Column(name = "users_inn")
private String inn;
@Column(name = "users_phone")
private String phone;
@Column(name = "users_brand")
private String brand;
@Enumerated(EnumType.STRING)
@Column(name = "users_type")
private UserTypes userType;
}
@Data
@AllArgsConstructor
@NoArgsConstructor
@Entity
public class Address {
@Id
@GeneratedValue(generator = "UUID")
@GenericGenerator(
name="UUID",
strategy = "org.hibernate.id.UUIDGenerator"
)
@JsonIgnore
private UUID id;
@OneToMany(mappedBy = "address")
private List<Depart> departs;
}
@Data
@AllArgsConstructor
@NoArgsConstructor
@Entity
public class Depart{
@Id
@GeneratedValue(generator = "UUID")
@GenericGenerator(
name="UUID",
strategy = "org.hibernate.id.UUIDGenerator"
)
@JsonIgnore
private UUID id;
@JsonAlias(value = "CODE")
private String code;
@JsonAlias(value = "NAME")
private String name;
}
P.s Заранее спасибо!