When a new bean is saved and cascades through a @ManyToOne/@OneToOne association to an unmodifiable (read-only) bean loaded via setUnmodifiable(true), ebean incorrectly attempts to insert the read-only bean instead of treating it as an existing row.
Root cause: InterceptReadOnly.isUpdate() returned false, causing ebean to classify the unmodifiable bean as a new insert rather than an existing record, resulting in a DuplicateKeyException on the FK target.
Fix: override isUpdate() in InterceptReadOnly to return true so unmodifiable beans are always treated as existing entities during cascade persist.
When a new bean is saved and cascades through a
@ManyToOne/@OneToOneassociation to an unmodifiable (read-only) bean loaded viasetUnmodifiable(true), ebean incorrectly attempts to insert the read-only bean instead of treating it as an existing row.Root cause:
InterceptReadOnly.isUpdate()returnedfalse, causing ebean to classify the unmodifiable bean as a new insert rather than an existing record, resulting in aDuplicateKeyExceptionon the FK target.Fix: override
isUpdate()inInterceptReadOnlyto returntrueso unmodifiable beans are always treated as existing entities during cascade persist.