-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 
Author Message
 Post subject: JNDI, hibernate.cfg.xml, SessionFactory
PostPosted: Thu Nov 02, 2006 10:29 am 
Regular
Regular

Joined: Mon Oct 02, 2006 12:03 pm
Posts: 62
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.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 02, 2006 11:10 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
the dao generation is not as optimal as i would like it to be.


but you can customize the templates to generate the code you would like to have in the getSessionFactory code...

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 02, 2006 11:40 am 
Regular
Regular

Joined: Mon Oct 02, 2006 12:03 pm
Posts: 62
How I can modify these templates? Does any tutorial exist?

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 02, 2006 12:57 pm 
Regular
Regular

Joined: Mon Oct 02, 2006 12:03 pm
Posts: 62
I've seen this link, this pacth is util for us. Will be it available speedy?

http://opensource.atlassian.com/projects/hibernate/browse/HBX-733


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 02, 2006 2:28 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
the patch is there for you to use.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 02, 2006 2:41 pm 
Regular
Regular

Joined: Mon Oct 02, 2006 12:03 pm
Posts: 62
max wrote:
the patch is there for you to use.


Mmm, I don't know how I can integrate this pacth to my Hibernate Tools. What Would I have to make to integrate this pacth in my HibernateTools?

Thanks max.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 02, 2006 2:46 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
look under build and contribute under tools.hibernate.org

_________________
Max
Don't forget to rate


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.