java - Why is a simple Hibernate findOne() by primary key taking so long? -


i'm splitting off an earlier question eliminate 'select before save' confusion. in example, i'm trying simple findone() primary key. against existing sqlserver db, latest versions of spring boot , spring data.

i have logging set can see sql hibernate has generated. in example, according logging timing, query takes 4 seconds. querying primary key. when run sql hibernate generated in db tool dbvisualizer, returns in sub-second, expect.

i increased hibernate packaging logging trace level, try see delay is, , found following, before , after 4 second delay:

2017-08-14 09:51:35.345 debug 7532 --- [nio-8085-exec-1] org.hibernate.sql                        : select customer0_.customer_id customer1_4_0_, customer0_.first_name first_na2_4_0_, customer0_.last_name last_nam3_4_0_ xbr_customer_tab customer0_ customer0_.customer_id=? hibernate: select customer0_.customer_id customer1_4_0_, customer0_.first_name first_na2_4_0_, customer0_.last_name last_nam3_4_0_ xbr_customer_tab customer0_ customer0_.customer_id=? 2017-08-14 09:51:35.470 trace 7532 --- [nio-8085-exec-1] o.h.r.j.i.resourceregistrystandardimpl   : registering statement [org.apache.tomcat.jdbc.pool.statementfacade$statementproxy[proxy=25287222; query=select customer0_.customer_id customer1_4_0_, customer0_.first_name first_na2_4_0_, customer0_.last_name last_nam3_4_0_ xbr_customer_tab customer0_ customer0_.customer_id=?; delegate=sqlserverpreparedstatement:6]] 2017-08-14 09:51:35.471 trace 7532 --- [nio-8085-exec-1] o.h.e.jdbc.internal.jdbccoordinatorimpl  : registering last query statement [org.apache.tomcat.jdbc.pool.statementfacade$statementproxy[proxy=25287222; query=select customer0_.customer_id customer1_4_0_, customer0_.first_name first_na2_4_0_, customer0_.last_name last_nam3_4_0_ xbr_customer_tab customer0_ customer0_.customer_id=?; delegate=sqlserverpreparedstatement:6]] 2017-08-14 09:51:35.479 trace 7532 --- [nio-8085-exec-1] o.h.type.descriptor.sql.basicbinder      : binding parameter [1] [varchar] - [40666316] 2017-08-14 09:51:35.488 trace 7532 --- [nio-8085-exec-1] o.h.l.p.e.i.abstractloadplanbasedloader  : bound [2] parameters total 2017-08-14 09:51:39.426 trace 7532 --- [nio-8085-exec-1] o.h.r.j.i.resourceregistrystandardimpl   : registering result set [sqlserverresultset:6] 2017-08-14 09:51:39.434 trace 7532 --- [nio-8085-exec-1] o.h.l.p.e.p.i.resultsetprocessorimpl     : processing result set 2017-08-14 09:51:39.434 debug 7532 --- [nio-8085-exec-1] o.h.l.p.e.p.i.resultsetprocessorimpl     : starting resultset row #0 2017-08-14 09:51:39.436 debug 7532 --- [nio-8085-exec-1] l.p.e.p.i.entityreferenceinitializerimpl : on call entityidentifierreaderimpl#resolve, entitykey known; should happen on root returns optional identifier specified 2017-08-14 09:51:39.436 trace 7532 --- [nio-8085-exec-1] l.p.e.p.i.entityreferenceinitializerimpl : hydrating entity state 

i'm wondering why says 2 parameters bound, when there 1 in sql.

any ideas why select taking long? in spring app, , not in client dbvisualizer?

here entity:

import javax.persistence.entity; import javax.persistence.id; import javax.persistence.table;  @entity @table(name = "my_customer_table") public class customer {      @id     private string customer_id;     private string first_name;     private string last_name;      protected customer() {}       public customer(string firstname, string lastname) {         this.first_name = firstname;         this.last_name = lastname;     }  } 

here's customerrepository

import com.....customer; import org.springframework.data.repository.crudrepository;  public interface customerrepository extends crudrepository<customer, string> { } 

and code customer, @service class customerrepository @autowired in:

customer customer = customerrepository.findone(customerid); 

here generated sql:

select customer0_.customer_id customer1_4_0_, customer0_.first_name first_na2_4_0_, customer0_.last_name last_nam3_4_0_ my_customer_table customer0_ customer0_.customer_id=? 

fixed adding following parameter connection string in datasource.

sendstringparametersasunicode=false  

more detail : http://www.jochenhebbrecht.be/site/2014-05-01/java/fixing-slow-queries-running-sql-server-using-jpa-hibernate-and-jtds


Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -