I am working in users creation so, right now I need to order the list of active users sort by date, is to say the last updated user. I have a class that define my entity "Users" in my database, I am trying to store the full date (Year,Month,Day Hours, Minutes, Seconds, Nanosecons), but when I save the user in the table only is stored Year,Month,Day and the other attributes are "0". I am using Datetime as a data type in the table column, and Date in Java to map this entity. If someone can help me to find my error, or other solution to do it I will appreciated it. thanks a lot
This is my code:
@Entity
@Table(name = "users")....
public class User {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long user_id;
@Column(nullable = false)
private boolean is_active;
@Column(nullable = false)
private String created_by;
@Column
@Temporal(TemporalType.DATE)
private Date createdAt;
@Column(nullable = true)
private String updated_by;
@Column
@Temporal(TemporalType.DATE)
private Date updatedAt;
Implementation
Date date2 = java.util.Calendar.getInstance().getTime();
newUser.setCreatedAt(date2);
newUser.setUpdatedAt(date2);
newUser = this.userRepository.save(newUser);