【发布时间】:2014-06-10 06:44:37
【问题描述】:
我知道你会生我的气。但我还是会问。 我尝试了stackoverflow中的每个解决方案来解决问题。但没有解决。 我生成休眠 dao pojos 和 hbm.xml.and 当我尝试用 dao 添加一些东西时,我收到错误“无法在 JNDI 中找到 SessionFactory”。***
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;
}
}
和 MainClass.java(测试)
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);
}
和 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>
和 tomcat 版本:v7.0.50 我再说一遍 在你开始生气之前。我尝试了 stackoverflow 中的所有解决方案。但没有奏效。 ->enter link description here ->enter link description here ->enter link description here ->enter link description here
有同样的问题,那里的解决方案对我没有帮助或不理解那里的解决方案。 请帮帮我.. 我为我糟糕的英语道歉 谢谢***
【问题讨论】:
标签: hibernate jndi sessionfactory