Hibernate 在JNDI中找不到SessionFactory

Hibernate 在JNDI中找不到SessionFactory,hibernate,jndi,sessionfactory,Hibernate,Jndi,Sessionfactory,我知道你会生我的气,但我还是会问的。 我试图找出stackoverflow中的每一个解决方案来解决这个问题,但没有解决。 我生成了hibernate dao POJO和hbm.xml。当我试图用dao添加一些东西时,我得到了一个错误:无法在JNDI中找到SessionFactory*** kullanicialhome.java 和MainClass.java测试 和hbm.cfg.xml 和tomcat版本:v7.0.50 在你开始生气之前,我再说一遍。我试图在stackoverflow中找到

我知道你会生我的气,但我还是会问的。 我试图找出stackoverflow中的每一个解决方案来解决这个问题,但没有解决。 我生成了hibernate dao POJO和hbm.xml。当我试图用dao添加一些东西时,我得到了一个错误:无法在JNDI中找到SessionFactory***

kullanicialhome.java

和MainClass.java测试

和hbm.cfg.xml

和tomcat版本:v7.0.50 在你开始生气之前,我再说一遍。我试图在stackoverflow中找到所有解决方案,但没有成功。 -> -> -> ->

有一个相同的问题,并且没有解决方案对我没有帮助,或者不理解这些解决方案。 请帮帮我。。 我为我的英语不好道歉
谢谢***

我想您可能混淆了ejb和hibernate,我看不出您试图在JNDI中设置sessionfactory的位置。你必须做到以下几点

public class KullanicilarHome {

private static final Log log = LogFactory.getLog(KullanicilarHome.class);
private final SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
.
.
.
.
注意:确保类路径中有.property文件。通常我把它放在WEB-INF文件夹中


参考:

谢谢您的回答。我按照他们说的做。property和hbm.cfg.xml文件在同一个目录下。src>main>java/mainclass&hibernate.properties&hibernate.cfg.xml,我得到一个错误,比如:如果我把fileproperties和hbm.cfg.xml放到web inf中,我会得到hibernate.cfg.xml找不到的错误。非常感谢。我最终可以做到。但是另外,我必须为每个blablablablabla.hbm.xml添加hibernate.cfg.xml,这非常累人。再次感谢
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);

    }
<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>
public class KullanicilarHome {

private static final Log log = LogFactory.getLog(KullanicilarHome.class);
private final SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
.
.
.
.