Skip to content

Consider allowing attributes annotated with CreatedDate to determine "isNew" status for R2DBC Repositories #1587

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
efenderbosch-atg opened this issue Aug 16, 2023 · 1 comment
Assignees
Labels
status: declined A suggestion or change that we don't feel we should currently apply

Comments

@efenderbosch-atg
Copy link

Affects: r2dbc 6, data-commons 3.1

Currently r2dbc "is new state detection" supports:

  • null/0 @Id properties
  • null/0 @Version properties
  • implementing Persistable::isNew

Another possibility is null @CreatedDate properties. I personally don't like nullable id properties and a version property doesn't make sense for my current project since there's only 1 user mutating an entity at a time, but the service does mutate entities, which was causing OptimisticLockingFailureException to be thrown when an old version comes through the API.

My solution was to implement Persistable, but it might be nice to support null @CreatedDate properties natively as an alternative"is new state detection".

My entities look like this:

@Immutable
interface AuditedPersistable<T> : Persistable<T> {
    @get:CreatedDate
    val createdAt: Instant?

    @get:LastModifiedDate
    val updatedAt: Instant?

    @JsonIgnore
    override fun isNew() = createdAt == null
}

@Table
data class Foo(
    private val id: UUIDv7,
    val bar: String,
    override val createdAt: Instant?,
    override val updatedAt: Instant?,
) : AuditedPersistable<UUIDv7> {
    @Id
    override fun getId() = id
}

I did try the custom EntityInformation route, but that proved to be too difficult when compared to the above solution.

Or maybe just add documentation with something like this as an example.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Aug 16, 2023
@mp911de mp911de added the for: team-attention An issue we need to discuss as a team to make progress label Aug 16, 2023
@mp911de mp911de self-assigned this Aug 28, 2023
@mp911de mp911de added status: declined A suggestion or change that we don't feel we should currently apply and removed status: waiting-for-triage An issue we've not yet triaged labels Aug 28, 2023
@mp911de mp911de closed this as not planned Won't fix, can't repro, duplicate, stale Aug 29, 2024
@mp911de
Copy link
Member

mp911de commented Aug 29, 2024

We do not intend to introduce yet another mechanism. First, we have a series of variants that cover a wide range of arrangements. Secondly, if these approaches do not suit your requirements, you can subclass your repository factory and introduce your own EntityInformation by implementing isNew(…) according to your needs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: declined A suggestion or change that we don't feel we should currently apply
Projects
None yet
Development

No branches or pull requests

3 participants