-->
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.  [ 6 posts ] 
Author Message
 Post subject: Hibernate 4 and tomcat
PostPosted: Tue Oct 25, 2011 12:01 pm 
Newbie

Joined: Tue Oct 25, 2011 11:54 am
Posts: 4
Hi,
I try to migrate to hibernate 4 snapshot with an existing code that works fine under hibernate 3.6.7.
It work in standalone mode.
But within tomcat, with a datasource key (hibernate.connection.datasource) like "java:comp/env/jdbc/myDb" I get many reloading before crash app. I have namingException that jdni couldn't find datasource. At last I get an exception indicates to use an url key.

I build sessionFactory inside ServletContext.

Is it a bug, or there is a work around

Thank's


Top
 Profile  
 
 Post subject: Re: Hibernate 4 and tomcat
PostPosted: Wed Oct 26, 2011 4:56 am 
Newbie

Joined: Tue Oct 25, 2011 11:54 am
Posts: 4
Exceptions:
Code:
Caused by: org.hibernate.service.jndi.JndiException: Unable to lookup JNDI name [java:comp/env/jdbc/myCompDb]
   at org.hibernate.service.jndi.internal.JndiServiceImpl.locate(JndiServiceImpl.java:68)
   at org.hibernate.service.jdbc.connections.internal.DatasourceConnectionProviderImpl.configure(DatasourceConnectionProviderImpl.java:116)
   at org.hibernate.service.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:81)
   at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:160)
   at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:133)
   at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.buildJdbcConnectionAccess(JdbcServicesImpl.java:208)
   at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:85)
   at org.hibernate.service.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:81)
   at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:160)
   at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:133)
   at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:70)
   at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2256)
   at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2252)
   at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1721)
   at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1761)
   at myComp.business.services.HibernateOracleModule.provideSessionFactory(HibernateOracleModule.java:59)

.....

Caused by: javax.naming.NamingException: Ce Contexte doit être accédé par une java: URL
   at org.apache.naming.SelectorContext.parseName(SelectorContext.java:776)
   at org.apache.naming.SelectorContext.lookup(SelectorContext.java:135)
   at javax.naming.InitialContext.lookup(InitialContext.java:415)
   at org.hibernate.service.jndi.internal.JndiServiceImpl.locate(JndiServiceImpl.java:65)
   ... 67 more


Top
 Profile  
 
 Post subject: Re: Hibernate 4 and tomcat
PostPosted: Tue Dec 27, 2011 6:42 am 
Newbie

Joined: Mon Sep 07, 2009 4:20 pm
Posts: 12
I have encountered exactly the same problem when upgrading from hibernate 3.6 to 4.0.

Did you find a solution in the meantime ?


Top
 Profile  
 
 Post subject: Re: Hibernate 4 and tomcat
PostPosted: Tue Jan 31, 2012 2:12 pm 
Newbie

Joined: Tue Oct 25, 2011 11:54 am
Posts: 4
No I haven't found solution. Still in Hibernate 3.

I used Tomcat's JNDI-bound JDBC connections, and when hibernate searching Datasource, it create an InitialContext, which is empty.

May be I will try to set DataDource directly into hibernate config. I see in DatasourceConnectionProviderImpl:
Code:
// Could be a solution to get Datasource and set in config
final Object dataSource = configValues.get( Environment.DATASOURCE );
         if ( DataSource.class.isInstance( dataSource ) ) {
            this.dataSource = (DataSource) dataSource;
         }
         else {
            final String dataSourceJndiName = (String) dataSource;
                                if ( dataSourceJndiName == null ) {
               throw new HibernateException(
                     "DataSource to use was not injected nor specified by [" + Environment.DATASOURCE
                           + "] configuration property"
               );
            }
            if ( jndiService == null ) {
               throw new HibernateException( "Unable to locate JndiService to lookup Datasource" );
            }
            this.dataSource = (DataSource) jndiService.locate( dataSourceJndiName );
//--> Here where my exception lauchs
         }
      }


Top
 Profile  
 
 Post subject: Re: Hibernate 4 and tomcat
PostPosted: Tue Jan 31, 2012 2:14 pm 
Newbie

Joined: Tue Oct 25, 2011 11:54 am
Posts: 4
Hope someone could give some clues

I open an issue.... https://hibernate.onjira.com/browse/HHH-7012


Top
 Profile  
 
 Post subject: Re: Hibernate 4 and tomcat
PostPosted: Mon Feb 13, 2012 11:46 am 
Newbie

Joined: Wed Jun 04, 2008 2:29 pm
Posts: 2
It looks like in the Hibernate 3.3 source code that the data source was retrieved by the following code where jndiName is a string (from org.hibernate.connection.DatasourceConnection line 75)

Code:
ds = ( DataSource ) NamingHelper.getInitialContext( props ).lookup( jndiName );


In 4.1.0 it is done by the following where name is a javax.naming.Name (from org.hibernate.service.jndi.internal.JndiServiceImpl line 65)

Code:
   public Object locate(String jndiName) {
      InitialContext initialContext = buildInitialContext();
      Name name = parseName( jndiName, initialContext );
      try {
         return initialContext.lookup( name );
      }
      catch ( NamingException e ) {
         throw new JndiException( "Unable to lookup JNDI name [" + jndiName + "]", e );
      }
      finally {
         cleanUp( initialContext );
      }
   }


If you make the following fix to the above code it will work.
Code:
return initialContext.lookup( name.toString() );


The Name object that it is using is a javax.naming.CompositeName which I think is the problem but I don't know why it is of that type.

The Name object is generated from line 86 in JndiServiceImpl

Code:
return context.getNameParser( "" ).parse( jndiName );


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