r/JavaProgramming 1d ago

Need help in Code

Post image

Paypal clone using java spring boot and kafka need help

Actually I was following @Mrunmai Dahare mam lecture in the vedio episode 3 : 16.21 timestamp I don't get what to change please help

3 Upvotes

3 comments sorted by

7

u/SimpleAide5607 1d ago

It would be useful if you described the problem you are facing instead of putting a screenshot of the code that tells me nothing

2

u/Brilliant_Yoghurt265 1d ago

no clue broski im a beginner

3

u/jjduru 1d ago

Presumably you would like to timestamp the entity with the LocalDateTime.now() before inserting it into the database.
First of all, your "createTransaction" method should ingest a DTO request. The ObjectMapper component will take care of the mapping between the incoming DTO and a new Transaction entity.

In order to automate the create and update of the LocalDateTime on the entity, make all the entities, including Transaction, to inherit a BaseEntity that handles automatically the update on the "date_updated" column.
After the mapping, you save and flush on the repository, which gives you back the newly created managed entity, and you return the a DTO out of it, not the entity itself.

@MappedSuperclass
@Getter
public abstract class BaseEntity implements Serializable {

  @Serial 
  private static final long serialVersionUID = 202504040001L;

  @CreationTimestamp(source = SourceType.VM)
  @Column(name = "date_created", nullable = false, updatable = false)
  @ColumnDefault("CURRENT_TIMESTAMP")
  private LocalDateTime dateCreated;

  @CreationTimestamp(source = SourceType.VM)
  @Column(name = "date_updated", nullable = false)
  @ColumnDefault("CURRENT_TIMESTAMP")
  private LocalDateTime dateUpdated;
}