Which statement is correct ?
-
a) session.contains() method to determine if an instance belongs to the session cache.
-
b) session.contains() method to determine if an instance belongs to the data base .
-
c) Both are correct
-
d) none of the above
session.contains() checks if an instance exists in the session cache (first-level cache), not whether it's in the database. An entity can be in session cache without being persisted, or exist in database without being in cache.
In Hibernate, session.contains(object) checks whether the given instance is currently associated with (tracked by) that session's first-level cache/persistence context — not whether a matching row exists in the underlying database. An object could exist in the database but not be loaded into the session, in which case contains() would return false even though the data is persisted.