2

Using Spring webflux with H2-R2DBC and creating a course by adding the details in course table defined as below.

CREATE TABLE IF NOT EXISTS course(
id VARCHAR(40) PRIMARY KEY,
name VARCHAR(40) NOT NULL,
fee DECIMAL,
updatedtime TIMESTAMP DEFAULT CURRENT_TIMESTMP);

Using ReactiveCrudRepository save method to save the data like below

Course course=new Course();
course.setName("Physics");
course.setId("PHY123");
course.fee(100);

repository.save(course);

as per logs in webflux on save the object is having null for updatedtime.

Question :-

  1. How to avoid setting null and set default value as current timestamp on each insert/update.
  2. How to use @Column(name="updatedtime",insertable=false) in Spring Webflux.
pri
  • 49
  • 2
  • 5
  • Try creating the table with `updatedTime TIMESTAMP AS CURRENT_TIMESTAMP` im not sure it will work, something i remember i read once. – Toerktumlare Mar 21 '21 at 23:08
  • No, it's still set to null using AS CURRENT_TIMESTAMP as well. – pri Mar 23 '21 at 00:44
  • Alternatively , use the Spring data audit to fill the creation and update timestamp field, check [my example](https://github.com/hantsy/spring-r2dbc-sample/blob/master/data-r2dbc-entitytemplate/src/main/java/com/example/demo/Post.java#L51). – Hantsy Jun 04 '21 at 06:32

0 Answers0