Hibernate Books

All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: How Can I Make Hibernate Mapping Case Insensitive?
PostPosted: Tue Jun 06, 2017 3:00 am 
Newbie

Joined: Tue Jun 06, 2017 2:43 am
Posts: 2
Hi All,

I am using hibernate mapping in a project in Java and I have an error that I cannot figured out. I have several tables that includes column names all in lower case (e.g. db_id). To use them in Java, in my .hbm.xml file I am mapping them with the following line:

Code:
<id name="dbId" type="long" column="DB_ID">


I haven't got any error until now. Even if I use upper case above (column="DB_ID"), mapping was successfull. However, I now get a missing column error when I try to running the project. The error line is like:

Code:
org.hibernate.HibernateException: Missing column: DB_ID in public.x.account
        at org.hibernate.mapping.Table.validateColumns(Table.java:277)


When I change the column name from db_id to DB_ID manually in pgAdmin or Navicat(I am using PostgreSQL), this error disappears and the next column name gives error. I have tens of tables and hundreds of column names. I have also many .hbm.xml files for mapping. (This is a part of a big project.) So I do not want to change all column names manually or change the all column attributes in .hbm.xml files.

What can I do to make it case insensitive?


Top
 Profile  
 
 Post subject: Re: How Can I Make Hibernate Mapping Case Insensitive?
PostPosted: Tue Jun 06, 2017 3:34 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1263
For Hibernate 5.x, you can use a custom physical naming strategy which you provide via the hibernate.physical_naming_strategy configuration property.

What you can do is to come up with your own naming strategy that changes the case of columns:

Code:
public class UpperCaseNamingStrategy extends PhysicalNamingStrategyStandardImpl {
   @Override
   public Identifier toPhysicalColumnName(Identifier name, JdbcEnvironment context) {
      return new Identifier( name.getText().toUpperCase(), name.isQuoted() );
   }
}

_________________
If you liked my answer, you are going to love my High-Performance Java Persistence book and my blog as well.


Top
 Profile  
 
 Post subject: Re: How Can I Make Hibernate Mapping Case Insensitive?
PostPosted: Tue Jun 06, 2017 7:52 am 
Newbie

Joined: Tue Jun 06, 2017 2:43 am
Posts: 2
The problem is solved.

I guess the issue stems from the fact that the language of the operating system or java is not set in English. So I created a setenv.bat file in the apache-tomcat/bin directory and fill it with the following statement

Code:
set JAVA_OPTS=%JAVA_OPTS% -Duser.language=en -Duser.region=US


It is solved with this way. I hope this will be helpful for the people who are experiencing the same issue.


Top
 Profile  
 
 Post subject: Re: How Can I Make Hibernate Mapping Case Insensitive?
PostPosted: Tue Jun 06, 2017 8:48 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1263
I'm glad I could help.

_________________
If you liked my answer, you are going to love my High-Performance Java Persistence book and my blog as well.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.