I am starting to use hibernate for the first time in my project. But I do not know how to ‘find’ the SessionFactory with JNDI
pre-hibernate:
I am currently using Tomcat, and use JNDI to find a DataSource,
<Resource name=”jdbc/HotelDB” auth=”Container” type=”javax.sql.DataSource”
maxActive=”100″ maxIdle=”30″ maxWait=”10000″
username=”bob” password=”xxxx” driverClassName=”com.mysql.jdbc.Driver”
url=”jdbc:mysql://zoomer.xxxx.com/hotel?autoReconnect=true&requireSSL=false”/>
post-hibernate:
The myeclipse wizard generated this code for the DAO object
protected SessionFactory getSessionFactory() {
try {
return (SessionFactory) new InitialContext().lookup(“jdbc/HotelDB”);
} catch (Exception e) {
log.error(“Could not locate SessionFactory in JNDI”, e);
throw new IllegalStateException(“Could not locate SessionFactory in JNDI”);
}
}
The key “jdbc/HotelDB” is obviously wrong since this is a DataSource, Not a SessionFactory – but how do I create/define the session factory ?
Is there documentation or a sample project showing Dao use within an appserver ?
Thanks,
Neal