I know you'll be mad at me.but I'll ask anyway. i tried to every solution in stackoverflow for problem.but unresolved. i generate to hibernate dao pojos and hbm.xml.and when i try to add something with dao,i am getting error "Could not locate SessionFactory in JNDI".***
KullanicilarHome.java
public class KullanicilarHome {
private static final Log log = LogFactory.getLog(KullanicilarHome.class);
private final SessionFactory sessionFactory = getSessionFactory();
protected SessionFactory getSessionFactory() {
try {
return (SessionFactory) new InitialContext()
.lookup("SessionFactory");
} catch (Exception e) {
log.error("Could not locate SessionFactory in JNDI", e);
throw new IllegalStateException(
"Could not locate SessionFactory in JNDI");
}
}
public void persist(Kullanicilar transientInstance) {
log.debug("persisting Kullanicilar instance");
try {
sessionFactory.getCurrentSession().persist(transientInstance);
log.debug("persist successful");
} catch (RuntimeException re) {
log.error("persist failed", re);
throw re;
}
}
and MainClass.java (test)
public class MainClass {
public static void main(String[] args) {
// TODO Auto-generated method stub
Kullanicilar user = new Kullanicilar();
user.setAd("Ergin");
user.setSoyad("DURAN");
user.setUniversite("Kxxx");
user.setBolum("bxx");
user.setCepTel("5xxxxxx");
user.setEmail("exxxx");
user.setVeliTel("55xxxxx");
KullanicilarHome x = new KullanicilarHome();
x.persist(user);
}
and hbm.cfg.xml
<hibernate-configuration>
<session-factory name="SessionFactory">
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.password">root</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/db</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.session_factory_name">SessionFactory</property>
</session-factory>
</hibernate-configuration>
and tomcat version: v7.0.50 i say again Before you start to get angry. i tried to all solutions in stackoverflow.but did not work. ->enter link description here ->enter link description here ->enter link description here ->enter link description here
have a same problem and there solutions did not help me or did not understand there solutions. help me please.. I apologize for my bad english thanks***