Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version:3.1
Name and version of the database you are using:Oracle 10g
Hello forum, I'm using Hibernate Tools in order to generate POJO classes, mapping classes and DAO's classes. Hibernate Tools generates me these files correctly. However I have taken several days how I can assemple all in J2EE web application structure.
The main problem is Hibernate Tools generates me DAO's files as this form -->
Code:
public class DAO {
private static final Log log = LogFactory.getLog(StatusDAO.class);
private final SessionFactory sessionFactory = getSessionFactory();
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");
}
}
public void persist(Status transientInstance) {
log.debug("persisting Status instance");
try {
sessionFactory.getCurrentSession().persist(transientInstance);
...
I don't know how do I use it? Concretly, I don't know how do I write hibernate.cfg.xml file in order to use JNDI, because getSessionFactory function uses ---- nitialContext().lookup("SessionFactory") ---- So, when I use a DAO, it finds one sessionFactory at tomcat (or others) resources, but I don't how do I configure it.
My definitive question is: How do I integrate DAO classes to use JNDI properties correctly?
Thanks for all.