Bug 219406 - Generate Entities mishandles case-sensitive database table names
Summary: Generate Entities mishandles case-sensitive database table names
Status: RESOLVED FIXED
Alias: None
Product: Dali JPA Tools
Classification: WebTools
Component: Framework (show other bugs)
Version: 1.0.1   Edit
Hardware: All All
: P3 enhancement with 1 vote (vote)
Target Milestone: 2.1 M3   Edit
Assignee: Neil Hauge CLA
QA Contact:
URL:
Whiteboard:
Keywords: helpwanted
Depends on:
Blocks:
 
Reported: 2008-02-19 05:55 EST by Sakari Maaranen CLA
Modified: 2008-11-04 16:23 EST (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Sakari Maaranen CLA 2008-02-19 05:55:59 EST
Build ID: M20071023-1652 (V 3.3.1.1)

Steps To Reproduce:
1. Create a MySQL 5.0 database schema that has lower-case table names. I was using a replica of the JIRA 3.11 database that has tables like "jiraissue", "project" and the like. My schema name is "jiradb311".

2. In Eclipse, use the JPA Development perspective.

3. Create a new Eclipse connection profile in the Data Source Explorer to connect to the database schema. Ensure that the connection is open in Eclipse, before you continue.

4. Create a new or select your existing JPA project.

5. Right click on your project in Eclipse JPA development perspective, and select JPA Tools / Generate Entities... from the context menu.

6. Choose your MySQL database connection and schema, in my example "jiradb311".

7. On the next page select the appropriate package name, in my case com.company.jira.entity, and select some tables to generate entities for. I selected "jiraissue", "project" and several others.

8. When the entity generation completes, it has produced entities named like this: com.company.jira.entity.Jiraissue and com.company.jira.entity.Project. So, the names are capitalized, but there are no @Table annotations to correct this. These classes should have annotations like @Table(name="project") and @Table(name="jiraissue").

9. When you have created all the other things needed for a fully working JPA JAR and deploy it (e.g. in an EAR file) to an application server (Apache Geronimo 2.0.2 in my case), it will create new tables with capitalized names like "Project" and "Jiraissue". It does not map correctly to the existing tables "project" and "jiraissue".

This is combined with the other problem that in my META-INF/orm.xml file the default schema is ignored by Eclipse:
<persistence-unit-metadata>
    <persistence-unit-defaults>
      <schema>jiradb311</schema>
    </persistence-unit-defaults>
  </persistence-unit-metadata>
However, there is already another bug report on this second issue.

I had to write annotations like @Table(name = "project", schema = "jiradb311") in my generated entity classes to get rid of Eclipse errors like:
Schema "root" cannot be resolved for table "Project"

More information:
The automatic entity generation tool produces Java-like class names that have different letter-case from the actual database table names. This is okay, but the tool does not generate any @Table annotations to map the entity POJO class names correctly to the different-case table names.

This problem occurs at least with Eclipse Dali JPA Tools 1.0.1 (EJB 3.0), Apache Geronimo 2.0.2 and MySQL 5.0.
Comment 1 Neil Hauge CLA 2008-03-07 16:32:45 EST
The schema default issue that you mention is fixed in version 1.0.2, which is now available.  Regarding Entity Generation - this is the first issue that has been reported regarding case sensitivity.

It does appear that for your case, and other similar cases that it would be nice to have an option to preserve exact case matching when generating Entities.  I'm not sure that there is a way we could detect that a particular schema is case sensitive, so this option would have to be specified by the user.

I am going to set the severity as enhancement to reflect the nature of the bug.  If anyone is interested in contributing a solution for this, I would be glad to help get you started.  Otherwise we will look at this as a possibility for a future release.



Comment 2 Karen Butzke CLA 2008-11-04 16:23:28 EST
Setting to fixed, Brian's database case-sensitivity work should have fixed this.  Let us know if you are still having problems with MySQL