1 2 Previous Next 17 Replies Latest reply on Feb 2, 2010 7:23 AM by zeeman

    Seam 2.2 with AS 5.1 and hibernate not working

    zeeman Novice
      I have a new project that used to work in seam 2.1 deployed as a WAR. I used seam-gen from 2.2 to generate a new project. I copied my code to newly generated project and updated the schema declaration in xml files to 2.2. I have changed components.xml and persistance.xml to match Seam 2.2 examples (JPA one). I'm getting below error when I start the app server.

      If I comment out the import script I get EMF is not bound exception. Not sure if it's an issue with EMF and EM config or something else.
      `
      2010-01-24 20:18:38,609 ERROR [org.hibernate.tool.hbm2ddl.SchemaExport] (main) schema export unsuccessful
      org.hibernate.JDBCException: Error during import script execution at line 1
           at org.hibernate.tool.hbm2ddl.SchemaExport.importScript(SchemaExport.java:332)
           at org.hibernate.tool.hbm2ddl.SchemaExport.execute(SchemaExport.java:264)
           at org.hibernate.tool.hbm2ddl.SchemaExport.create(SchemaExport.java:211)
           at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:343)
           at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1327)
           at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:867)
           at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:669)
           at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:132)
           at org.jboss.jpa.deployment.PersistenceUnitDeployment.start(PersistenceUnitDeployment.java:301)
           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.reflect.plugins.introspection.ReflectionUtils.invoke(ReflectionUtils.java:59)

      Caused by: java.sql.SQLException: Table not found in statement [INSERT INTO properties]
      `
      I have an import script that inserts few rows in a properties table. For some reason hibernate is not finding my entity classes and not generating the DB schema.

      I have commented out the persistence-unit-ref node in web.xml.


      Data source:
           <local-tx-datasource>
                 <jndi-name>myProjectdatasource</jndi-name>
                 <use-java-context>false</use-java-context>
                 <connection-url>jdbc:hsqldb:mydb</connection-url>
                 <driver-class>org.hsqldb.jdbcDriver</driver-class>
                 <user-name>sa</user-name>
                 <password></password>
              </local-tx-datasource>

         
          persistence.xml:
          <persistence-unit name="myDS" transaction-type="JTA">
              <provider>org.hibernate.ejb.HibernatePersistence</provider>
              <jta-data-source>myProjectdatasource</jta-data-source>
              <properties>
                  <property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/>
                  <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
                  <property name="hibernate.show_sql" value="true"/>
                  <property name="hibernate.format_sql" value="true"/>
                  <property name="jboss.entity.manager.factory.jndi.name" value="java:/myprojectEMF"/>
                  <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup"/>
              </properties>
          </persistence-unit>
         

          components.xml:
          <core:init debug="@debug@" jndi-pattern="@jndiPattern@" />
         
           <core:manager concurrent-request-timeout="500"
                conversation-timeout="120000" conversation-id-parameter="cid"
                parent-conversation-id-parameter="pid" />

           <web:hot-deploy-filter url-pattern="*.seam" />

           <transaction:entity-transaction entity-manager="#{entityManager}" />

           <persistence:entity-manager-factory name="entityManagerFactory" installed="false" />

           <persistence:managed-persistence-context
                name="entityManager" auto-create="true" entity-manager-factory="#{entityManagerFactory}"
                persistence-unit-jndi-name="java:/myprojectEMF" />

        • 1. Re: Seam 2.2 with AS 5.1 and hibernate not working
          zeeman Novice

          Anyone? I have spent a week on this and made no progress.

          • 2. Re: Seam 2.2 with AS 5.1 and hibernate not working
            Robert  Anderson Newbie
            "Table not found in statement [INSERT INTO properties]"

            Are you sure that this table exists?
            • 3. Re: Seam 2.2 with AS 5.1 and hibernate not working
              zeeman Novice
              It's an entity in my domain model. For some reason Hibernate is not binding annotated entity classes.

              Even when I comment out my import sql script. I get an error saying entityManagerFactory not bound in JNDI when I try to access the db. So there must be something wrong in seam while setting up EMF.

              <blockquote>
              _Robert Anderson Nogueira de Oliveira wrote on Jan 26, 2010 11:02:_<br/>

              "Table not found in statement [INSERT INTO properties]"

              Are you sure that this table exists?
              </blockquote>

              Click HELP for text formatting instructions. Then edit this text and check the preview.
              • 4. Re: Seam 2.2 with AS 5.1 and hibernate not working
                zeeman Novice

                Still blocked on this. Would appreciate any help.

                • 5. Re: Seam 2.2 with AS 5.1 and hibernate not working
                  Jean Luc Apprentice

                  Do you have a correct persistence.xml in the META-INF of a JAR inside the WAR/EAR? This is required for a JPA provider to discover your entities (see section 6.2 of the specs).


                  I'd also like to ask the same question as Robert Anderson Nogueira de Oliveira: Are you sure that this table exists?. You said It's an entity in my domain model but that's not correct, the table is not an entity. The entity is mapped to the table. So does the table exists in the database?

                  • 6. Re: Seam 2.2 with AS 5.1 and hibernate not working
                    Jean Luc Apprentice

                    Forgot to add: if not using JPA but pure Hibernate, the file to check is hibernate.cfg.xml not persistence.xml

                    • 7. Re: Seam 2.2 with AS 5.1 and hibernate not working
                      zeeman Novice

                      I'm using JPA with Hibernate. I do have the persistence.xml file I posted above in a jar inside my war file.


                      As you can see I have hbm2ddl.auto set to create-drop. So Hibernate should create the tables for my entities.


                      Even when I comment out the import.sql I still get entity manager factory not bound to JNDI exception. So Seam in 2.2 for some reason is not creating the EMF. I followed the same exact steps for the JPA example. Which does work for me. But my project does not.

                      • 8. Re: Seam 2.2 with AS 5.1 and hibernate not working
                        yachaa Newbie

                        If the EMF is not bound, can you try to change the persistence.xml from



                        <jta-data-source>myProjectdatasource</jta-data-source>




                        to



                        <jta-data-source>java:/myProjectdatasource</jta-data-source>





                        The reason being is that because the namespace of your datasource may be global and you need to put java:/ prior to the name declared.


                        Hope it helps.

                        • 9. Re: Seam 2.2 with AS 5.1 and hibernate not working
                          zeeman Novice

                          I use in my DS

                          <use-java-context>false</use-java-context> 

                          which does not require java:/ to be included. I even tried it with java:/ it does not help. Not sure what's making Seam break in binding EMF.


                          Also, because this issue is driving me crazy and cannot find a solution for it. After I comment out sql in import script. I test my project WAR in jBoss 4.2 (I get entity manager null exception). When testing in jBoss 5.1 I get EMF not bound in JNDI error.



                          Ivan Sukianto wrote on Jan 30, 2010 11:55:


                          If the EMF is not bound, can you try to change the persistence.xml from

                          <jta-data-source>myProjectdatasource</jta-data-source>




                          to


                          <jta-data-source>java:/myProjectdatasource</jta-data-source>





                          The reason being is that because the namespace of your datasource may be global and you need to put java:/ prior to the name declared.

                          Hope it helps.


                          Click HELP for text formatting instructions. Then edit this text and check the preview.

                          • 10. Re: Seam 2.2 with AS 5.1 and hibernate not working
                            Jean Luc Apprentice

                            Browse the JNDI tree (using the JMX beans that come with JBoss,
                            http://localhost:8080/jmx-console/HtmlAdaptor?action=inspectMBean&name=jboss%3Aservice%3DJNDIView and invoke the list() method).


                            That will tell if you the data source is deployed at all (and where exactly). This will reduce the number of possibilities and possibly point towards the problem.

                            • 11. Re: Seam 2.2 with AS 5.1 and hibernate not working
                              zeeman Novice

                              From JBoss, the global JNDI name space has the below. It does have my data source. But I don't see my entity manager factory there. Any ideas?


                              +- QueueConnectionFactory
                                +- ldapEmailKey
                                +- XAConnectionFactory
                                +- queue
                                |   +- A
                                |   +- testQueue
                                |   +- ex
                                |   +- DLQ
                                |   +- MemberOnDemand
                                |   +- D
                                |   +- C
                                |   +- B
                                +- TransactionSynchronizationRegistry
                                +- myProjectdatasource
                                +- UUIDKeyGeneratorFactory
                                +- ldapTitle
                                +- HiLoKeyGeneratorFactory
                                +- adminUsername
                                +- ldapUsernameKey
                                +- UIL2ConnectionFactory[link -> ConnectionFactory]
                                +- ldapActiveKey
                                +- adminPwd
                                +- UserTransactionSessionFactory (proxy: $Proxy15 implements interface org.jboss.tm.usertx.interfaces.UserTransactionSessionFactory)
                                +- ldapSizeLimit
                                +- UILXAConnectionFactory[link -> XAConnectionFactory]
                                +- ldapMemberOfKey
                                +- console
                                |   +- PluginManager (proxy: $Proxy48 implements interface org.jboss.console.manager.PluginManagerMBean)
                                +- ldapFirstNameKey
                                +- HTTPXAConnectionFactory
                                +- topic
                                |   +- testDurableTopic
                                |   +- testTopic
                                |   +- securedTopic
                                +- searchBase
                                +- providerType
                                +- ldapLastNameKey
                                +- UserTransaction
                                +- HTTPConnectionFactory
                                +- UIL2XAConnectionFactory[link -> XAConnectionFactory]
                                +- UILConnectionFactory[link -> ConnectionFactory]
                                +- jmx
                                |   +- invoker
                                |   |   +- RMIAdaptor (proxy: $Proxy47 implements interface org.jboss.jmx.adaptor.rmi.RMIAdaptor,interface org.jboss.jmx.adaptor.rmi.RMIAdaptorExt)
                                |   +- rmi
                                |   |   +- RMIAdaptor[link -> jmx/invoker/RMIAdaptor]
                                +- searchFilter
                                +- ConnectionFactory
                                +- providerUrl
                                +- TopicConnectionFactory
                                +- ldapPhoneKey
                                +- searchFilterUsers
                              



                              From the Java: namespace I have:


                                +- jaas
                                |   +- EncryptDBPassword
                                |   +- HsqlDbRealm
                                |   +- jbossmq
                                |   +- EncryptDBPasswordInt
                                |   +- JmsXARealm
                                +- TransactionPropagationContextImporter
                                +- JmsXA
                                +- comp.ejb3
                                |   NonContext: null
                                +- DefaultDS
                                +- StdJMSPool
                                +- TransactionManager
                                +- TransactionPropagationContextExporter
                                +- ConnectionFactory
                                +- jdbc
                                +- DefaultJMSProvider
                                +- XAConnectionFactory
                                +- Mail
                                +- comp.original
                                +- timedCacheFactory
                              Failed to lookup: timedCacheFactory, errmsg=org.jboss.util.TimedCachePolicy
                                +- SecurityProxyFactory
                                +- comp
                              

                              • 12. Re: Seam 2.2 with AS 5.1 and hibernate not working
                                Jean Luc Apprentice

                                My data sources and EMF are under java:, see below:


                                
                                java: Namespace
                                
                                  +- EntityManagerFactories (class: org.jnp.interfaces.NamingContext)
                                  |   +- mainUnit (class: org.jboss.jpa.injection.InjectedEntityManagerFactory)
                                  +- fooDatasource (class: org.jboss.resource.adapter.jdbc.WrapperDataSource)
                                  +- barDatasource (class: org.jboss.resource.adapter.jdbc.WrapperDataSource)
                                



                                Enable DEBUG logging for Hibernate, Seam and JBoss, perhaps you'll see something in the log hinting why the EMF is not deployed. Are other Seam components deployed (if not, components.xml is probably not found). Are the right XSDs references in components.xml?


                                I use Seam 2.2, JBoss 5.1 and Hibernate without problems so it must be something specific to your environment.


                                • 13. Re: Seam 2.2 with AS 5.1 and hibernate not working
                                  zeeman Novice

                                  I did set the log level to DEBUG for seam, hibernate, and jboss. I don't see any logs from jboss about binding my EMF in JNDI. My Seam components do get deployed fine. I do have the right XSDs in components.xml (copied from 2.2 examples).


                                  Can you post your persistence.xml and components.xml? I can compare my files to yours. Thanks!

                                  • 14. Re: Seam 2.2 with AS 5.1 and hibernate not working
                                    Jean Luc Apprentice

                                    persistence.xml




                                    <?xml version="1.0" encoding="UTF-8" ?>
                                    <persistence xmlns="http://java.sun.com/xml/ns/persistence"
                                        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                                        xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
                                            http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" version="1.0">
                                       <persistence-unit name="mainUnit">
                                          <provider>org.hibernate.ejb.HibernatePersistence</provider>
                                          <jta-data-source>java:/fooDatasource</jta-data-source>
                                          <mapping-file>META-INF/orm.xml</mapping-file>
                                          <properties>
                                             <property name="hibernate.hbm2ddl.auto" value="validate"/>
                                             <property name="hibernate.cache.use_query_cache" value="false"/>
                                             <property name="hibernate.show_sql" value="false"/>
                                             <property name="hibernate.use_sql_comments" value="true"/>
                                             <property name="hibernate.dialect" value="org.hibernate.dialect.OracleDialect"/>
                                             <property name="hibernate.cache.provider_class" value="org.hibernate.cache.HashtableCacheProvider"/>
                                             <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup" />
                                             <property name="jboss.entity.manager.factory.jndi.name" value="java:/EntityManagerFactories/mainUnit"/>
                                          </properties>
                                       </persistence-unit>
                                    </persistence>



                                    components.xml:




                                    <?xml version="1.0" encoding="UTF-8"?>
                                    <components xmlns="http://jboss.com/products/seam/components"
                                                xmlns:core="http://jboss.com/products/seam/core"
                                                xmlns:persistence="http://jboss.com/products/seam/persistence"
                                                xmlns:drools="http://jboss.com/products/seam/drools"
                                                xmlns:bpm="http://jboss.com/products/seam/bpm"
                                                xmlns:security="http://jboss.com/products/seam/security"
                                                xmlns:mail="http://jboss.com/products/seam/mail"
                                                xmlns:web="http://jboss.com/products/seam/web"
                                                xmlns:transaction="http://jboss.com/products/seam/transaction"
                                                xmlns:cache="http://jboss.com/products/seam/cache"
                                                xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                                                xsi:schemaLocation=
                                                        "http://jboss.com/products/seam/core http://jboss.com/products/seam/core-2.1.xsd
                                                     http://jboss.com/products/seam/persistence http://jboss.com/products/seam/persistence-2.1.xsd
                                                     http://jboss.com/products/seam/drools http://jboss.com/products/seam/drools-2.1.xsd
                                                     http://jboss.com/products/seam/bpm http://jboss.com/products/seam/bpm-2.1.xsd
                                                     http://jboss.com/products/seam/security http://jboss.com/products/seam/security-2.1.xsd
                                                     http://jboss.com/products/seam/mail http://jboss.com/products/seam/mail-2.1.xsd
                                                     http://jboss.com/products/seam/web http://jboss.com/products/seam/web-2.1.xsd
                                                     http://jboss.com/products/seam/transaction http://jboss.com/products/seam/transaction-2.1.xsd
                                                     http://jboss.com/products/seam/cache http://jboss.com/products/seam/cache-2.1.xsd
                                                     http://jboss.com/products/seam/components http://jboss.com/products/seam/components-2.1.xsd">
                                    
                                        <core:init debug="@debug@"
                                                   jndi-pattern="@jndiPattern@"
                                                   security-enabled="@seamSecurity@"
                                                />
                                    
                                        <core:manager concurrent-request-timeout="2000"
                                                      conversation-timeout="120000"
                                                      conversation-id-parameter="cid"
                                                      parent-conversation-id-parameter="pid"/>
                                    
                                        <web:hot-deploy-filter url-pattern="*.seam"/>
                                    
                                        <persistence:entity-manager-factory name="entityManagerFactory"
                                                                            persistence-unit-name="mainUnit"/>
                                    
                                        <persistence:managed-persistence-context name="entityManager"
                                                                                 auto-create="true"
                                                                                 persistence-unit-jndi-name="java:/EntityManagerFactories/mainUnit"/>
                                    
                                    
                                        <transaction:ejb-transaction/>
                                    </components>
                                    




                                    1 2 Previous Next