-->
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: VARCHAR/NVARCHAR mismatch causing poor SQL performance
PostPosted: Thu Jul 05, 2007 1:09 pm 
Newbie

Joined: Mon Feb 20, 2006 9:23 am
Posts: 9
I'm using Hibernate 3.2 SP1 with SQL Server 2000 and JSQLConnect JDBC
Driver.

My underlying SQL tables all have Primary Keys of type VARCHAR(30),
and there are foreign key relationships between the tables too.

In my Hibernate mapping I am declaring <id> elements with a type
of org.hibernate.type.StringType. In my primary and foreign key
mappings I am using column sql-type="varchar(30)".

I am using pure HQL throughout - no raw native SQL queries.

My problem is that I am seeing poor query performance in SQL, and
when I turn on SQL Server profiling the reason is evident. The SQL
queries submitted are using NVARCHAR values rather than VARCHAR
i.e.

select * from Foo f where f.BAR_FK=N'....'

rather than

select * from Foo f where f.BAR_FK='....'

This causes SQL to do index scans rather than seeks because it
believes it needs to convert between VARCHAR and NVARCHAR.

What I'm not sure of is whether the appearance of the N'...' values
is due to something Hibernate is doing, or due to the operation of
the JDBC driver.

Is there anything I can do at the Hibernate level to force the use
of true VARCHAR rather than NVARCHAR string values for PK/FK
columns in the emitted SQL?

Thanks

Alan


Top
 Profile  
 
 Post subject: Re: VARCHAR/NVARCHAR mismatch causing poor SQL performance
PostPosted: Mon Feb 21, 2011 1:11 pm 
Newbie

Joined: Mon Feb 21, 2011 1:09 pm
Posts: 1
Hi Alan,

It has been years since you have reported this but were you able to find a solution for this issue?

Thanks!


Top
 Profile  
 
 Post subject: Re: VARCHAR/NVARCHAR mismatch causing poor SQL performance
PostPosted: Mon Feb 21, 2011 1:41 pm 
Newbie

Joined: Mon Feb 20, 2006 9:23 am
Posts: 9
Alas no - other than dropping down to using stored procs that handle the NVARCHAR->VARCHAR conversion explicitly before executing the required query.


Top
 Profile  
 
 Post subject: Re: VARCHAR/NVARCHAR mismatch causing poor SQL performance
PostPosted: Fri Dec 02, 2011 10:32 am 
Newbie

Joined: Thu Dec 18, 2008 12:45 am
Posts: 4
I meet the same problem.


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.