Spring Roo
  1. Spring Roo
  2. ROO-1740

Database reverse engineering cannot handle camelcase columns in MySQL using Hibernate

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Works as Designed
    • Affects Version/s: 1.1.0.RELEASE
    • Fix Version/s: 1.1.1.RELEASE
    • Component/s: None
    • Labels:
      None
    • Environment:
      MySQL 5.1 Ubuntu 10.10

      Description

      When reverse engineering tables with camelcase columns using MySQL and Hibernate, something goes wrong, as the webapp resulting from a 'controller all' results in a mapping exception when running it.

      Steps:

      1. Create a database and add rights
      create database roobug
      grant all privileges on roobug.* to roobug@localhost identified by 'roobug'
      2. Create a table with a camelcase column
      create table camelcasebug(id int primary key, buggyColumn varchar(50));
      3. Startup Roo and create a project
      mkdir roobug
      cd roobug
      roo
      project --topLevelPackage com.buggy.camelcase
      4. Setup persistence
      persistence setup --database MYSQL --provider HIBERNATE --databaseName roobug --userName roobug --password roobug
      5. Reverse engineer
      database reverse engineer --package ~.domain
      6. Create controllers
      controller all --package ~.controller
      7. Exit Roo
      q
      8. Run the application in Tomcat.
      mvn tomcat:run

      The result will be an exception like this:

      org.hibernate.HibernateException: Missing column: buggy_column in roobug.camelcasebug

      When looking at the DbManaged .aj file for that table, the mapping seems correct. Perhaps Roo creates a faulty configuration somewhere?

        Issue Links

          Activity

          Hide
          Alan Stewart added a comment -

          As you say the mapping is correct and DBRE has created legal JPA annotations, but unfortunately Hibernate has a problem so I suggest raise an issue with them. I changed the provider to ECLIPSELINK and OPENJPA and the web app starts up successfully in both. Perhaps a work around may be found by setting the case to lower case when you start MySQL - this article may be of some help: http://dev.mysql.com/doc/refman/5.1/en/identifier-case-sensitivity.html

          Show
          Alan Stewart added a comment - As you say the mapping is correct and DBRE has created legal JPA annotations, but unfortunately Hibernate has a problem so I suggest raise an issue with them. I changed the provider to ECLIPSELINK and OPENJPA and the web app starts up successfully in both. Perhaps a work around may be found by setting the case to lower case when you start MySQL - this article may be of some help: http://dev.mysql.com/doc/refman/5.1/en/identifier-case-sensitivity.html
          Hide
          Lieven Doclo added a comment -

          Sorry, but I disagree. This bug is caused due to the fact that Roo is using the ImprovedNamingStrategy from Hibernate. This naming strategy convert any camelcase entity column (either as the property name or the value in the @Column annotation) to a column with underscores. In the use case of reverse engineering, it is not advisable to use the ImprovedNamingStrategy, mainly due to this fact (it cannot be used in case-sensitive databases such as MySQL with camelcase columns). This is not a Hibernate issue, as the ImprovedNamingStrategy does exactly what it should do.
          In the current default setup, Roo is unable to use any table with Hibernate that contains columns in camelcase (on a case-sensitive filesystem such as Linux and with MySQL, it is also not usable for camelcase tables). When using database reverse engineer, Roo should change the persistence.xml to use the DefaultNamingStrategy.

          Show
          Lieven Doclo added a comment - Sorry, but I disagree. This bug is caused due to the fact that Roo is using the ImprovedNamingStrategy from Hibernate. This naming strategy convert any camelcase entity column (either as the property name or the value in the @Column annotation) to a column with underscores. In the use case of reverse engineering, it is not advisable to use the ImprovedNamingStrategy, mainly due to this fact (it cannot be used in case-sensitive databases such as MySQL with camelcase columns). This is not a Hibernate issue, as the ImprovedNamingStrategy does exactly what it should do. In the current default setup, Roo is unable to use any table with Hibernate that contains columns in camelcase (on a case-sensitive filesystem such as Linux and with MySQL, it is also not usable for camelcase tables). When using database reverse engineer , Roo should change the persistence.xml to use the DefaultNamingStrategy.
          Hide
          Alan Stewart added a comment -

          Changed hibernate.ejb.naming_strategy to org.hibernate.cfg.DefaultNamingStrategy when database reverse engineer command first run.

          Show
          Alan Stewart added a comment - Changed hibernate.ejb.naming_strategy to org.hibernate.cfg.DefaultNamingStrategy when database reverse engineer command first run.
          Hide
          Alan Stewart added a comment -

          Git ID b10704b5f9def6a8e6b7eb59a9c9135a879ba7a4

          Show
          Alan Stewart added a comment - Git ID b10704b5f9def6a8e6b7eb59a9c9135a879ba7a4

            People

            • Assignee:
              Alan Stewart
              Reporter:
              Lieven Doclo
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: