Skip to content

@OwnerField

The @OwnerField annotation marks a field as the record owner identifier. When present, only the owner of the record (and administrators) can manage it.

Basic Usage

java
@Entity
@SquizyEntity
public class Task {

    @OwnerField
    private String createdBy;

    @NotNull
    private String title;

    private String description;
}

When a record is created, the @OwnerField is automatically populated with the current user's email. Only that user (or an admin) can subsequently update or delete the record.

Attributes

visibleByOthers

Controls whether non-owners can see (read) the record. Defaults to false:

java
// Other users can see the record but cannot modify it
@OwnerField(visibleByOthers = true)
private String createdBy;

When false, the record is completely hidden from non-owner, non-admin users.

setOnUpdate

Controls whether the owner field is updated on each modification. Defaults to false (set only on creation):

java
// Tracks the last modifier instead of the original creator
@OwnerField(setOnUpdate = true)
private String lastModifiedBy;

Behavior

ScenarioDefault (visibleByOthers = false)visibleByOthers = true
Owner reads✅ Allowed✅ Allowed
Owner updates/deletes✅ Allowed✅ Allowed
Admin reads✅ Allowed✅ Allowed
Admin updates/deletes✅ Allowed✅ Allowed
Other user reads❌ Hidden✅ Read-only
Other user updates/deletes❌ Denied❌ Denied