Cannot set any value LocalDateTime in Entity of Spring Boot Example

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;


....
}
@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.createdUser = getUsernameFromAuthentication();
this.createdAt = LocalDateTime.now();
}

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

...
}
@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.createdUser = getUsernameFromAuthentication();
this.createdAt = LocalDateTime.now();
}

@PreUpdate
public void preUpdate() {
this.updatedUser = getUsernameFromAuthentication();
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);
}
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?
3 Replies
JavaBot
JavaBot9mo ago
This post has been reserved for your question.
Hey @direct_x_34! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here. 💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.
Unknown User
Unknown User9mo ago
Message Not Public
Sign In & Join Server To View
JavaBot
JavaBot9mo ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.
Want results from more Discord servers?
Add your server