9 Replies Latest reply on Mar 9, 2012 7:28 AM by vitorrm

    Jboss AS 6.1.0 + JPA + Hibernate - Case Sensitive problem

    vitorrm

      Good morning,

       

      I am trying to migrate from Jboss AS version 5.1 to 6.1 and I am having this strange issue. I´ll aprecciate if someone help me.

       

      I´ve this class:

       

      @Entity

      @Table(name = "TESTE_JBOSS")

      public class Teste implements Serializable {

           ...

      }

       

      And I´ve the table TESTE_JBOSS in my database SQL SERVER 2008 R2 with collation Latin1_General_BIN. Note that both the table names are in uppercase.


      When I put the server (JbossAS 6.1.0) up everything seems ok, but when I tried to use the application I got the error:

       

      ...

      Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: Invalid object name 'teste_jboss'.

      ...

       

      When I change the table name in database to lowercase things work, but I can´t change all the table and column names to lowercase.

       

      I tried to change the persistence.xml, the version of hibernate to 3.6.7, the datasource, the jdbc driver. But anything worked.

      I run this exactly same application in JbossAS 6.0 Final and it worked fine. I don´t know if there is some configuration or if is a bug of JbossAS 6.1.0.

       

      Sorry about my english.

       

      Someone have any idea?

       

      Thks

        • 1. Re: Jboss AS 6.1.0 + JPA + Hibernate - Case Sensitive problem
          wolfgangknauf

          So, the error does not happen at deploy time, only at runtime when accessing the Entity bean? Is the table automatically created at deploy time, or does it already exist?

           

          If it is happening at runtime: could you add this switch to your "persistence.xml" and check the sql statements found in the server log?

           

           

          {code:xml}

                    <persistence-unit name="...">                <jta-data-source>...</jta-data-source>                <properties>                     ...                     <!-- Activate SQL-Logging-->                     <property name="hibernate.show_sql" value="true"></property>                </properties>           </persistence-unit>

          {code}

           

          Best regards

           

          Wolfgang

          • 2. Re: Jboss AS 6.1.0 + JPA + Hibernate - Case Sensitive problem
            vitorrm

            Hi

             

            The table already exist in the SQL SERVER.

             

            I enabled the log and the stack trace before the error is

             


             

            13:47:04,605 INFO  [org.hibernate.validator.engine.resolver.DefaultTraversableResolver] Instantiated an instance of org.hibernate.validator.engine.resolver.JPATraversableResolver.
            13:47:04,609 INFO  [org.hibernate.cfg.search.HibernateSearchEventListenerRegister] Unable to find org.hibernate.search.event.FullTextIndexEventListener on the classpath. Hibernate Search is not enabled.
            13:47:04,613 INFO  [org.hibernate.util.NamingHelper] JNDI InitialContext properties:{}
            13:47:04,614 INFO  [org.hibernate.connection.DatasourceConnectionProvider] Using datasource: java:jdbc/DATASOURCE_TESTE
            13:47:04,617 INFO  [org.hibernate.dialect.Dialect] Using dialect: org.hibernate.dialect.SQLServer2008Dialect
            13:47:04,617 INFO  [org.hibernate.cfg.SettingsFactory] Database ->
                   name : Microsoft SQL Server
                version : 10.50.1617
                  major : 10
                  minor : 50
            13:47:04,618 INFO  [org.hibernate.cfg.SettingsFactory] Driver ->
                   name : Microsoft JDBC Driver 4.0 for SQL Server
                version : 4.0.1427.2
                  major : 4
                  minor : 0
            13:47:04,618 INFO  [org.hibernate.transaction.TransactionFactoryFactory] Using default transaction strategy (direct JDBC transactions)
            13:47:04,618 INFO  [org.hibernate.transaction.TransactionManagerLookupFactory] No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
            13:47:04,618 INFO  [org.hibernate.cfg.SettingsFactory] Automatic flush during beforeCompletion(): disabled
            13:47:04,618 INFO  [org.hibernate.cfg.SettingsFactory] Automatic session close at end of transaction: disabled
            13:47:04,618 INFO  [org.hibernate.cfg.SettingsFactory] Scrollable result sets: enabled
            13:47:04,618 INFO  [org.hibernate.cfg.SettingsFactory] JDBC3 getGeneratedKeys(): enabled
            13:47:04,618 INFO  [org.hibernate.cfg.SettingsFactory] Connection release mode: auto
            13:47:04,618 INFO  [org.hibernate.cfg.SettingsFactory] Default batch fetch size: 1
            13:47:04,618 INFO  [org.hibernate.cfg.SettingsFactory] Generate SQL with comments: disabled
            13:47:04,618 INFO  [org.hibernate.cfg.SettingsFactory] Order SQL updates by primary key: disabled
            13:47:04,618 INFO  [org.hibernate.cfg.SettingsFactory] Order SQL inserts for batching: disabled
            13:47:04,619 INFO  [org.hibernate.cfg.SettingsFactory] Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
            13:47:04,619 INFO  [org.hibernate.hql.ast.ASTQueryTranslatorFactory] Using ASTQueryTranslatorFactory
            13:47:04,619 INFO  [org.hibernate.cfg.SettingsFactory] Query language substitutions: {}
            13:47:04,620 INFO  [org.hibernate.cfg.SettingsFactory] JPA-QL strict compliance: enabled
            13:47:04,620 INFO  [org.hibernate.cfg.SettingsFactory] Second-level cache: enabled
            13:47:04,620 INFO  [org.hibernate.cfg.SettingsFactory] Query cache: disabled
            13:47:04,620 INFO  [org.hibernate.cfg.SettingsFactory] Cache region factory : org.hibernate.cache.impl.NoCachingRegionFactory
            13:47:04,624 INFO  [org.hibernate.cfg.SettingsFactory] Optimize cache for minimal puts: disabled
            13:47:04,624 INFO  [org.hibernate.cfg.SettingsFactory] Structured second-level cache entries: disabled
            13:47:04,624 INFO  [org.hibernate.cfg.SettingsFactory] Statistics: disabled
            13:47:04,624 INFO  [org.hibernate.cfg.SettingsFactory] Deleted entity synthetic identifier rollback: disabled
            13:47:04,624 INFO  [org.hibernate.cfg.SettingsFactory] Default entity-mode: pojo
            13:47:04,624 INFO  [org.hibernate.cfg.SettingsFactory] Named query checking : enabled
            13:47:04,624 INFO  [org.hibernate.cfg.SettingsFactory] Check Nullability in Core (should be disabled when Bean Validation is on): disabled
            13:47:04,640 INFO  [org.hibernate.impl.SessionFactoryImpl] building session factory
            13:47:04,641 INFO  [org.hibernate.type.BasicTypeRegistry] Type registration [materialized_blob] overrides previous : org.hibernate.type.MaterializedBlobType@15dd9c
            13:47:04,641 INFO  [org.hibernate.type.BasicTypeRegistry] Type registration [clob] overrides previous : org.hibernate.type.ClobType@1883817
            13:47:04,641 INFO  [org.hibernate.type.BasicTypeRegistry] Type registration [java.sql.Clob] overrides previous : org.hibernate.type.ClobType@1883817
            13:47:04,641 INFO  [org.hibernate.type.BasicTypeRegistry] Type registration [wrapper_materialized_blob] overrides previous : org.hibernate.type.WrappedMaterializedBlobType@1aaa49
            13:47:04,641 INFO  [org.hibernate.type.BasicTypeRegistry] Type registration [characters_clob] overrides previous : org.hibernate.type.PrimitiveCharacterArrayClobType@a1c086
            13:47:04,641 INFO  [org.hibernate.type.BasicTypeRegistry] Type registration [materialized_clob] overrides previous : org.hibernate.type.MaterializedClobType@166d107
            13:47:04,641 INFO  [org.hibernate.type.BasicTypeRegistry] Type registration [wrapper_characters_clob] overrides previous : org.hibernate.type.CharacterArrayClobType@1253efb
            13:47:04,641 INFO  [org.hibernate.type.BasicTypeRegistry] Type registration [blob] overrides previous : org.hibernate.type.BlobType@49f120
            13:47:04,641 INFO  [org.hibernate.type.BasicTypeRegistry] Type registration [java.sql.Blob] overrides previous : org.hibernate.type.BlobType@49f120
            13:47:04,692 INFO  [org.hibernate.impl.SessionFactoryObjectFactory] Not binding factory to JNDI, no JNDI name configured
            13:47:04,869 WARN  [org.hibernate.util.JDBCExceptionReporter] SQL Error: 208, SQLState: S0002
            13:47:04,869 ERROR [org.hibernate.util.JDBCExceptionReporter] Invalid object name 'teste_jboss'.
            
            

             

            my persistence.xml looks like

             

             

            <?xml version="1.0" encoding="UTF-8"?>
            <persistence version="2.0" 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_2_0.xsd">
            
                      <persistence-unit name="testeUnit" transaction-type="RESOURCE_LOCAL">
                                <non-jta-data-source>java:jdbc/DATASOURCE_TESTE</non-jta-data-source>
                                <class>com.empresa.Teste</class>
                                <exclude-unlisted-classes>true</exclude-unlisted-classes>
                                <properties>
                                          <property name="hibernate.dialect" value="org.hibernate.dialect.SQLServer2008Dialect"/>
                                          <property name="hibernate.show_sql" value="true" />
                                </properties>
                      </persistence-unit>
            </persistence>
            
            

             

            tks for reply

            • 3. Re: Jboss AS 6.1.0 + JPA + Hibernate - Case Sensitive problem
              wolfgangknauf

              Maybe it is a matter of SQLServer configuration - seems that it can be configured to use case sensitive table names: http://weblogs.sqlteam.com/mladenp/archive/2006/12/07/44176.aspx

               

              Could you check this?

               

              Best regards

               

              Wolfgang

              • 4. Re: Jboss AS 6.1.0 + JPA + Hibernate - Case Sensitive problem
                vitorrm

                My database is using collation Latin1_General_BIN - Case Sensitive. Unfortunately, change the collation is not an alternative to me.

                 

                In the annotation @Table(name = "TESTE_JBOSS") I defined the table name in uppercase and this works in JbossAS 5.1 and JbossAS 6.0. Why don´t works in JbossAS 6.1?

                 

                If you note JPA/Hibernate is ignoring the uppercase of the annotation and trying to find the table with lowercase name.

                 

                Best regards

                 

                Vitor R Munhoz

                • 5. Re: Jboss AS 6.1.0 + JPA + Hibernate - Case Sensitive problem
                  wolfgangknauf

                  Hi,

                   

                  sorry, I don't know the Hibernate code good enough. I see that the SQL server dialects use case insensitive string comparisons: http://docs.jboss.org/hibernate/core/3.6/javadocs/org/hibernate/dialect/SQLServerDialect.html - there is a method "areStringComparisonsCaseInsensitive" which returns "true" always. But I don't  know whether this is used also for table name case mapping.

                   

                  You might try to find more help in hibernate forums: https://forum.hibernate.org/

                   

                  Best regards

                   

                  Wolfgang

                  • 6. Re: Jboss AS 6.1.0 + JPA + Hibernate - Case Sensitive problem
                    vitorrm

                    I opened a discussion in Hibernate forum https://forum.hibernate.org/viewtopic.php?f=1&t=1012617

                     

                    But I am using the same version of hibernate in Jboss 6.0 and Jboss 6.1 and on the 6.0 works. I wonder what has changed from one to another that causes this issue. I looked the changes in Jira but I didn't find anything relevant for my problem.

                     

                    Wolfgang, Thks for trying help

                     

                    Vitor

                    • 7. Re: Jboss AS 6.1.0 + JPA + Hibernate - Case Sensitive problem
                      vitorrm

                      Hi,

                       

                      I ´ve not found the solution yet and I found the same behavior on JbossAS 7.0.x + JPA 2.0 + Hibernate 4.0.0.CR2.

                       

                      How can I debug to know what´s going on?

                       

                      Vitor

                      • 8. Re: Jboss AS 6.1.0 + JPA + Hibernate - Case Sensitive problem

                        I see same issues with JBoss 7.1.0 Final + Hibernate 4.0.1 too

                        • 9. Re: Jboss AS 6.1.0 + JPA + Hibernate - Case Sensitive problem
                          vitorrm

                          Good morning,

                           

                          It seems to be a hibernate problem.

                           

                          I´ve solved the problem changing the hibernate version in Jboss 6.1 to version 3.6.7 and I removed the version that was there before.