Ebean Embedded Composite主外键映射在级联类型全部上保存错误

时间:2018-09-04 20:31:51

标签: java playframework ebean

我有一个需要层叠oneToMany关系的实体:

@Entity
@Table(name = "internationalizations")
public class Internationalization extends Model {

    @OneToMany(
        mappedBy = "internationalization",
        cascade = CascadeType.ALL
    )
    private List<CallApplyingProgram> applyingPrograms = new ArrayList<>();

                          ---- Getter & Setter----
}

这里是关系:

@Entity
@Table(name = "applying_programs")
public class CallApplyingProgram extends Model {

    @EmbeddedId
    private CallApplyingProgramId id;

    @ManyToOne
    @MapsId("internationalizationId")
    private Internationalization internationalization;

    @MapsId("programId")
    private Program program;

                           --- Getters & Setters ---
}

最后是EmbeddedId:

@Embeddable
public class CallApplyingProgramId implements Serializable {

    private String programId;

    private Long internationalizationId;

                           --- Getters & Setters ---
}

这样映射到数据库: Database Mapping (internationalization_id代替internationalizationid)

但是当我想像这样使用Ebean保存模型时:

Internationalization internationalization = new Internationalization();

    Program program = new Program("LD");

    CallApplyingProgram applyingProgram = new CallApplyingProgram();
    applyingProgram.setInternationalization(internationalization);
    applyingProgram.setProgram(program);

    List<CallApplyingProgram> programs = new ArrayList<>();
    programs.add(applyingProgram);

    internationalization.setApplyingPrograms(programs);
    internationalization.save();

它给了我这个错误:

    Test integration.models.persistence.InternationalizationIntegrationTest.testAddingCallApplyingPrograms failed: javax.persistence.PersistenceException: Matches for the concatenated key columns where not found? I expect that the concatenated key was null, and this bean does not have ManyToOne assoc beans matching the primary key columns?, took 0.105 sec
[error]     at io.ebeaninternal.server.persist.dmlbind.BindableIdEmbedded.deriveConcatenatedId(BindableIdEmbedded.java:94)
[error]     at io.ebeaninternal.server.persist.dml.InsertMeta.deriveConcatenatedId(InsertMeta.java:142)
[error]     at io.ebeaninternal.server.persist.dml.InsertHandler.bind(InsertHandler.java:74)
[error]     at io.ebeaninternal.server.persist.dml.DmlBeanPersister.execute(DmlBeanPersister.java:67)
[error]     at io.ebeaninternal.server.persist.dml.DmlBeanPersister.insert(DmlBeanPersister.java:49)
[error]     at io.ebeaninternal.server.core.PersistRequestBean.executeInsert(PersistRequestBean.java:1136)
[error]     at io.ebeaninternal.server.core.PersistRequestBean.executeNow(PersistRequestBean.java:723)
[error]     at io.ebeaninternal.server.persist.BatchControl.executeNow(BatchControl.java:217)
[error]     at io.ebeaninternal.server.persist.BatchedBeanHolder.executeNow(BatchedBeanHolder.java:88)
[error]     at io.ebeaninternal.server.persist.BatchControl.flush(BatchControl.java:270)
[error]     at io.ebeaninternal.server.persist.BatchControl.flush(BatchControl.java:226)
[error]     at io.ebeaninternal.server.transaction.JdbcTransaction.batchFlush(JdbcTransaction.java:661)
[error]     at io.ebeaninternal.server.transaction.JdbcTransaction.internalBatchFlush(JdbcTransaction.java:779)
[error]     at io.ebeaninternal.server.transaction.JdbcTransaction.flushCommitAndNotify(JdbcTransaction.java:979)
[error]     at io.ebeaninternal.server.transaction.JdbcTransaction.commit(JdbcTransaction.java:1031)
[error]     at io.ebeaninternal.server.transaction.TransactionMap$State.commit(TransactionMap.java:82)
[error]     at io.ebeaninternal.server.transaction.DefaultTransactionThreadLocal.commit(DefaultTransactionThreadLocal.java:74)
[error]     at io.ebeaninternal.server.transaction.DefaultTransactionScopeManager.commit(DefaultTransactionScopeManager.java:17)
[error]     at io.ebeaninternal.server.core.DefaultServer.commitTransaction(DefaultServer.java:886)
[error]     at io.ebeaninternal.server.core.BeanRequest.commitTransIfRequired(BeanRequest.java:61)
[error]     at io.ebeaninternal.server.persist.DefaultPersister.insert(DefaultPersister.java:407)
[error]     at io.ebeaninternal.server.persist.DefaultPersister.save(DefaultPersister.java:393)
[error]     at io.ebeaninternal.server.core.DefaultServer.save(DefaultServer.java:1602)
[error]     at io.ebeaninternal.server.core.DefaultServer.save(DefaultServer.java:1594)
[error]     at io.ebean.Model.save(Model.java:190)
[error]     at integration.models.persistence.InternationalizationIntegrationTest.testAddingCallApplyingPrograms(InternationalizationIntegrationTest.java:84)
[error]     ...

您知道什么可能导致错误吗?

0 个答案:

没有答案