Tôi đang sử dụng oracle 11g, hibernate 3 và jsf2.I đã triển khai ứng dụng của tôi trên was7.Every đang hoạt động tốt nhưng khi tôi cố gắng đăng nhập sau 5-6 giờ nó mang lại cho tôi lỗijava.sql.SQLException: Io ngoại lệ: Kết nối thiết lập lại bởi peer: socket write error
ERROR org.hibernate.util.JDBCExceptionReporter - Io exception: Connection reset by peer: socket write error
[5/28/13 11:31:25:048 IST] 00000024 SystemErr R org.hibernate.exception.GenericJDBCException: could not execute query
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:126)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:114)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
at org.hibernate.loader.Loader.doList(Loader.java:2231)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2125)
at org.hibernate.loader.Loader.list(Loader.java:2120)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:401)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:361)
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:196)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1148)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:102)
Tôi không thể tìm ra cách lỗi này để giải quyết.Vui lòng giúp tôi.Cảm ơn trước.
Bây giờ tôi đã giải quyết vấn đề này bằng mã nhưng tôi không biết là nó đúng cách hay không. Bạn đề nghị tôi, tôi nên tiếp tục với giải pháp này trên không.
public class ApplicationUtilityBean implements Serializable {
private SessionFactory sessionFactory;
private AnnotationConfiguration cfg;
public String filePath;
private String realPath = Config.PATH;
public ApplicationUtilityBean() throws URISyntaxException {
getConnection();
}
public void getConnection() {
URL r = this.getClass().getClassLoader().getResource("hibernate.cfg.xml");
cfg = new AnnotationConfiguration();
cfg.configure(r);
String pwd = cfg.getProperty("hibernate.connection.password");
TripleDESEncryption tripledesenc = null;
try {
tripledesenc = new TripleDESEncryption();
} catch (Exception e) {
e.printStackTrace();
}
cfg.setProperty("hibernate.connection.password",
tripledesenc.decrypt(pwd));
sessionFactory = cfg.buildSessionFactory();
System.out.println("cfg: " + cfg);
System.out.println("sessionFactory: " + sessionFactory);
}
public Session getSession() {
System.out.println("Going to get session");
Session session = null;
try {
System.out.println("cfg is: " + cfg);
System.out.println("sessionFactory: " + sessionFactory);
session = sessionFactory.openSession();
if(session != null){
try {
Transaction trxn = session.beginTransaction();
Query queryResult = session.createSQLQuery("select * from dual");
List<GTS_USER>listgtsuser = queryResult.list();
} catch (Exception e) {
e.printStackTrace();
System.out.println("Creating new connection............");
session.close();
sessionFactory.close();
getConnection();
session = sessionFactory.openSession();
}
}
} catch (Exception e) {
e.printStackTrace();
}
return session;
}
}
và tập tin cấu hình Hibernate của tôi là
<hibernate-configuration>
<session-factory>
<property name="hibernate.cache.region.factory_class">net.sf.ehcache.hibernate.EhCacheRegionFactory</property>
<property name="hibernate.cache.use_query_cache">true</property>
<property name="hibernate.cache.use_second_level_cache">true</property>
<property name="hibernate.connection.driver_class">oracle.jdbc.OracleDriver</property>
<property name="hibernate.connection.url">jdbc:oracle:thin:@xxxxxxxxx:1521:HMS</property>
<property name="hibernate.connection.username">xxxxx</property>
<property name="hibernate.connection.password">xxxxxxxxxxx</property>
<property name="hibernate.connection.pool_size">10</property>
<property name="show_sql">true</property>
<property name="dialect">org.hibernate.dialect.OracleDialect</property>
<property name="hibernate.hbm2ddl.auto">update</property>
Bạn có chỉ định tham số cơ sở dữ liệu trong tệp cấu hình ngủ đông hoặc bạn đang sử dụng nguồn dữ liệu được định nghĩa trong was7 và tra cứu bằng JNDI? – gkamal
chỉ định thông số db trong cấu hình ngủ đông chỉ – RaviPancholi