12 Replies Latest reply: Jun 5, 2012 2:35 AM by Sergiu Pienar RSS

    Can not create HibernateSessionFactory -> NamingContext is read-only

    Sergiu Pienar Apprentice

      I'm trying to set up Hibernate 3.6.9 with JBoss 7.1.0  .

       

      To create the SessionFactory I'm using a class which extends org.hibernate.jmx.HibernateService .


      Upon JBoss start-up I get the following errors :

       

      12:18:33,768 INFO  [org.hibernate.util.NamingHelper] (MSC service thread 1-16) JNDI InitialContext properties:{}

      12:18:33,773 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-16) MSC00001: Failed to start service jboss.mbean.service."jboss.jca:service=HibernateFactory,name=HibernateFactory".start: org.jboss.msc.service.StartException in service jboss.mbean.service."jboss.jca:service=HibernateFactory,name=HibernateFactory".start: JBAS017222: Failed to execute legacy service start() method

              at org.jboss.as.service.StartStopService.start(StartStopService.java:56)

              at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]

              at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]

              at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [rt.jar:1.6.0_25-ea]

              at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [rt.jar:1.6.0_25-ea]

              at java.lang.Thread.run(Thread.java:662) [rt.jar:1.6.0_25-ea]

      Caused by: java.lang.reflect.InvocationTargetException

              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.6.0_25-ea]

              at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) [rt.jar:1.6.0_25-ea]

              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) [rt.jar:1.6.0_25-ea]

              at java.lang.reflect.Method.invoke(Method.java:597) [rt.jar:1.6.0_25-ea]

              at org.jboss.as.service.AbstractService.invokeLifecycleMethod(AbstractService.java:52)

              at org.jboss.as.service.StartStopService.start(StartStopService.java:54)

              ... 5 more

      Caused by: java.lang.UnsupportedOperationException: JBAS011859: Naming context is read-only

              at org.jboss.as.naming.WritableServiceBasedNamingStore.requireOwner(WritableServiceBasedNamingStore.java:126)

              at org.jboss.as.naming.WritableServiceBasedNamingStore.unbind(WritableServiceBasedNamingStore.java:98)

              at org.jboss.as.naming.WritableServiceBasedNamingStore.rebind(WritableServiceBasedNamingStore.java:85)

              at org.jboss.as.naming.NamingContext.rebind(NamingContext.java:237)

              at org.hibernate.util.NamingHelper.bind(NamingHelper.java:97)

              at org.hibernate.impl.SessionFactoryObjectFactory.addInstance(SessionFactoryObjectFactory.java:113)

              at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:367)

              at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1872)

              at org.hibernate.jmx.HibernateService.buildSessionFactory(HibernateService.java:64)

              at org.hibernate.jmx.HibernateService.start(HibernateService.java:40)

              at com.persistence.HibernateService.start(HibernateService.java:27)

        • 1. Re: Can not create HibernateSessionFactory -> NamingContext is read-only
          jaikiran pai Master

          I think this was fixed in 7.1.1.Final. So please try that version or the latest nightly builds.

          • 2. Re: Can not create HibernateSessionFactory -> NamingContext is read-only
            Sergiu Pienar Apprentice

            I did try with JBoss 7.1.1 Final but with no success. I'll give it a go with the latest nightly.

            Thank you

            • 3. Re: Can not create HibernateSessionFactory -> NamingContext is read-only
              jaikiran pai Master

              Actually looking at the stacktrace and your description, you are deploying the HibernateService via the MBean? I would recommend that you just switch to the JPA spec compliant persistence.xml approach and package those entities in a .jar. That'll let the JPA integration code to kick in and do the necessary setup for this binding.

              • 4. Re: Can not create HibernateSessionFactory -> NamingContext is read-only
                Sergiu Pienar Apprentice

                I can't go with the JPA approach due to my management (I don't think they'll be happy if I tell them this)

                • 5. Re: Can not create HibernateSessionFactory -> NamingContext is read-only
                  jaikiran pai Master

                  Okay, fair enough. But if you have to convince them then you can surely say that the JPA approach is portable since it's a specification. But if you still have to stick with the sar approach (which I don't know how good it is in AS7) then first give it a try against either 7.1.1.Final or latest nightly build (preferable) and if it fails there then please post the relevant stacktrace. Let's see if there's a way around it.

                  • 6. Re: Can not create HibernateSessionFactory -> NamingContext is read-only
                    Sergiu Pienar Apprentice

                    I tried with JBoss AS 7.2.0.Alpha1-SNAPSHOT "Steropes". Same problem. The relevant stacktrace is at : http://pastebin.com/pw6yLLLT

                     

                    Thank you

                    • 7. Re: Can not create HibernateSessionFactory -> NamingContext is read-only
                      jaikiran pai Master

                      Sergiu Pienar wrote:

                       

                      The relevant stacktrace is at : http://pastebin.com/pw6yLLLT

                       

                       

                      Let's just paste it here:

                       

                      11:08:31,430 INFO  [org.jboss.as.osgi] (MSC service thread 1-9) JBAS011907: Register module: Module "deployment.all-dev.ear.all-schedulers.sar:main" from Service Module Loader
                      11:08:31,437 INFO  [org.hibernate.jmx.HibernateServiceMBean] (MSC service thread 1-8) starting service at JNDI name: java:jboss/HibernateFactory
                      11:08:31,439 INFO  [org.hibernate.jmx.HibernateServiceMBean] (MSC service thread 1-8) service properties: {hibernate.session_factory_name=java:jboss/HibernateFactory, hibernate.transaction.manager_lookup_class=org.hibernate.transaction.JBossTransactionManagerLookup, hibernate.transaction.auto_close_session=true, hibernate.transaction.factory_class=org.hibernate.transaction.CMTTransac
                      11:08:31,538 INFO  [org.jboss.as.osgi] (MSC service thread 1-10) JBAS011907: Register module: Module "deployment.all-dev.ear.administrator.war:main" from Service Module Loader
                      11:08:31,545 INFO  [org.jboss.as.osgi] (MSC service thread 1-14) JBAS011907: Register module: Module "deployment.all-dev.ear.client.war:main" from Service Module Loader
                      11:08:31,617 INFO  [org.hibernate.annotations.common.Version] (MSC service thread 1-8) Hibernate Commons Annotations 3.2.0.Final
                      11:08:31,622 INFO  [org.hibernate.cfg.Environment] (MSC service thread 1-8) Hibernate 3.6.9.Final
                      11:08:31,626 INFO  [org.hibernate.cfg.Environment] (MSC service thread 1-8) loaded properties from resource hibernate.properties: {hibernate.transaction.flush_before_completion=true, hibernate.transaction.auto_close_session=true, hibernate.jdbc.fetch_size=5, hibernate.cache.provider_class=org.hibernate.cache.EhCacheProvider, hibernate.transaction.manager_lookup_class=org.hibernate.tr
                      11:08:31,629 INFO  [org.hibernate.cfg.Environment] (MSC service thread 1-8) using java.io streams to persist binary types
                      11:08:31,630 INFO  [org.hibernate.cfg.Environment] (MSC service thread 1-8) Bytecode provider name : javassist
                      11:08:31,634 INFO  [org.hibernate.cfg.Environment] (MSC service thread 1-8) using JDK 1.4 java.sql.Timestamp handling
                      11:08:31,737 INFO  [org.hibernate.cfg.Configuration] (MSC service thread 1-8) Hibernate Validator not found: ignoring
                      11:08:31,798 INFO  [org.hibernate.validator.util.Version] (MSC service thread 1-8) Hibernate Validator 4.2.0.Final
                      11:08:31,847 INFO  [org.hibernate.cfg.search.HibernateSearchEventListenerRegister] (MSC service thread 1-8) Unable to find org.hibernate.search.event.FullTextIndexEventListener on the classpath. Hibernate Search is not enabled.
                      11:08:31,849 INFO  [org.apache.struts.action.ActionServlet] (MSC service thread 1-10) Loading chain catalog from vfs:/C:/J7Alpha/jboss-as-7.2.0.Alpha1-SNAPSHOT/bin/content/all-dev.ear/lib/struts-tiles-1.3.8.jar/org/apache/struts/tiles/chain-config.xml
                      11:08:31,849 INFO  [org.apache.struts.action.ActionServlet] (MSC service thread 1-11) Loading chain catalog from vfs:/C:/J7Alpha/jboss-as-7.2.0.Alpha1-SNAPSHOT/bin/content/all-dev.ear/lib/struts-tiles-1.3.8.jar/org/apache/struts/tiles/chain-config.xml
                      11:08:31,852 INFO  [org.hibernate.util.NamingHelper] (MSC service thread 1-8) JNDI InitialContext properties:{}
                      11:08:31,858 INFO  [org.hibernate.connection.DatasourceConnectionProvider] (MSC service thread 1-8) Using datasource: java:jboss/datasources/myDS
                      11:08:32,264 INFO  [org.apache.struts.tiles.TilesPlugin] (MSC service thread 1-11) Tiles definition factory loaded for module ''.
                      11:08:32,266 INFO  [org.apache.struts.validator.ValidatorPlugIn] (MSC service thread 1-11) Loading validation rules file from '/WEB-INF/validator-rules.xml'
                      11:08:32,268 INFO  [org.apache.struts.validator.ValidatorPlugIn] (MSC service thread 1-11) Loading validation rules file from '/WEB-INF/validation.xml'
                      11:08:32,380 INFO  [org.jboss.web] (MSC service thread 1-11) JBAS018210: Registering web context: /administrator
                      11:08:32,389 INFO  [org.apache.struts.tiles.TilesPlugin] (MSC service thread 1-10) Tiles definition factory loaded for module ''.
                      11:08:32,392 INFO  [org.apache.struts.validator.ValidatorPlugIn] (MSC service thread 1-10) Loading validation rules file from '/WEB-INF/validator-rules.xml'
                      11:08:32,393 INFO  [org.apache.struts.validator.ValidatorPlugIn] (MSC service thread 1-10) Loading validation rules file from '/WEB-INF/validation.xml'
                      11:08:32,485 INFO  [org.hibernate.dialect.Dialect] (MSC service thread 1-8) Using dialect: org.hibernate.dialect.SAPDBDialect
                      11:08:32,497 INFO  [org.hibernate.cfg.SettingsFactory] (MSC service thread 1-8) Database ->
                             name : MySQL
                          version : 5.1.56-community
                            major : 5
                            minor : 1
                      11:08:32,564 INFO  [org.jboss.web] (MSC service thread 1-10) JBAS018210: Registering web context: /client
                      11:08:32,573 INFO  [org.hibernate.cfg.SettingsFactory] (MSC service thread 1-8) Driver ->
                             name : MySQL-AB JDBC Driver
                          version : mysql-connector-java-5.1.14 ( Revision: ${bzr.revision-id} )
                            major : 5
                            minor : 1
                      11:08:32,593 INFO  [org.hibernate.transaction.TransactionFactoryFactory] (MSC service thread 1-8) Transaction strategy: org.hibernate.transaction.CMTTransactionFactory
                      11:08:32,594 INFO  [org.hibernate.transaction.TransactionManagerLookupFactory] (MSC service thread 1-8) instantiating TransactionManagerLookup: org.hibernate.transaction.JBossTransactionManagerLookup
                      11:08:32,596 INFO  [org.hibernate.transaction.TransactionManagerLookupFactory] (MSC service thread 1-8) instantiated TransactionManagerLookup
                      11:08:32,603 INFO  [org.hibernate.cfg.SettingsFactory] (MSC service thread 1-8) Automatic flush during beforeCompletion(): enabled
                      11:08:32,605 INFO  [org.hibernate.cfg.SettingsFactory] (MSC service thread 1-8) Automatic session close at end of transaction: enabled
                      11:08:32,607 INFO  [org.hibernate.cfg.SettingsFactory] (MSC service thread 1-8) Scrollable result sets: enabled
                      11:08:32,609 INFO  [org.hibernate.cfg.SettingsFactory] (MSC service thread 1-8) JDBC3 getGeneratedKeys(): enabled
                      11:08:32,611 INFO  [org.hibernate.cfg.SettingsFactory] (MSC service thread 1-8) Connection release mode: auto
                      11:08:32,614 INFO  [org.hibernate.cfg.SettingsFactory] (MSC service thread 1-8) Maximum outer join fetch depth: 5
                      11:08:32,622 INFO  [org.hibernate.cfg.SettingsFactory] (MSC service thread 1-8) Default batch fetch size: 1
                      11:08:32,624 INFO  [org.hibernate.cfg.SettingsFactory] (MSC service thread 1-8) Generate SQL with comments: disabled
                      11:08:32,626 INFO  [org.hibernate.cfg.SettingsFactory] (MSC service thread 1-8) Order SQL updates by primary key: disabled
                      11:08:32,628 INFO  [org.hibernate.cfg.SettingsFactory] (MSC service thread 1-8) Order SQL inserts for batching: disabled
                      11:08:32,630 INFO  [org.hibernate.cfg.SettingsFactory] (MSC service thread 1-8) Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
                      11:08:32,640 INFO  [org.hibernate.hql.ast.ASTQueryTranslatorFactory] (MSC service thread 1-8) Using ASTQueryTranslatorFactory
                      11:08:32,649 INFO  [org.hibernate.cfg.SettingsFactory] (MSC service thread 1-8) Query language substitutions: {}
                      11:08:32,650 INFO  [org.hibernate.cfg.SettingsFactory] (MSC service thread 1-8) JPA-QL strict compliance: disabled
                      11:08:32,651 INFO  [org.hibernate.cfg.SettingsFactory] (MSC service thread 1-8) Second-level cache: enabled
                      11:08:32,653 INFO  [org.hibernate.cfg.SettingsFactory] (MSC service thread 1-8) Query cache: enabled
                      11:08:32,655 INFO  [org.hibernate.cfg.SettingsFactory] (MSC service thread 1-8) Cache region factory : org.hibernate.cache.impl.NoCachingRegionFactory
                      11:08:32,668 INFO  [org.hibernate.cfg.SettingsFactory] (MSC service thread 1-8) Optimize cache for minimal puts: disabled
                      11:08:32,669 INFO  [org.hibernate.cfg.SettingsFactory] (MSC service thread 1-8) Structured second-level cache entries: enabled
                      11:08:32,670 INFO  [org.hibernate.cfg.SettingsFactory] (MSC service thread 1-8) Query cache factory: org.hibernate.cache.StandardQueryCacheFactory
                      11:08:32,675 INFO  [org.hibernate.cfg.SettingsFactory] (MSC service thread 1-8) Statistics: disabled
                      11:08:32,676 INFO  [org.hibernate.cfg.SettingsFactory] (MSC service thread 1-8) Deleted entity synthetic identifier rollback: disabled
                      11:08:32,676 INFO  [org.hibernate.cfg.SettingsFactory] (MSC service thread 1-8) Default entity-mode: pojo
                      11:08:32,678 INFO  [org.hibernate.cfg.SettingsFactory] (MSC service thread 1-8) Named query checking : enabled
                      11:08:32,686 INFO  [org.hibernate.cfg.SettingsFactory] (MSC service thread 1-8) Check Nullability in Core (should be disabled when Bean Validation is on): disabled
                      11:08:32,700 INFO  [org.hibernate.impl.SessionFactoryImpl] (MSC service thread 1-8) building session factory
                      11:08:32,704 INFO  [org.hibernate.type.BasicTypeRegistry] (MSC service thread 1-8) Type registration [clob] overrides previous : org.hibernate.type.ClobType@1fc840d
                      11:08:32,704 INFO  [org.hibernate.type.BasicTypeRegistry] (MSC service thread 1-8) Type registration [java.sql.Clob] overrides previous : org.hibernate.type.ClobType@1fc840d
                      11:08:32,705 INFO  [org.hibernate.type.BasicTypeRegistry] (MSC service thread 1-8) Type registration [characters_clob] overrides previous : org.hibernate.type.PrimitiveCharacterArrayClobType@18dad71
                      11:08:32,707 INFO  [org.hibernate.type.BasicTypeRegistry] (MSC service thread 1-8) Type registration [materialized_blob] overrides previous : org.hibernate.type.MaterializedBlobType@bfc15b
                      11:08:32,710 INFO  [org.hibernate.type.BasicTypeRegistry] (MSC service thread 1-8) Type registration [wrapper_materialized_blob] overrides previous : org.hibernate.type.WrappedMaterializedBlobType@1d654a3
                      11:08:32,712 INFO  [org.hibernate.type.BasicTypeRegistry] (MSC service thread 1-8) Type registration [wrapper_characters_clob] overrides previous : org.hibernate.type.CharacterArrayClobType@1df2f9c
                      11:08:32,720 INFO  [org.hibernate.type.BasicTypeRegistry] (MSC service thread 1-8) Type registration [blob] overrides previous : org.hibernate.type.BlobType@65d075
                      11:08:32,722 INFO  [org.hibernate.type.BasicTypeRegistry] (MSC service thread 1-8) Type registration [java.sql.Blob] overrides previous : org.hibernate.type.BlobType@65d075
                      11:08:32,724 INFO  [org.hibernate.type.BasicTypeRegistry] (MSC service thread 1-8) Type registration [materialized_clob] overrides previous : org.hibernate.type.MaterializedClobType@f3360c
                      11:08:32,764 INFO  [org.hibernate.impl.SessionFactoryObjectFactory] (MSC service thread 1-8) Factory name: java:jboss/HibernateFactory
                      11:08:32,764 INFO  [org.hibernate.util.NamingHelper] (MSC service thread 1-8) JNDI InitialContext properties:{}
                      11:08:32,770 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-8) MSC00001: Failed to start service jboss.mbean.service."jboss.jca:service=HibernateFactory,name=HibernateFactory".start: org.jboss.msc.service.StartException in service jboss.mbean.service."jboss.jca:service=HibernateFactory,name=HibernateFactory".start: JBAS017222: Failed to execute legacy service start() method
                              at org.jboss.as.service.StartStopService.start(StartStopService.java:56)
                              at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
                              at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
                              at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [rt.jar:1.6.0_25-ea]
                              at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [rt.jar:1.6.0_25-ea]
                              at java.lang.Thread.run(Thread.java:662) [rt.jar:1.6.0_25-ea]
                      Caused by: java.lang.reflect.InvocationTargetException
                              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.6.0_25-ea]
                              at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) [rt.jar:1.6.0_25-ea]
                              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) [rt.jar:1.6.0_25-ea]
                              at java.lang.reflect.Method.invoke(Method.java:597) [rt.jar:1.6.0_25-ea]
                              at org.jboss.as.service.AbstractService.invokeLifecycleMethod(AbstractService.java:52)
                              at org.jboss.as.service.StartStopService.start(StartStopService.java:54)
                              ... 5 more
                      Caused by: java.lang.UnsupportedOperationException: JBAS011859: Naming context is read-only
                              at org.jboss.as.naming.WritableServiceBasedNamingStore.requireOwner(WritableServiceBasedNamingStore.java:126)
                              at org.jboss.as.naming.WritableServiceBasedNamingStore.unbind(WritableServiceBasedNamingStore.java:98)
                              at org.jboss.as.naming.WritableServiceBasedNamingStore.rebind(WritableServiceBasedNamingStore.java:85)
                              at org.jboss.as.naming.NamingContext.rebind(NamingContext.java:237)
                              at org.hibernate.util.NamingHelper.bind(NamingHelper.java:97)
                              at org.hibernate.impl.SessionFactoryObjectFactory.addInstance(SessionFactoryObjectFactory.java:113)
                              at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:367)
                              at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1872)
                              at org.hibernate.jmx.HibernateService.buildSessionFactory(HibernateService.java:64)
                              at org.hibernate.jmx.HibernateService.start(HibernateService.java:40)
                              at MyHibernateService.start(MyHibernateService.java:30)
                              ... 11 more
                      
                      11:08:33,227 INFO  [org.jboss.as.osgi] (MSC service thread 1-14) JBAS011907: Register module: Module "deployment.all-dev.ear.all-ejb.jar:main" from Service Module Loader
                      
                      • 8. Re: Can not create HibernateSessionFactory -> NamingContext is read-only
                        Scott Marlow Master

                        Or you could stop using "hibernate.session_factory_name=java:jboss/HibernateFactory", which requires that the jndi name space is writable.

                         

                        For JPA deployments, this is accomplished via this JPA deployment code https://github.com/jbossas/jboss-as/blob/master/jpa/core/src/main/java/org/jboss/as/jpa/service/PersistenceUnitServiceImpl.java#L84

                         

                         

                         WritableServiceBasedNamingStore.pushOwner(context.getController().getServiceContainer().subTarget());
                         this.entityManagerFactory = createContainerEntityManagerFactory();
                         WritableServiceBasedNamingStore.popOwner();            
                        
                        • 9. Re: Can not create HibernateSessionFactory -> NamingContext is read-only
                          Scott Marlow Master

                          I like this idea, just stop using "hibernate.session_factory_name".  Instead switch to JPA packaging/configuration.  You can then get the Hibernate SessionFactory from JPA (see JPA doc here for details.)

                           

                          This will also allow you to use JPA features as well.

                          • 10. Re: Can not create HibernateSessionFactory -> NamingContext is read-only
                            Scott Marlow Master

                            Sergiu,

                             

                            I didn't notice that you created both threads asking about this.  You will need to make some application changes, as we recommended.  Which path you follow is up to you.

                             

                            Scott

                            • 11. Re: Can not create HibernateSessionFactory -> NamingContext is read-only
                              Sergiu Pienar Apprentice

                              Hi Scott,

                               

                              Indeed I created both threads ... out of desperation


                              I'll have to decide on some approach. Thank you for your (and Jaikiran's) help so far.

                              • 12. Re: Can not create HibernateSessionFactory -> NamingContext is read-only
                                Sergiu Pienar Apprentice

                                Scott,

                                 

                                The WritableServiceBasedNamingStore.pushOwner approach can only be applied in a JPA environment ?

                                 

                                Thanks