Java 如何告诉 Hibernate 注释 @Column 区分大小写?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22505624/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to tell Hibernate annotation @Column to be case-sensitive?
提问by Deathtiny
I'm trying to do a simple SELECT query in a table named ECM (in uppercase) on a Sybase db with Hibernate. I've annotated my DBO this way :
我正在尝试在带有 Hibernate 的 Sybase 数据库上的名为 ECM(大写)的表中执行简单的 SELECT 查询。我以这种方式注释了我的 DBO:
@Entity
@Table(name="ECM")
public class RelationshipDbo {
...
}
However, I'm facing a "table not found" error : the generated SQL has the table name in lowercase. I cannot change the database configuration to tell it to be case-insensitive.
但是,我遇到了“找不到表”错误:生成的 SQL 的表名是小写的。我无法更改数据库配置以告诉它不区分大小写。
I've also tried putting quotes like this :
我也试过这样引用:
@Table(name="`ECM`")
and this :
和这个 :
@Table(name="'ECM'")
Result : the quotes are added in the query, but the table name is still converted from uppercase to lowercase.
结果:查询中添加了引号,但表名仍然从大写转换为小写。
Technical information :
技术信息 :
Hibernate 4.3
JPA 1.2
org.hibernate.dialect.SybaseDialect
Have you guys any idea?
你们有什么想法吗?
EDIT:Also tried this Hibernate changes @Table(name) to lowercase
编辑:也试过这个Hibernate 将 @Table(name) 更改为小写
Then my columns names and table name are automatically quoted, but the names still get lowercased.
然后我的列名和表名被自动引用,但名称仍然小写。
回答by Balaji Reddy
Try this:
尝试这个:
Use backticks as in @Table(name="`ECM`")?
使用反引号 @Table(name="`ECM`")?
This must work from Hibernate point. If not then problem should be in DB (if i'm not wrong)
这必须从休眠点开始工作。如果不是,那么问题应该出在数据库中(如果我没有错的话)
回答by Julien
What is your Sybase db version ?
SybaseDialect
has been deprecated in Hibernate 3.5 and then refactored since Hibernate 4.1 with a bunch of subclasses matching different versions of Sybase. Have you tried one of the subclasses to see if it makes any difference?
你的 Sybase 数据库版本是什么?
SybaseDialect
在 Hibernate 3.5 中已被弃用,然后从 Hibernate 4.1 开始重构,其中包含一堆匹配不同 Sybase 版本的子类。您是否尝试过其中一个子类,看看它是否有什么不同?
- org.hibernate.dialect.Sybase11Dialect
- org.hibernate.dialect.SybaseAnywhereDialect
- org.hibernate.dialect.SybaseASE15Dialect
- org.hibernate.dialect.Sybase11Dialect
- org.hibernate.dialect.SybaseAnywhereDialect
- org.hibernate.dialect.SybaseASE15Dialect
回答by Christian Bongiorno
I think I have your answer:
我想我有你的答案:
Basically, you need to change the naming strategy for you JPA provider. How you do this will depend on how you setup your project.
基本上,您需要更改 JPA 提供程序的命名策略。你如何做到这一点取决于你如何设置你的项目。
In my case, using spring boot data I set a property in my application.properties to
就我而言,使用 Spring Boot 数据,我在 application.properties 中设置了一个属性
spring.jpa.hibernate.naming-strategy=org.hibernate.cfg.EJB3NamingStrategy
Without more details from you I can't give more specifics on how to do this.
如果没有您提供的更多详细信息,我无法提供有关如何执行此操作的更多细节。
回答by CannedMoose
My goal is a little different since was trying to create tables upper case and hibernate created them in lower case. Also i was using MySQL not Sybase. But for me quoting the names like this worked:
我的目标有点不同,因为我试图创建大写的表格,而 hibernate 以小写的形式创建它们。另外我使用的是 MySQL 而不是 Sybase。但对我来说,引用这样的名字是有效的:
@Entity
@Table(name="\"ECM\"")
public class RelationshipDbo {
...
}
Then tables were created upper case. Maybe that helps also for the queries.
然后表被创建大写。也许这也有助于查询。