4 Replies Latest reply on Dec 1, 2007 9:42 PM by dazhu tang

    can't find datasource problem when mirgrate from seam1.2 to

    dazhu tang Newbie

      My application is working very well until i decide to migrade from seam1.2 to seam2, i am stuck by hibernate configuration problem in seam2, which always sent the message "Can't find the data source" , I have to list the related configuration files here, I also check your forum, it seems that there are other people are asking the similar question before , but with no good answer.

      1. components.xml under "WEB-INF" directory of my application

      
      <?xml version="1.0" encoding="UTF-8"?>
      <components xmlns="http://jboss.com/products/seam/components"
       xmlns:core="http://jboss.com/products/seam/core"
       xmlns:bpm="http://jboss.com/products/seam/bpm"
       xmlns:persistence="http://jboss.com/products/seam/persistence"
       xmlns:security="http://jboss.com/products/seam/security"
       xmlns:transaction="http://jboss.com/products/seam/transaction"
       xmlns:framework="http://jboss.com/products/seam/framework"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://jboss.com/products/seam/core http://jboss.com/products/seam/core-2.0.xsd
       http://jboss.com/products/seam/bpm http://jboss.com/products/seam/bpm-2.0.xsd
       http://jboss.com/products/seam/persistence http://jboss.com/products/seam/persistence-2.0.xsd
       http://jboss.com/products/seam/security http://jboss.com/products/seam/security-2.0.xsd
       http://jboss.com/products/seam/transaction http://jboss.com/products/seam/transaction-2.0.xsd
       http://jboss.com/products/seam/framework http://jboss.com/products/seam/framework-2.0.xsd
       http://jboss.com/products/seam/components http://jboss.com/products/seam/components-2.0.xsd">
      
       <core:init debug="true" transaction-management-enabled="false" />
      
       <!-- 120 second conversation timeout -->
       <core:manager conversation-timeout="1800000"
       concurrent-request-timeout="500" conversation-id-parameter="cid" />
      
       <!-- this is related with hibernate.cfg.xml which install the hibernate entity manager-->
      
       <persistence:hibernate-session-factory
       name="hibernateSessionFactory" />
      
       <persistence:managed-hibernate-session name="session"
       session-factory-jndi-name="java:/HibernateSessionFactory"
       auto-create="true" />
      
      
      </components>
      


      2.hibernate.cfg.xml and seam.properties deployed directly in jar file of my application
      <hibernate-configuration>
       <session-factory name="java:/HibernateSessionFactory">
       <property name="hibernate.show_sql">false</property>
       <property name="connection.datasource">java:/CPI_SqlserverDatasource</property>
      
      ...
      </hibernate-configuration>
      


      3.my ds.xml file for data source, i deploy it into the {Tomcat6.home}\lib\deploy directory

      
      <?xml version="1.0" encoding="UTF-8"?>
      <datasources>
      
       <local-tx-datasource>
       <jndi-name>CPI_SqlserverDatasource</jndi-name>
       <connection-url>jdbc:sqlserver://127.0.0.1:1433;DatabaseName=CPI_NEW;integratedSecurity=true;applicationName=CPI UI;</connection-url>
      
       <driver-class>com.microsoft.sqlserver.jdbc.SQLServerDriver</driver-class>
      
       <min-pool-size>5</min-pool-size>
       <max-pool-size>20</max-pool-size>
       <transaction-isolation>TRANSACTION_READ_COMMITTED</transaction-isolation>
       <idle-timeout-minutes>0</idle-timeout-minutes>
       </local-tx-datasource>
      
      </datasources>
      



      4. faces-config.xml under "WEB-INF" directory of my application
      
      <?xml version='1.0' encoding='UTF-8'?>
      <faces-config version="1.2"
       xmlns="http://java.sun.com/xml/ns/javaee"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd">
      
      
       <application>
       <locale-config>
      
       <default-locale>en</default-locale>
       <supported-locale>en</supported-locale>
       <supported-locale>zh</supported-locale>
      
       </locale-config>
      
       </application>
      
      
      
      </faces-config>
      



      5. context.xml under the "META-INF" directory of my application
      <?xml version="1.0" encoding="UTF-8"?>
      <Context override="true">
       <Manager
       className="org.apache.catalina.session.StandardManager"
       distributable="false"
       maxActiveSessions="-1"
       pathname=""
       />
      </Context>
      
      


      the exception i got is

      严�: Exception sending context initialized event to listener instance of class org.jboss.seam.servlet.SeamListener
      org.hibernate.HibernateException: Could not find datasource: java:/CPI_SqlserverDatasource
      at org.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:59)
      at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:124)
      at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:56)
      at org.hibernate.cfg.SettingsFactory.createConnectionProvider(SettingsFactory.java:414)
      at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:62)
      at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2009)
      at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1292)
      at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:915)
      at org.jboss.seam.persistence.HibernateSessionFactory.createSessionFactory(HibernateSessionFactory.java:165)
      at org.jboss.seam.persistence.HibernateSessionFactory.startup(HibernateSessionFactory.java:79)
      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:585)
      at org.jboss.seam.util.Reflections.invoke(Reflections.java:21)
      at org.jboss.seam.util.Reflections.invokeAndWrap(Reflections.java:125)
      at org.jboss.seam.Component.callComponentMethod(Component.java:2074)
      at org.jboss.seam.Component.callCreateMethod(Component.java:1997)
      at org.jboss.seam.Component.newInstance(Component.java:1968)
      at org.jboss.seam.contexts.Contexts.startup(Contexts.java:304)
      at org.jboss.seam.contexts.Contexts.startup(Contexts.java:278)
      at org.jboss.seam.contexts.ServletLifecycle.endInitialization(ServletLifecycle.java:95)
      at org.jboss.seam.init.Initialization.init(Initialization.java:555)
      at org.jboss.seam.servlet.SeamListener.contextInitialized(SeamListener.java:34)
      at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3830)
      at org.apache.catalina.core.StandardContext.start(StandardContext.java:4337)
      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:1138)
      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:566)
      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:585)
      at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
      at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)


      Can someone give me some userful comments on this ? Thanks in advance.

        • 1. Re: can't find datasource problem when mirgrate from seam1.2
          dazhu tang Newbie

          I forgot to tell that i was trying under the tomcat6 with embedded jboss, And i also tried to deploy hibernate example in the Seam2 into tomcat6, but with the same exceptions:

          org.hibernate.HibernateException: Could not find datasource
          at org.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:56)
          at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:124)
          at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:56)
          at org.hibernate.cfg.SettingsFactory.createConnectionProvider(SettingsFactory.java:414)
          at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:62)
          at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2009)
          at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1292)
          at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:915)
          at org.jboss.seam.persistence.HibernateSessionFactory.createSessionFactory(HibernateSessionFactory.java:165)
          at org.jboss.seam.persistence.HibernateSessionFactory.startup(HibernateSessionFactory.java:79)
          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:585)
          at org.jboss.seam.util.Reflections.invoke(Reflections.java:21)
          at org.jboss.seam.util.Reflections.invokeAndWrap(Reflections.java:125)
          at org.jboss.seam.Component.callComponentMethod(Component.java:2074)
          at org.jboss.seam.Component.callCreateMethod(Component.java:1997)
          at org.jboss.seam.Component.newInstance(Component.java:1968)
          at org.jboss.seam.contexts.Contexts.startup(Contexts.java:304)
          at org.jboss.seam.contexts.Contexts.startup(Contexts.java:278)
          at org.jboss.seam.contexts.ServletLifecycle.endInitialization(ServletLifecycle.java:95)
          at org.jboss.seam.init.Initialization.init(Initialization.java:555)
          at org.jboss.seam.servlet.SeamListener.contextInitialized(SeamListener.java:34)
          at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3830)
          at org.apache.catalina.core.StandardContext.start(StandardContext.java:4337)
          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.deployWAR(HostConfig.java:825)
          at org.apache.catalina.startup.HostConfig.deployWARs(HostConfig.java:714)
          at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:490)
          at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1138)
          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:566)
          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:585)
          at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
          at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
          Caused by: javax.naming.NameNotFoundException: Name java:comp is not bound in this Context
          at org.apache.naming.NamingContext.lookup(NamingContext.java:770)
          at org.apache.naming.NamingContext.lookup(NamingContext.java:153)
          at org.apache.naming.SelectorContext.lookup(SelectorContext.java:137)
          at org.jboss.embedded.tomcat.jndi.ENCFactory.getObjectInstance(ENCFactory.java:73)
          at javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:304)
          at javax.naming.spi.NamingManager.getContext(NamingManager.java:422)
          at javax.naming.spi.ContinuationContext.getTargetContext(ContinuationContext.java:38)
          at javax.naming.spi.NamingManager.getContinuationContext(NamingManager.java:770)
          at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:718)
          at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:590)
          at javax.naming.InitialContext.lookup(InitialContext.java:351)
          at org.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:52)
          ... 47 more

          • 2. Re: can't find datasource problem when mirgrate from seam1.2
            Pete Muir Master

            You should put the ds in your WEB-INF/classes if deploying to embedded on tomcat.

            • 3. Re: can't find datasource problem when mirgrate from seam1.2
              dazhu tang Newbie

              Well,I have put my -ds.xml file under WEB-INF and WEB-INF\classes and even META_INF of my application directory, but it all doesn't work! I don't understand why it is so hard for configuration.

              But if i put the -ds.xml under the {tomcat}/lib/deploy directory , it at least can find the datasoure when tomcat is started.

              INFO 01-12 09:34:11,416 (ConnectionFactoryBindingService.java:bindConnectionFactory:148) -Bound ConnectionManager 'jboss.jca:service=DataSourceBinding,name=CPI_SqlserverDatasource' to JNDI name 'java:CPI_SqlserverDatasource'

              but i just don't know why my hibernate can't find this datasource under this kind of situation.

              • 4. Re: can't find datasource problem when mirgrate from seam1.2
                dazhu tang Newbie

                Can someone share his experience for integrating seam2 with Hibernate successfully?