Hi Friends,
I'm new to this forum so kindly bear with me...
I've a confusion regarding use of Hibernate with Myeclipse... I'm seeing that while executing my web-application hibernate opens a session with the help of getSession() but in no place (so far) I've seen how Hibernate closes this sesion... My question is how/or at which place session gets closed [I'm using default configuration of Hibernate with Myeclipse].
Below is the code snipset of MyEclipse generated DAO.
Thanks in advance
package bean;
import java.sql.Timestamp;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.criterion.Example;
/**
* A data access object (DAO) providing persistence and search support for
* Selllog entities. Transaction control of the save(), update() and delete()
* operations can directly support Spring container-managed transactions or they
* can be augmented to handle user-managed Spring transactions. Each of these
* methods provides additional information for how to configure it for the
* desired type of transaction control.
*
* @see bean.Selllog
* @author MyEclipse Persistence Tools
*/
public class SelllogDAO extends BaseHibernateDAO {
private static final Log log = LogFactory.getLog(SelllogDAO.class);
// property constants
public static final String OPENING_BALENCE = "openingBalence";
public static final String RECEIVE = "receive";
public static final String TRANSFER = "transfer";
public static final String TRANSFER_TO_COMMENT = "transferToComment";
public static final String DAY_BRAND_RATE = "dayBrandRate";
public static final String CLOSING_BALANCE = "closingBalance";
public static final String LAST_UPDATE_USE_ID = "lastUpdateUseId";
public void save(Selllog transientInstance) {
log.debug("saving Selllog instance");
try {
getSession().save(transientInstance);
log.debug("save successful");
} catch (RuntimeException re) {
log.error("save failed", re);
throw re;
}
}
public void delete(Selllog persistentInstance) {
log.debug("deleting Selllog instance");
try {
getSession().delete(persistentInstance);
log.debug("delete successful");
} catch (RuntimeException re) {
log.error("delete failed", re);
throw re;
}
}
public Selllog findById(java.lang.Integer id) {
log.debug("getting Selllog instance with id: " + id);
try {
Selllog instance = (Selllog) getSession().get("bean.Selllog", id);
return instance;
} catch (RuntimeException re) {
log.error("get failed", re);
throw re;
}
}
public List findByExample(Selllog instance) {
log.debug("finding Selllog instance by example");
try {
List results = getSession().createCriteria("bean.Selllog").add(
Example.create(instance)).list();
log.debug("find by example successful, result size: "
+ results.size());
return results;
} catch (RuntimeException re) {
log.error("find by example failed", re);
throw re;
}
}
public List findByProperty(String propertyName, Object value) {
log.debug("finding Selllog instance with property: " + propertyName
+ ", value: " + value);
try {
String queryString = "from Selllog as model where model."
+ propertyName + "= ?";
Query queryObject = getSession().createQuery(queryString);
queryObject.setParameter(0, value);
return queryObject.list();
} catch (RuntimeException re) {
log.error("find by property name failed", re);
throw re;
}
}
public List findByOpeningBalence(Object openingBalence) {
return findByProperty(OPENING_BALENCE, openingBalence);
}
public List findByReceive(Object receive) {
return findByProperty(RECEIVE, receive);
}
public List findByTransfer(Object transfer) {
return findByProperty(TRANSFER, transfer);
}
public List findByTransferToComment(Object transferToComment) {
return findByProperty(TRANSFER_TO_COMMENT, transferToComment);
}
public List findByDayBrandRate(Object dayBrandRate) {
return findByProperty(DAY_BRAND_RATE, dayBrandRate);
}
public List findByClosingBalance(Object closingBalance) {
return findByProperty(CLOSING_BALANCE, closingBalance);
}
public List findByLastUpdateUseId(Object lastUpdateUseId) {
return findByProperty(LAST_UPDATE_USE_ID, lastUpdateUseId);
}
public List findAll() {
log.debug("finding all Selllog instances");
try {
String queryString = "from Selllog";
Query queryObject = getSession().createQuery(queryString);
return queryObject.list();
} catch (RuntimeException re) {
log.error("find all failed", re);
throw re;
}
}
public Selllog merge(Selllog detachedInstance) {
log.debug("merging Selllog instance");
try {
Selllog result = (Selllog) getSession().merge(detachedInstance);
log.debug("merge successful");
return result;
} catch (RuntimeException re) {
log.error("merge failed", re);
throw re;
}
}
public void attachDirty(Selllog instance) {
log.debug("attaching dirty Selllog instance");
try {
getSession().saveOrUpdate(instance);
log.debug("attach successful");
} catch (RuntimeException re) {
log.error("attach failed", re);
throw re;
}
}
public void attachClean(Selllog instance) {
log.debug("attaching clean Selllog instance");
try {
getSession().lock(instance, LockMode.NONE);
log.debug("attach successful");
} catch (RuntimeException re) {
log.error("attach failed", re);
throw re;
}
}
} |