简体   繁体   English

JPA 2.0和MySQL不遵守区分大小写的表名

[英]JPA 2.0 & MySQL are not respecting case sensitive table names


I have a strange issue my ear project: I have put the correct annotations on my entity class: 我的耳朵项目遇到一个奇怪的问题:我在实体类上放置了正确的注释:

@Entity
@Table(name = "PRODUCTS")

But when I deploy my application on glassfish 3.1.2.2, I find that JPA has created the tables with lowercase chars 但是,当我在glassfish 3.1.2.2上部署应用程序时,我发现JPA用小写字符创建了表。

I am using EclipseLink 2.4.1 我正在使用EclipseLink 2.4.1

Please Help me. 请帮我。

I got the solution from Brian Vosburgh's comment: In the windows version of MySQL the names of table are set to lower case. 我从Brian Vosburgh的评论中得到了解决方案:在Windows版本的MySQL中,表的名称设置为小写。 On linux, by default, this configuration is disabled, and the tables'names set by JPA are applied to MySQL without modification. 在Linux上,默认情况下,此配置为禁用状态,并且JPA设置的表名无需修改即可应用于MySQL。

To make it working on windows as like linux, add the line: 要使其像linux一样在Windows上运行,请添加以下行:

lower_case_table_names=0

Thank you for your help, specially Brian Vosburgh 谢谢您的帮助,特别是Brian Vosburgh

I found a property the makes all the difference. 我找到了一个属性,使一切都变得不同。 In the EclipseLink wizard (generate entities from tables), third page (Customize Defaults), I checked the "Always generate optional JPA annotations and DDL parameters" option. 在EclipseLink向导(从表生成实体)的第三页(自定义默认值)中,我选中了“始终生成可选的JPA批注和DDL参数”选项。 This option writes the below annotation in the Entity class: 此选项将以下注释写入Entity类:

@Table(name="TableName")

The correct table name letter case will be used. 将使用正确的表名字母大小写。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM