public User getUserOnlyByUserName(String username) {
LOGGER.info(" into getUserByIdJOIN ServiceImpl in UserDao------>>>>>>");
Session session = sessionFactory.openSession();
Criteria criteria = session.createCriteria(User.class);
criteria.add(Restrictions.eq(USERNAME, username));
Object obj = criteria.uniqueResult();
if(obj==null){
return null;
}
session.close();
LOGGER.info(" out of getUserByIdJOIN ServiceImpl in UserDao------>>>>>>");
return (User) obj;
}
197在(dbname)
上连接root @ localhost相同的mysql日志如下所示
197在itaf4上连接root @ localhost 197查询/ * mysql-connector-java-5.1.42(修订版: 1f61b0b0270d9844b006572ba4e77f19c0f230d4)* / *** SELECT @@ session.auto_increment_increment AS auto_increment_increment, @@ character_set_client AS character_set_client, @@ character_set_connection AS character_set_connection, @@ character_set_results AS character_set_results, @@ character_set_server AS character_set_server,@@ init_connect AS init_connect,@ @ interactive_timeout AS interactive_timeout,@@ license AS许可证,@@ lower_case_table_names AS lower_case_table_names, @@ max_allowed_packet AS max_allowed_packet,@@ net_buffer_length AS net_buffer_length,@@ net_write_timeout AS net_write_timeout, @@ query_cache_size AS query_cache_size,@@ query_cache_type AS query_cache_type,@@ sql_mode AS sql_mode,@@ system_time_zone AS system_time_zone,@@ time_zone AS time_zone,@@ tx_isolation AS tx_isolation,@@ wait_timeout AS wait_timeout 197查询SET NAMES latin1 197查询SET character_set_results = NULL 197查询SET autocommit = 1 197查询SET sql_mode =' STRICT_TRANS_TABLES'
197查询选择this_.user_id为user_id1_3_0_,this_.accountNonExpired为accountN2_3_0_,this_.accountNonLocked as accountN3_3_0_,this_.attempts为attempts4_3_0_, this_.credentialsNonExpired为credenti5_3_0_,this_.enabled as enabled6_3_0_,this_.firstname as firstnam7_3_0_,this_.lastAttempt as lastAtte8_3_0_,this_.lastname为lastname9_3_0_,this_.password为 passwor10_3_0_,this_.roleId as roleId12_3_0_,this_.username as usernam11_3_0_来自用户this_ where this_.username =' demo_admin' 197查询显示警告 197退出**
答案 0 :(得分:1)
Hibernate不执行这些SQL语句。 MySQL驱动程序为您执行它们。
如果您想知道Hibernate生成什么语句,那么您应该配置datasource-proxy
或p6spy
as explained in this article。这样,您就可以确定应用程序显式生成了哪些JDBC语句。
在您的情况下,初始化数据库连接时将执行所有这些语句。您可以调试MySQL Connector / J驱动程序并亲自查看。
如果您多次看到这些日志,则表示您不重用连接,即bad for performance and system scalability。配置连接池解决方案后,请确保同时使用FlexyPool,以便了解其下发生的情况。