I know that transient instance means the instance is newly created and its corresponding row does not exist in the database where as detached instance has corresponding entr
As others said, org.hibernate.Session.contains(Object) may be used in Hibernate to know if an entity instance is attached or detached. Regarding the transient state, the best that could be done I think is what org.hibernate.Session.saveOrUpdate(Object) (by virtue of org.hibernate.persister.entity.AbstractEntityPersister.isTransient(Object, SessionImplementor)) does, that is:
@Id property, it's always considered transient@Id property value which is null, it's always considered transient@Id property value which is equal to the configured unsaved-value, then it's considered transient (only applies to XML mapping, I think it's somewhat deprecated, see here)@Version property whose value is the one of a newly created instance (that is, it's a null Long, or Date, etc.), then it's considered transientHence, I think that, for entities without a generated id, looking at the @Version property is the way to go. If there's no such property, Hibernate itself in saveOrUpdate makes a SELECT query against the database to determine whether the entity instance is transient or not, to determine if it should do an INSERT or an UPDATE respectively.
See Hibernate manual (as an example, 4.3 one here).