When a new object persists, an error occurs with the collection.

FK not found

Here is the mapping:

@Entity(name = "CRM_TASKDEPARTURE") @Access(AccessType.PROPERTY) @DiscriminatorValue(value = TaskType.Consts.VISIT_ID) public class TaskVisit extends Task { private static final long serialVersionUID = 1L; private List<TaskVisitAddress> addresses = new ArrayList(); public TaskVisit() { } @OneToMany(fetch = FetchType.LAZY,cascade = CascadeType.PERSIST,mappedBy = "taskVisit") public List<TaskVisitAddress> getAddresses() { return addresses; } } 

Map object collection:

 @Entity(name = "CRM_TaskDepartureAddress") public class TaskVisitAddress implements Serializable { ...any fields @Id @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "TASKID") public TaskVisit getTaskVisit() { return taskVisit; } @Id @OneToOne(fetch = FetchType.LAZY) @JoinColumn(name = "PERSONADDRESSID") public PersonAddress getPersonAddress() { return personAddress; } } 

InheritanceType.JOINED Abstract Task class.

The sequence of inserts in the table:

  1. CRM_TASK
  2. CRM_TaskDepartureAddress
  3. CRM_TASKDEPARTURE

2 and 3 according to the logic, you must first have an insert in CRM_TASKDEPARTURE , and then already CRM_TaskDepartureAddress , since CRM_TaskDepartureAddress has FK on CRM_TASKDEPARTURE , and not vice versa. What could be the error?

Ps JPA Implementation - eclipselink 2.6.1

  • Really such sequence of insert? When adding TaskVisitAddress to the collection, do you remember to install TaskVisitAddress.taskVisit or do you hope that jpa will do it for you? - Sergey
  • @banme 2 TaskVisitAddress.taskVisit is set, this is a bug, I hope that someone knows how to get around this without the help of a crutch. - George Vassilev
  • @banme 2 TaskVisitAddress.taskVisit is set, this is a bug (the collection considers the PK ID’s abstract class class (CRM_TASK), not CRM_TASKDEPARTURE), I hope someone knows how to get around this without the help of a crutch. - George Vassilev
  • You can alter the inheritance a bit. Make InheritanceType.SINGLE_TABLE, and CRM_TASKDEPARTURE in TaskVisit declare @SecondaryTable. Other heirs of Task are similar. If this option is suitable, maybe eclipselink can be fooled? - Sergey

0