I used "Hibernate Code Generator Dialog" to generate DAO classes with this configuration:
Code:
<?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 name="test">
<property name="hibernate.connection.driver_class">org.gjt.mm.mysql.Driver</property>
<property name="hibernate.connection.password">joe</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost/mydb</property>
<property name="hibernate.connection.username">joe</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property>
</session-factory>
</hibernate-configuration>
the JNDI name should be "test", not the default "SessionFactory"
Here the generated code:
Code:
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");
}
}
"SessionFactory" is used instead of "test" for the lookup. This is a bug isn't it ? the generated code should be:
Code:
.lookup("test");
How can it be working if I don't rename the JNDI name ? If more than
one hibernate application is running in my Application Server, there
will be a conflict on "SessionFactiory" entry in JNDI ! no ?
config:
Eclipse 3.3.0
hibernate-3.2.5.ga
HibernateTools-3.2.0.GA
JDK 1.5.0.12
Windows XP