Skip to content

DuplicateKeyException when inserting a bean that references an unmodifiable (read-only) cached entity via a relationship #3813

Description

@dragkes

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Fields

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions