5

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 :

@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.

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

Then my columns names and table name are automatically quoted, but the names still get lowercased.

Community
  • 1
  • 1
Deathtiny
  • 728
  • 3
  • 8
  • 14

4 Answers4

3

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:

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

Then tables were created upper case. Maybe that helps also for the queries.

CannedMoose
  • 509
  • 1
  • 10
  • 18
  • Seems ugly but actually works. However, best option would be to change Hibernate's naming strategy, @see https://stackoverflow.com/a/39194169/956727 – abarre Oct 26 '17 at 08:37
1

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.

In my case, using spring boot data I set a property in my application.properties to

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.

Christian Bongiorno
  • 5,150
  • 3
  • 38
  • 76
0

Try this:

Use backticks as in @Table(name="`ECM`")?

This must work from Hibernate point. If not then problem should be in DB (if i'm not wrong)

Lukas Eder
  • 211,314
  • 129
  • 689
  • 1,509
Balaji Reddy
  • 5,576
  • 3
  • 36
  • 47
  • 2
    Already tested it, and unsuccessful, as stated in my post. Problem is that, even quoted, the ECM letter get lowercased for some reason. – Deathtiny Mar 19 '14 at 13:10
0

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?

  • org.hibernate.dialect.Sybase11Dialect
  • org.hibernate.dialect.SybaseAnywhereDialect
  • org.hibernate.dialect.SybaseASE15Dialect
Julien
  • 1,087
  • 7
  • 15
  • Thanks, tried the three possible dialects, but the generated SQL stays the same: always my table name lowercased.. – Deathtiny Mar 19 '14 at 13:11
  • Strange. I ran a quick test by switching to SybaseDialect in an existing project (using an H2 in-mem db) and the case in my SQL output is correct.. The main difference I see in my config is that I'm using JPA 2.1. not sure if this makes a difference. – Julien Mar 19 '14 at 13:19