spring-projects / spring-projects/spring-data-relational

Update domain model with generated non-id fields

Open
#1,274 15 comments 5 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

type: enhancement
Dominant language
Java
Stars
827
Forks
394
PR merge metrics
No merged PRs in 30d

Description

Versions:

  • Spring boot 2.3.1.RELEASE
  • spring-data-r2dbc 1.1.1.RELEASE
  • r2dbc-postgresql 0.8.3.RELEASE

Current Behavior
check_create_at_ret table has a column created_at with a default value.

create table check_create_at_ret
(
    id         bigint generated by default as identity
        constraint check_create_at_ret_pkey primary key,
    created_at timestamp default now() not null,
    status     varchar(64)
);

But after saving the new entity, the value that is set at the database level is not returned.

Example:

@Data
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
public class CheckCreateAtRet {

    @Id
    private Long id;

    private String status;

    private LocalDateTime createdAt;
    
}
public interface CheckCreateAtRetRepo extends ReactiveCrudRepository<CheckCreateAtRet, Long> {
}
// ...
private final CheckCreateAtRetRepo checkCreateAtRetRepo;

public void save() {
        checkCreateAtRetRepo.save(new CheckCreateAtRet().setStatus("Status123"))
                .doOnNext(entity -> System.out.println(entity.getCreatedAt()))
                .subscribe();
}
// ...

Null will be printed

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the CheckCreateAtRetRepo.save call and the PostgreSQL check_create_at_ret table definition, focusing on how the database-generated created_at value is handled. Reproduce the example with CheckCreateAtRet and verify that the entity returned after save contains the generated createdAt value.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, postgresql, spring-boot
Domain
backend, database
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.