简体   繁体   English

如何告诉Hibernate注释@Column区分大小写?

[英]How to tell Hibernate annotation @Column to be case-sensitive?

I'm trying to do a simple SELECT query in a table named ECM ( in uppercase ) on a Sybase db with Hibernate. 我正在尝试带有Hibernate的Sybase数据库的名为ECM( 大写 )的表中执行简单的SELECT查询。 I've annotated my DBO this way : 我用这种方式注释了我的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. 但是,我面临“ 找不到表 ”错误:生成的SQL具有小写的表名。 I cannot change the database configuration to tell it to be case-insensitive. 我无法更改数据库配置以告诉它不区分大小写。

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. 然后我的列名和表名被自动引用,但名称仍然是小写的。

Try this: 尝试这个:

Use backticks as in @Table(name="`ECM`")? 使用@Table(name="`ECM`")?反引号@Table(name="`ECM`")?

This must work from Hibernate point. 这必须从Hibernate点开始。 If not then problem should be in DB (if i'm not wrong) 如果不是那么问题应该在DB中(如果我没错)

I think I have your answer: 我想我有你的答案:

Basically, you need to change the naming strategy for you JPA provider. 基本上,您需要更改JPA提供程序的命名策略。 How you do this will depend on how you setup your project. 如何执行此操作取决于您如何设置项目。

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. 如果没有您的更多详细信息,我无法详细说明如何执行此操作。

My goal is a little different since was trying to create tables upper case and hibernate created them in lower case. 我的目标有点不同,因为尝试创建表大写,而hibernate以小写形式创建它们。 Also i was using MySQL not Sybase. 我也使用MySQL而不是Sybase。 But for me quoting the names like this worked: 但对我来说引用这样的名字有用:

@Entity
@Table(name="\"ECM\"")
public class RelationshipDbo {
    ...
}

Then tables were created upper case. 然后将表创建为大写。 Maybe that helps also for the queries. 也许这对查询也有帮助。

What is your Sybase db version ? 您的Sybase db版本是什么? 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. SybaseDialect已在Hibernate 3.5中弃用,然后在Hibernate 4.1之后重构,其中包含一些与不同版本的Sybase匹配的子类。 Have you tried one of the subclasses to see if it makes any difference? 您是否尝试过其中一个子类来查看它是否有任何区别?

  • org.hibernate.dialect.Sybase11Dialect org.hibernate.dialect.Sybase11Dialect
  • org.hibernate.dialect.SybaseAnywhereDialect org.hibernate.dialect.SybaseAnywhereDialect
  • org.hibernate.dialect.SybaseASE15Dialect org.hibernate.dialect.SybaseASE15Dialect

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

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