spring-projects / spring-projects/spring-data-relational
Update domain model with generated non-id fields
Open
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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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