How to set a default value of an Id in JPA to 38? I know that I can set a single id length by using @Column(length=38), but how to change it globally?
If this is not possible with JPA, maybe it is with Spring Data or Hibernate?
How to set a default value of an Id in JPA to 38? I know that I can set a single id length by using @Column(length=38), but how to change it globally?
If this is not possible with JPA, maybe it is with Spring Data or Hibernate?
I think you should add a abstract parent class for your entities, here is my AbstractEntity:
@MappedSuperclass
public class AbstractEntity {
@Id
@GeneratedValue
@Column(length=38)
private Long id;
@Column(name = "created_at")
private Date createdTime;
@Column(name = "updated_at")
private Date updatedTime;
@PrePersist
public void init() {
if(createdTime == null) {
createdTime = new Date();
}
updatedTime = new Date();
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Date getCreatedTime() {
return createdTime;
}
public void setCreatedTime(Date createdTime) {
this.createdTime = createdTime;
}
public Date getUpdatedTime() {
return updatedTime;
}
public void setUpdatedTime(Date updatedTime) {
this.updatedTime = updatedTime;
}
}