-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: Sorting case unsensitive
PostPosted: Thu Aug 26, 2010 11:49 am 
Newbie

Joined: Thu Aug 26, 2010 11:39 am
Posts: 3
Hi all,
I'm doing a simple SQL query with Hibernate, but if I run it in Windows I get it order like AaBbCc and if I run under Linux I get it ordered like ABCabc. The database is in a linux machine in the two test so it doesn't change.

I'm a bit confused because I thought that the DB was doing the sorting so I didn't expect to found different results, How this could happen?

I'm using Hibernate 3.5 and Oracle 11g.

My simple test:
Code:
String sql = "SELECT * FROM ENGICLIE.T_RT_RTI ORDER BY DESCR_RTI";

Query query = HibernateUtil.getSessionFactory().getCurrentSession().createSQLQuery(sql)
      .addEntity("sc", TRtRti.class);

List list = query.list();

for (int i = 0 ; i<list.size(); i++) {
   TRtRti r = (TRtRti)list.get(i);
   System.out.println(r.getDescrRti());
}


Windows Output:
Code:
AAA_RTI_GLC1
AAA_rti_glc2
AAA_RTI_GLC3
BAL_BLA_BLA
Descrizione rti
eeweqw
GLC_TEST_INS_1
mao mao
rti con spazi
RTI GLC test finale
test GLC 3
TEST GLC 4 mod.2
testRTI


Linux output:
Code:
AAA_RTI_GLC1
AAA_RTI_GLC3
AAA_rti_glc2
BAL_BLA_BLA
Descrizione rti
GLC_TEST_INS_1
RTI GLC test finale
TEST GLC 4 mod.2
eeweqw
mao mao
rti con spazi
test GLC 3
testRTI


Top
 Profile  
 
 Post subject: Re: Sorting case unsensitive
PostPosted: Thu Aug 26, 2010 1:30 pm 
Beginner
Beginner

Joined: Thu Dec 11, 2008 8:18 am
Posts: 35
In database the query executes in same way or in different??


Top
 Profile  
 
 Post subject: Re: Sorting case unsensitive
PostPosted: Fri Aug 27, 2010 4:20 am 
Newbie

Joined: Thu Aug 26, 2010 11:39 am
Posts: 3
Looking through Hibernate log the query seems the same.

But I don't think that the problem is that.
The query is really simple and the problem is the sorting criteria. The only thing that change is that the same code is executed in a windows machine and in a linux one.

I tried to do the same query also with a simple JDBC call and I get the same problem, so the problem isn't Hibernate.

Is it possible that the Java client pass a parameter of the locale of the JVM to Oracle to do the query?
The locale of the Windows machine is it_IT.
The locale of the Linux machine is en_US.


Top
 Profile  
 
 Post subject: Re: Sorting case unsensitive
PostPosted: Fri Aug 27, 2010 4:39 am 
Newbie

Joined: Thu Aug 26, 2010 11:39 am
Posts: 3
BINGO!

Oracle's globalization support enables you to store, process, and retrieve data in native languages. It ensures that database utilities, error messages, sort order, and date, time, monetary, numeric, and calendar conventions automatically adapt to any native language and locale.

For anyone that want go deeper:
http://download.oracle.com/docs/cd/B19306_01/server.102/b14225/ch1overview.htm#NLSPG001

Solution:
Add locale parameter when I start JVM, for example:
-Duser.country=IT -Duser.language=it


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 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.