-->
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.  [ 1 post ] 
Author Message
 Post subject: Hibernate and JNDI with Websphere Portal
PostPosted: Mon Jul 17, 2006 2:27 am 
Newbie

Joined: Fri Jul 14, 2006 3:19 am
Posts: 12
I'll have to make a db connection with JNDI to Hibernate.
Can anybody help me to find out what is wrong in my source.

my properties:
Code:
hibernate.connection.datasource = java:/comp/env/jdbc/jndiUrlaubsplaner
hibernate.jndi.url =  jdbc:oracle:thin:@AT-LXAUSW01.benteler.net:1521:wsphprod
hibernate.connection.username = urlaubsplaner 
hibernate.connection.password = urlaubsplaner 
hibernate.transaction.factory_class = \
    org.hibernate.transaction.JTATransactionFactory
hibernate.transaction.manager_lookup_class = \
    org.hibernate.transaction.JBossTransactionManagerLookup
hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect


my sessionbuild:
Code:
private SessionFactory _sessionFactory;
   private Session _session;
    private ThreadLocal _threadLocal = new ThreadLocal();

   // Template Methods
   protected abstract String getKeyFieldName();
   protected abstract Class getStoredClass();   

   // Methods
   protected AbstractServiceDBImpl() {
//      initalizeHibernate();
        if (! isHibernateInitialized())
            initalizeHibernate();
   }
   
   protected Session getSession() throws HibernateException {
      Contract.require(isHibernateInitialized(), "hibernate ist initialisiert");

      Session session = (Session) _threadLocal.get();
       
      if (session == null || !session.isOpen()) {      
         session = _sessionFactory.openSession();
            _threadLocal.set(session);
      }
      /*try {
          int i = 0;
         System.out.println(">>> session.connection().isClosed() " + session.connection().isClosed());
      } catch (HibernateException e) {
          System.out.println("Probleme beim connect");
         //e.printStackTrace();
      } catch (SQLException e) {
          System.out.println("Probleme beim connect");
         //e.printStackTrace();
      }*/   
            
      session.clear();
      
      Contract.ensure(session != null, "result");
      return session;
   }
 
    private boolean sessionIsConnected()
    {
//        return _session.isConnected();
        return ((Session) _threadLocal.get()).isConnected();
    }

   protected boolean isHibernateInitialized() {
       return _sessionFactory != null;
   }

   /**
    * Hibernate initialisieren. SessionFactory merken.
    */
   private void initalizeHibernate() {
       Contract.require(!isHibernateInitialized(), "Hibernate is not initialized yet");
       try
       {
           // Konfigurationsdateien einlesen
           URL mappingURL = getClass().getClassLoader().getResource("mapping.xml");
           InputStream in = getClass().getClassLoader().getResourceAsStream("hibernate.properties");

           Properties properties = new Properties();
           properties.load(in);
           System.out.println("test3");
           // Hibernate konfigurieren
           Configuration configuration = new Configuration();
           configuration.setProperties(properties);
           configuration.addURL(mappingURL);
           System.out.println("test4");
           // SessionFactory merken! Sie erzeugt die benötigten Sessions.
           _sessionFactory = configuration.buildSessionFactory();
       }
       catch (HibernateException e)
       {
           System.out.println("Probleme beim Konfigurieren von Hibernate!");
           e.printStackTrace();
       }
       catch (IOException e)
       {
           System.out.println("Probleme beim Zugriff auf die Datei hibernate.properties");
           e.printStackTrace();
       }
   
       Contract.ensure(isHibernateInitialized(), "Hibernate is successfully initialized");
   }


my main problem:
Quote:
[17.07.06 08:25:17:594 CEST] 544b4b1d DatasourceCon F org.hibernate.connection.DatasourceConnectionProvider Could not find datasource: java:/comp/env/jdbc/jndiUrlaubsplaner
[17.07.06 08:25:17:594 CEST] 544b4b1d DatasourceCon F org.hibernate.connection.DatasourceConnectionProvider TRAS0014I: Die folgende Ausnahmebedingung wurde protokolliert: javax.naming.NameNotFoundException: Name not found in context "java:".


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

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.