mardi 4 août 2015

Hibernate/JPA, determine if entity is new

Is there a way to determine given for example entity class:

@Entity
class A {

    String name;

}

boolean method(Object anyEntity) {
     // How can I check here, if this entity is completely new    
}

By new, I mean someone invoked new A() and possibly even set the name, but was never saved, or persisted.

Normally one could check the id, but I want a solution that doest not requires an id, or a getId() method.

Basically, has this entity been persisted to the database, even in detached mode.

@Version or getVersion is also not a satisfactory solution.

Maybe isDetached || isAttached might work, but I am not sure how to make that call on Hibernates API.

Aucun commentaire:

Enregistrer un commentaire