tags:

views:

85

answers:

1

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
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
or I will use Hibernate EntityManager instead of Spring's HibernateTemplate, thus I can use @PrePersist and @PreUpdate to know the state.
Matt
Feel free to ask for anything else you want. I have many ORM related answers. regards.
Arthur Ronald F D Garcia