Getting the state of an object

Does hibernate provide a method that returns the state of an object (temporary, permanent, separate)?

+5
source share
3 answers

see Hibernate Javadoc session and check methods

  • contains - Check if this instance is associated with this session.
  • getIdentifier - returns the value of the identifier of this object associated with this session. Beware of the exception that is thrown if the object is not connected, each exception should be considered fatal, and the session should not be used after it.
  • get - returns a constant instance of this entity class with the given identifier or null if there is no such constant instance.

"get" , , , "saveOrUpdate" ( )

+3

Session.contains , . , , , . , , .

, , , , ?

+3

I disagree with using session.contains(obj)to show the state of a hibernate object. An object that was previously saved / loaded would be accepted as TRANSIENT after a simple call session.clear()- if you do not have a primary key, but a compound key, of which you do not know what state it is in ...

The correct approach can be found inside Hibernate 3: org.hibernate.engine.ForeignKeys.isTransient (...)

0
source

All Articles