nathanmoon, as I noted above, the Session javadoc says fo the .get() method:
"If the instance, or a proxy for the instance, is already associated with the session, return that instance or proxy."
And as I see from my unit tests, the proxy was created also for the non-existent id. For example, session.get(MyClass, -1) retrive the proxy, with id=-1. My code below:
Code:
public void updateCatalogInfo(final Catalog catalog)
throws NoSuchCatalogException, CatalogException {
final Integer catalogId = catalog.getCatalogId();
try {
HibernateTemplate template = getHibernateTemplate();
Catalog persistantedCatalog
= (Catalog) template.get(Catalog.class, catalogId);
if (null == persistantedCatalog) {
//this is unsearchable in the my tests, even for the id=-1
throw new NoSuchCatalogException("There is no catalog "
+ "with id = '" + catalogId + "'.");
}
template.update(catalog);
}
catch (DataAccessException he) {
logger.error(he);
throw new CatalogException("Can't update the catalog with id = '"
+ catalogId + "'.", he);
}
}