|
From: ashwini on 29 Nov 2006 15:17 Hi All This is Ashwini... i am working on a project ..in which i have created tables in database ,,& used hibernate reverse engineering to generate related POJO Classes & DAO classes in eclipse .. I could generate pojo clases & DAO classes as per tables ..but in DAO classes i am getting following error ...getCurrentSession() is undefined for the type session factory.. does any one knows why this error should occur ,since this method is of class SessionFactory ..all other methods ..like openSession(),close(),getCollectionMetadate()..are working fine..but it is saying that getCurrent Session() ..is undefined ..does anyone know why is so?? early feedback would be of great help .. Thanks Ashwini for more information ..there is one table in Db called Alert .. i could generate Alert.java pojo class & AlertDAO.java class as bellow , Alert.java /** * Alert generated by MyEclipse - Hibernate Tools */ public class Alert implements java.io.Serializable { // Fields private long alertKey; private Keyword keyword; private String location; private String radius; private String howOften; private String email; // Constructors /** default constructor */ public Alert() { } /** minimal constructor */ public Alert(long alertKey, Keyword keyword, String email) { this.alertKey = alertKey; this.keyword = keyword; this.email = email; } /** full constructor */ public Alert(long alertKey, Keyword keyword, String location, String radius, String howOften, String emai public long getAlertKey() { return this.alertKey; } public void setAlertKey(long alertKey) { this.alertKey = alertKey; } public Keyword getKeyword() { return this.keyword; } other getter setter methods goes here... AlertDAO.java package com.Cmpe275Project.hibernate; import java.util.List; import javax.naming.InitialContext; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.hibernate.LockMode; import org.hibernate.SessionFactory; import org.hibernate.criterion.Example; /** * Data access object (DAO) for domain model class Alert. * @see com.Cmpe275Project.hibernate.Alert * @author MyEclipse - Hibernate Tools */ public class AlertDAO { private static final Log log = LogFactory.getLog(AlertDAO.class); private final SessionFactory sessionFactory = getSessionFactory(); protected SessionFactory getSessionFactory() { try { return (SessionFactory) new InitialContext().lookup("src/com.Cmpe275Project.hibernate"); } catch (Exception e) { log.error("Could not locate SessionFactory in JNDI", e); throw new IllegalStateException("Could not locate SessionFactory in JNDI"); } } public void save(Alert transientInstance) { log.debug("saving Alert instance"); try { sessionFactory.getCurrentSession().saveOrUpdate(transientInstance); log.debug("save successful"); } catch (RuntimeException re) { log.error("save failed", re); throw re; } } Show Recent Messages (F3) ajit_bhingare appears to be offline and will receive your messages after signing in. You currently appear offline to ajit_bhingare. ajit_bhingare: public void delete(Alert persistentInstance) { log.debug("deleting Alert instance"); try { sessionFactory.getCurrentSession().delete(persistentInstance); log.debug("delete successful"); } catch (RuntimeException re) { log.error("delete failed", re); throw re; } } public Alert findById( Long id) { log.debug("getting Alert instance with id: " + id); try { Alert instance = (Alert) sessionFactory.getCurrentSession() .get("com.Cmpe275Project.hibernate.Alert", id); return instance; } catch (RuntimeException re) { log.error("get failed", re); throw re; } } Show Recent Messages (F3) ajit_bhingare appears to be offline and will receive your messages after signing in. You currently appear offline to ajit_bhingare. ajit_bhingare: public List findByExample(Alert instance) { log.debug("finding Alert instance by example"); try { List results = sessionFactory.getCurrentSession() ..createCriteria("com.Cmpe275Project.hibernate.Alert") .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 Alert merge(Alert detachedInstance) { log.debug("merging Alert instance"); try { Alert result = (Alert) sessionFactory.getCurrentSession() .merge(detachedInstance); log.debug("merge successful"); return result; } catch (RuntimeException re) { log.error("merge failed", re); throw re; } } public void attachDirty(Alert instance) { log.debug("attaching dirty Alert instance"); try { sessionFactory.getCurrentSession().saveOrUpdate(instance); log.debug("attach successful"); } catch (RuntimeException re) { log.error("attach failed", re); throw re; } } public void attachClean(Alert instance) { log.debug("attaching clean Alert instance"); try { sessionFactory.getCurrentSession().lock(instance, LockMode.NONE); log.debug("attach successful"); } catch (RuntimeException re) { log.error("attach failed", re); throw re; } }
From: Matt McGill on 30 Nov 2006 07:41 ashwini wrote: > Hi All > This is Ashwini... > > i am working on a project ..in which i have created tables in database > ,,& used hibernate reverse engineering to generate related POJO > Classes & DAO classes in eclipse .. > > > I could generate pojo clases & DAO classes as per tables ..but in DAO > classes i am getting following error > > > ..getCurrentSession() is undefined for the type session factory.. > It sounds like you've got the wrong version of Hibernate on the classpath (getCurrentSession is a relatively recent addition to the API). That being said, this is absolutely the wrong place to ask your question. You'll do much better at http://forum.hibernate.org/. -Matt McGill
|
Pages: 1 Prev: Definition of Abstract Data Type Next: confusion about data abstraction |