-->
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.  [ 3 posts ] 
Author Message
 Post subject: oracle + hibernate chcaracter encoding
PostPosted: Tue Aug 23, 2005 8:12 am 
Newbie

Joined: Wed May 11, 2005 5:39 am
Posts: 9
Hi all
Hibernate version: 3

Mapping documents:
<hibernate-configuration>
<session-factory>
<property name="show_sql">true</property>

<property name="dialect">org.hibernate.dialect.Oracle9Dialect</property>
<property name="connection.driver_class">oracle.jdbc.OracleDriver</property>
<property name="hibernate.connection.url">jdbc:oracle:thin:@192.168.1.5:1521:citytran</property>
<property name="hibernate.connection.username">dbo</property>
<property name="hibernate.connection.password">111</property>

<property name="c3p0.max_size">2</property>
<property name="c3p0.min_size">0</property>
<property name="c3p0.timeout">10</property>
<property name="c3p0.max_statements">50</property>
<property name="c3p0.idle_test_period">3000</property>
<property name="c3p0.acquireRetryAttempts">1</property>

<property name="jdbc.batch_size">0</property>

<property name="jdbc.batch_versioned_data">false</property>

<property name="jdbc.use_streams_for_binary">true</property>

<property name="max_fetch_depth">1</property>

<mapping resource="User.hbm.xml"/>
.....
</session-factory>
</hibernate-configuration>

And test object mapping

<hibernate-mapping>
<class name="User" table="USERS" dynamic-update="true" >
<id name="id" unsaved-value="null" type="long" column="userid" >
<generator class="sequence">
<param name="sequence">SQ_USERS</param>
</generator>
</id>
<property name="username" type="string" column="USERRESUME" />
...
</class>
</hibernate-mapping>

Name and version of the database you are using:
Oracle 9.2
CREATE TABLE USERS (
USERID NUMBER (10) NOT NULL,
USERNAME VARCHAR2 (50) NOT NULL,
.....

And the problem:
If i try to get list of users with condition like this
Code:
       String username = "Гр..ор..";
       List list = ses.createQuery("from User u where u.username = '" + username + "'").list();


i get the following log:
The generated SQL (show_sql=true):
....
14:42:04,850 WARN Configurator:126 - No configuration found. Configuring ehcache from ehcache-failsafe.xml found in the classpath: jar:file:/D:/ScarPro/libs/Hibernate3/ehcache-1.1.jar!/ehcache-failsafe.xml
14:42:05,615 INFO SessionFactoryObjectFactory:82 - Not binding factory to JNDI, no JNDI name configured
14:42:05,615 INFO SessionFactoryImpl:379 - Checking 0 named queries
Hibernate: select user0_.userid as userid, user0_.USERRESUME as USERRESUME0_ from DBO.USERS user0_ where user0_.USERRESUME='??????'

questions signs instead user name.

And if i do the same without hibernate:
Code:
            Class.forName("oracle.jdbc.OracleDriver");
            Connection con = DriverManager.getConnection("jdbc:oracle:thin:@192.168.1.5:1521:citytran", "dbo", "111");
            Statement statement = con.createStatement();
            ResultSet resultSet = statement.executeQuery("select * from USERS where USERNAME='Гр..ор..'");
            if(resultSet.next()) {
                System.out.println(resultSet.getString("username"));
            }

it works.

Why hibernate convert string encoding?
Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 23, 2005 8:23 am 
Expert
Expert

Joined: Thu Dec 04, 2003 12:36 pm
Posts: 275
Location: Bielefeld, Germany
Try it again using named parameters (Query.setXXX):

Code:
String username = "Гр..ор..";
Query query = ses.createQuery("from User u where u.username = :username");
query.setString("username", username);
List list = query.list();


Best regards
Sven

_________________
Please don't forget to give credit, if this posting helped to solve your problem.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 23, 2005 8:47 am 
Newbie

Joined: Wed May 11, 2005 5:39 am
Posts: 9
Thanks, it works. (1 credit)

Most interesting is that i always used this approach (setting named parameter), but this time i decided to concatenate query with condition, why don't know ;) maybe laziness ;)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.