S
stunaz
Hello,
I want to tinitialize my objetc using the @PrePersist annotations.
Lets say i have an Entiy user:
@Entity
@Table(name = "USERS")
Public Class User {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name = "ID", unique = true, nullable = false)
private Integer id;
@Column(name="DATE_UPDATED",nullable = false)
@Temporal(TemporalType.DATE)
@NotNull
private Date dateCreated;
@PrePersist
public void beforeCreate(){
if (this.dateCreated == null) {
this.dateCreated = new Date();
}
}
//getter and setter
}
Somehow, the method beforeCreate is never called when i do :
session.saveOrUpdate(user)
but only when i do session.persist(user)
Can somebody tell me why and how to fix that?
Thanks
I want to tinitialize my objetc using the @PrePersist annotations.
Lets say i have an Entiy user:
@Entity
@Table(name = "USERS")
Public Class User {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name = "ID", unique = true, nullable = false)
private Integer id;
@Column(name="DATE_UPDATED",nullable = false)
@Temporal(TemporalType.DATE)
@NotNull
private Date dateCreated;
@PrePersist
public void beforeCreate(){
if (this.dateCreated == null) {
this.dateCreated = new Date();
}
}
//getter and setter
}
Somehow, the method beforeCreate is never called when i do :
session.saveOrUpdate(user)
but only when i do session.persist(user)
Can somebody tell me why and how to fix that?
Thanks