-->
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.  [ 2 posts ] 
Author Message
 Post subject: JNDI, hibernate.cfg.xml, SessionFactory
PostPosted: Tue Oct 31, 2006 1:39 pm 
Regular
Regular

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


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 31, 2006 2:59 pm 
Beginner
Beginner

Joined: Mon Dec 06, 2004 4:20 pm
Posts: 34
If you are wondering about the actual config file for JNDI, here's an snippet of hibernate.cfg.xml set up for WebLogic:

<property name="jndi.url">t3://localhost:9011</property>
<property name="jndi.class">
weblogic.jndi.WLInitialContextFactory
</property>
<property name="connection.datasource">myDatasource</property>
<property name="transaction.manager_lookup_class">
org.hibernate.transaction.WeblogicTransactionManagerLookup
</property>
<property name="connection.username">weblogic</property>
<property name="connection.password">weblogic</property>
<property name="hibernate.dialect">
org.hibernate.dialect.OracleDialect
</property>
<property name="session_factory_name">MyHibernateFactory</property>
<property name="transaction.factory_class">
org.hibernate.transaction.JTATransactionFactory
</property>

Don


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.