Cannot set any value LocalDateTime in Entity of Spring Boot Example

52 views Asked by At

I have a problem to set LocalDateTime.now to the entity of Spring Boot Example

Here is the entity shown below

@Getter
@Setter
@EqualsAndHashCode(callSuper = true)
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
@Entity
@Table(name = "PARK")
public class ParkEntity extends BaseEntity {

   ...

   @Column(name = "CHECK_IN")
   private LocalDateTime checkIn;


   ....
}

Here is the BaseEntity shown below

@Getter
@Setter
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
@MappedSuperclass
public abstract class BaseEntity {

    @Column(name = "CREATED_USER")
    protected String createdUser;

    @Column(name = "CREATED_AT")
    protected LocalDateTime createdAt;

    @Column(name = "UPDATED_USER")
    protected String updatedUser;

    @Column(name = "UPDATED_AT")
    protected LocalDateTime updatedAt;

    @PrePersist
    public void prePersist() {
        this.createdAt = LocalDateTime.now();
    }

    @PreUpdate
    public void preUpdate() {
        this.updatedAt = LocalDateTime.now();
    }

...
}

Here is the method shown below

private Park parkMethod(....) {
        ParkEntity parkEntity = ....
        parkEntity.setCheckIn(LocalDateTime.now());
        ParkEntity savedPark = parkRepository.save(parkEntity);
        return parkEntityToParkMapper.map(savedPark);
}

I have also other entities extending from BaseEntity.

I get null value in checkIn of savedPark . I have to manually set the LocalDateTime.now() instead of using @Builder.Default

How can I do that?

0

There are 0 answers