Answer the question
In order to leave comments, you need to log in
Can one table in Hibernate inherit the ID of a second table?
I have the entities described below (PartnerInformation, Activity, Address), how can I make the Activity and Address entities inherit id from PartnerInformation?
@Data
@Entity
@Builder
@AllArgsConstructor
@NoArgsConstructor
@JsonNaming(PropertyNamingStrategies.UpperSnakeCaseStrategy.class)
public class PartnerInformation {
@Id
@GeneratedValue(generator = "UUID")
@GenericGenerator(
name="UUID",
strategy = "org.hibernate.id.UUIDGenerator"
)
@JsonIgnore
private UUID id;
@JsonProperty("ID")
public String externalId;
private boolean isActive = true;
@OneToOne(cascade=CascadeType.ALL)
private Activity activity;
@OneToMany(cascade=CascadeType.ALL)
private List<Address> address;
}
Answer the question
In order to leave comments, you need to log in
Good afternoon.
So maybe you do not need a OneToOne connection, but you need @Embeddable
it for an Activity and instead of a OneToMany connection for a List, use @ElementCollection
or @CollectionOfElements
for List<Address>
https://stackoverflow.com/questions/8969059/differ...
https://www.baeldung.com/jpa- embedded-embeddable
If you want to embed an ID, you can probably look at @EmbeddedId
https://www.baeldung.com/spring-jpa-embedded-metho...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question