title: configure hibernate with spring
body: <p>I'm trying integrate spring with hibernate but catch NamingException: Context is read only</p>
  
  <p><strong>stacktrace</strong></p>
  
  <pre><code>WARNING: Could not bind factory to JNDI
  javax.naming.NamingException: Context is read only
      at org.apache.naming.NamingContext.checkWritable(NamingContext.java:903)
      at org.apache.naming.NamingContext.createSubcontext(NamingContext.java:517)
      at org.apache.naming.NamingContext.createSubcontext(NamingContext.java:538)
      at org.apache.naming.SelectorContext.createSubcontext(SelectorContext.java:422)
      at javax.naming.InitialContext.createSubcontext(InitialContext.java:464)
      at org.hibernate.util.NamingHelper.bind(NamingHelper.java:69)
      at org.hibernate.impl.SessionFactoryObjectFactory.addInstance(SessionFactoryObjectFactory.java:90)
      at org.hibernate.impl.SessionFactoryImpl.&lt;init&gt;(SessionFactoryImpl.java:306)
      at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1300)
      at org.springframework.orm.hibernate3.LocalSessionFactoryBean.newSessionFactory(LocalSessionFactoryBean.java:855)
      at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:774)
      at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:211)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1460)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1398)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:512)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:450)
      at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:290)
      at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
      at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:287)
      at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:189)
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:540)
      at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:842)
      at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:416)
      at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:261)
      at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:192)
      at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47)
      at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3843)
      at org.apache.catalina.core.StandardContext.start(StandardContext.java:4350)
      at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
      at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
      at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:525)
      at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:626)
      at org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.java:553)
      at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:488)
      at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1147)
      at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311)
      at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
      at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
      at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
      at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
      at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
      at org.apache.catalina.core.StandardService.start(StandardService.java:516)
      at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
      at org.apache.catalina.startup.Catalina.start(Catalina.java:578)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:597)
      at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
      at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
  </code></pre>
  
  <p><strong>configs</strong></p>
  
  <pre><code>&lt;bean id="myDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"&gt;
      &lt;property name="driverClassName" value="com.mysql.jdbc.Driver"/&gt;
      &lt;property name="url" value="jdbc:mysql://localhost/school"/&gt;
      &lt;property name="username" value="root"/&gt;
      &lt;property name="password" value="toor"/&gt;
  &lt;/bean&gt;
  
  &lt;bean id="hibernateSessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"&gt;
      &lt;property name="dataSource" ref="myDataSource"/&gt;
      &lt;property name="configLocation" value="/WEB-INF/hib.cfg.xml"/&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>hib.cfg.xml</p>
  
  <pre><code>&lt;hibernate-configuration&gt;
      &lt;session-factory name="java:hibernate/SessionFactory"&gt;
          &lt;property name="dialect"&gt;org.hibernate.dialect.MySQLDialect&lt;/property&gt;
          &lt;property name="show_sql"&gt;false&lt;/property&gt;
          &lt;property name="transaction.factory_class"&gt;
              org.hibernate.transaction.JTATransactionFactory
          &lt;/property&gt;
          &lt;property name="jta.UserTransaction"&gt;java:comp/UserTransaction&lt;/property&gt;
          &lt;property name="configClass"&gt;org.hibernate.cfg.AnnotationConfiguration&lt;/property&gt;
  
          &lt;mapping class="com.domain.Worker"/&gt;
      &lt;/session-factory&gt;
  &lt;/hibernate-configuration&gt;
  </code></pre>
  
  <p>How i can solve this problem?</p>
  
  <p>Thanks.</p>