本番サーバーでしか再現できないという問題があります。スタック トレースは次のとおりです。
Caused by: org.hibernate.exception.JDBCConnectionException: could not execute query
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:74)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.doList(Loader.java:2214)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2095)
at org.hibernate.loader.Loader.list(Loader.java:2090)
at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:289)
at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1695)
at org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:142)
at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:152)
at com.dir.web.beans.clientpartners.dao.DaoClientPartnerImpl.getBrandAssignments(DaoClientPartnerImpl.java:268)
... 46 more
Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
Last packet sent to the server was 0 ms ago.
at sun.reflect.GeneratedConstructorAccessor143.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1074)
at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:3134)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1818)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1961)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2543)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1737)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1888)
at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeQuery(NewProxyPreparedStatement.java:76)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:186)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1778)
at org.hibernate.loader.Loader.doQuery(Loader.java:662)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
at org.hibernate.loader.Loader.doList(Loader.java:2211)
... 53 more
Caused by: java.net.SocketException: Software caused connection abort: socket write error
at java.net.SocketOutputStream.socketWrite0(Native Method)
at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:92)
at java.net.SocketOutputStream.write(SocketOutputStream.java:136)
at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:65)
at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:123)
at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:3119)
... 64 more
例外をスローしているコードを確認できます。
public List<BrandAssignment> getBrandAssignments(String query) throws ClientPartnerException {
Validate.notEmpty(query, "The query cannot be empty or null");
List<BrandAssignment> brandAssignments = null;
try {
brandAssignments = getCurrentSession().createSQLQuery(query).addEntity(BrandAssignment.class).list();
getCurrentSession().close();
} catch (HibernateException hibernateException) {
throw new ClientPartnerException("Error getting brand assignments with query: " + query, hibernateException);
}
return brandAssignments;
}
getCurrentSession メソッドは、基本的にセッション ファクトリに現在のセッションを要求し、誰もトランザクションを開始していない場合はトランザクションを開始します。
これは、Hibernate の構成です。
<property name="c3p0.acquire_increment">1</property>
<property name="c3p0.idle_test_period">5</property>
<property name="c3p0.max_size">100</property>
<property name="c3p0.max_statements">0</property>
<property name="c3p0.min_size">10</property>
<property name="c3p0.timeout">100</property>
<property name="current_session_context_class">thread</property>
<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<!-- Disable the second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
クエリは次のようになります。
SELECT DISTINCT brand_assig.brand_assignment_id, brand_assignment_name, brand_assig.date_created, brand_assig.date_modified, brand_assig.modified_by, brand_assig.client_division_id, brand_assig.business_category, brand_assig.country, brand_assig.region, brand_assig.office_alias, brand_assig.assignment_start_date, brand_assig.assignment_end_date, brand_assig.assignment_status, brand_assig.industry_experience, brand_assig.description, brand_assig.communication_disciplines, brand_assig.client_type
FROM clnt_parent INNER JOIN clnt_partner INNER JOIN clnt_div INNER JOIN brand_assig
ON client_division.client_division_id = brand_assig.client_division_id AND client_partner.client_partner_id = client_division.client_partner_id AND client_parent.client_parent_id = client_partner.client_parent_id
WHERE ( MATCH (client_partner_name) AGAINST ('+nutrition*'IN BOOLEAN MODE) OR MATCH (client_parent_name) AGAINST ('+nutrition*'IN BOOLEAN MODE) OR MATCH (client_division_name) AGAINST ('+nutrition*'IN BOOLEAN MODE) OR MATCH (brand_assignment_name, industry_experience) AGAINST ('+nutrition*'IN BOOLEAN MODE)) AND brand_assig.assignment_end_date IS NOT NULL
ORDER BY client_partner.client_partner_name
問題は、開発環境でエラーを再現して解決策をテストすることができず、構成を確認して問題がないように見えるため、問題の原因がわからないことです。MySqlサーバーのタイムアウト設定を見ると、デフォルトで8時間に設定されています。このエラーは本番環境では頻繁に発生しますが、開発環境では発生しません。エラーの原因を知っている人はいますか?どうすればこれを再現できますか? 可能な解決策はありますか?ありがとう!