晚上好,我在使用Hibernate和JSF時遇到了上述異常,我在過去多次看到它,根本原因是這樣<session-factory name="sessionFactory">
因此我刪除了命名和更改生成的代碼與創建了一個SessionFactory:java.lang.IllegalStateException:無法在JNDI中找到SessionFactory
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");
}
}
到:
protected SessionFactory getSessionFactory() {
try {
return new Configuration().configure("hibernate.cfg.xml").buildSessionFactory();
} catch (Exception e) {
log.error("Could not locate SessionFactory in JNDI", e);
throw new IllegalStateException(
"Could not locate SessionFactory in JNDI");
}
}
它是工作的罰款和我在一起,但這個時候,我沒有解決的辦法,你知道問題在哪裏?
的hibernate-cfg.xml
<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">root</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/GUNO</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.search.autoregister_listeners">false</property>
</session-factory>