使用eclipse Hibernate插件时出现问题-无法在JNDI中找到sessionfactory

使用eclipse Hibernate插件时出现问题-无法在JNDI中找到sessionfactory,hibernate,eclipse-plugin,jndi,sessionfactory,Hibernate,Eclipse Plugin,Jndi,Sessionfactory,我正在使用EclipseHibernate插件中内置的反向工程功能为每个表生成dao和hbm.xml文件 它做得很好,但是当我尝试使用生成的对象时,我得到了一个在JNDI中找不到SessionFactory的错误 我看到一篇帖子,其中建议在hibernate.cfg.xml文件中命名SessionFactory时发生这种情况,因此我删除了名称标记,但仍然收到相同的错误 这是我的hibernate.cfg.xml <?xml version="1.0" encoding="utf-8

我正在使用EclipseHibernate插件中内置的反向工程功能为每个表生成dao和hbm.xml文件

它做得很好,但是当我尝试使用生成的对象时,我得到了一个在JNDI中找不到SessionFactory的错误

我看到一篇帖子,其中建议在hibernate.cfg.xml文件中命名SessionFactory时发生这种情况,因此我删除了名称标记,但仍然收到相同的错误

这是我的hibernate.cfg.xml

    <?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory>
        <property name="hibernate.bytecode.use_reflection_optimizer">false</property>
        <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="hibernate.connection.password">qwerty</property>
        <property name="hibernate.connection.url">jdbc:mysql://127.0.0.1:3306/agilegroup3</property>
        <property name="hibernate.connection.username">root</property>
        <property name="hibernate.default_catalog">agilegroup3</property>
        <property name="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</property>
        <mapping resource="generated/Usersroles.hbm.xml" />
        <mapping resource="generated/Role.hbm.xml" />
        <mapping resource="generated/Logdata.hbm.xml" />
        <mapping resource="generated/Logtrigger.hbm.xml" />
        <mapping resource="generated/User.hbm.xml" />
    </session-factory>
</hibernate-configuration>
我对JNDI了解不多,但我想它相当于一个配置文件。我不想使用JNDI,但我不知道如何使用eclipse插件实现这一点

更改生成的代码并不能真正帮助我,因为我需要在某些时候不断地重新生成代码,所以如果有人能解释为什么/如何发生这种情况,以及我能做些什么,我将不胜感激

谢谢


Jonathan

您可以直接在hibernate配置文件中指定所有连接、密码、用户名等,然后使用如下代码加载:

Configuration cfg = new Configuration();
cfg.configure();
SessionFactory sf = cfg.buildSessionFactory();
或者,您可以从JNDI获得它。这允许您的系统管理员在部署后通过向JNDI注册不同的SessionFactory来更改连接、密码、用户名等


您需要查阅应用程序服务器的文档,了解如何使用应用程序服务器指定JNDI资源。

buildsessionfactory方法内部初始化initialcontext。在get session factory方法中传递sessionfactory JNDI名称(即在查找中)

我也面临同样的问题。你解决这个问题了吗?如果是,请告诉我们解决方案。。。。
Configuration cfg = new Configuration();
cfg.configure();
SessionFactory sf = cfg.buildSessionFactory();