I am trying to figure out how to save all my entities by saving just the parent entity. I know how to save the parent only, but need to also persist the children. My odd issue is I have a custom class (AnnouncementExternalIds) that does not have a DB table.
Annoucement=parent
AnnouncementCustomer=child
AnnouncementOffice=child
AnnouncementExternalIds=does not have a DB table
When I use session.merge on an AccounementData object, I’d like for it to persist to the Announcement table and then each AnnouncementCustomer and AnnouncementOffice saves as a record to each other their DB tables.
@Entity
@Table(name = "ANNOUNCEMENT")
public class AnnouncementData {
@Id
private long id;
private AnnouncementExternalIds announcementExternalIDs;
}
public class AnnouncementExternalIds {
private List<AnnouncementCustomerId> announcementCustomerIds = new ArrayList<>();
private List<AnnouncementOfficeId> announcementOfficeIds = new ArrayList<>();
}
@Entity
@Table(name = "ANNOUNCEMENT_CUSTOMER_ID")
public class AnnouncementCustomerId {
@Id
private long customerId;
private int tenantId;
private long announcementId;
}
@Entity
@Table(name = "ANNOUNCEMENT_OFFICE_ID")
public class AnnouncementOfficeId {
@Id
private long officeId;
private int tenantId;
private long announcementId;
}
Tony is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.