Because of some limitation, client asked that I can't use incremental "id" primary key, only compound primary key is allowed. And I can't use JPA annotation to have entity callback. Thus how can I know an entity is going to be inserted or updated ? thanks a lot.
+1
A:
Hi,
Use a version column
@Version
public Integer getVersion() {
return this.version;
}
Whether it is null so it is an insert else it is an update.
regards,
Arthur Ronald F D Garcia
2009-10-15 04:48:06
Thanks a lot. I haven't used Hibernate for years. Since 2.1.7, it has changed a lot, I almost forgot all the basic things.
Matt
2009-10-16 13:07:02
or I will use Hibernate EntityManager instead of Spring's HibernateTemplate, thus I can use @PrePersist and @PreUpdate to know the state.
Matt
2009-10-16 13:13:24
Feel free to ask for anything else you want. I have many ORM related answers. regards.
Arthur Ronald F D Garcia
2009-10-16 13:24:59