日期:2014-05-17  浏览次数:20675 次

网站没访问几次就无限等待了~
//创建session
public static Session getSession(){
Configuration config = new Configuration().configure();
SessionFactory factory = config.buildSessionFactory();
Session session = factory.openSession();
return session;  
}
//其中一个dao
//增加图片
public boolean addImg(Img img){
Session session = DBUtil.getSession();
Transaction t = session.beginTransaction();
boolean falg = false;
try{
if(img!=null){
falg= true;
session.save(img);
}
t.commit();
}catch(Exception e){
t.rollback();
}finally{
session.close();
}
return falg;
}
//hibernate配置
<hibernate-configuration>
  <session-factory>
  <property name="hibernate.connection.driver_class">com.microsoft.jdbc.sqlserver.SQLServerDriver</property>
  <property name="hibernate.connection.url">jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=skynet</property>
  <property name="hibernate.connection.username">sa</property>
  <property name="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</property>
  <!-- <property name="hibernate.show_sql">true</property> -->
  <mapping resource="com/xml/img.hbm.xml"/>
  </session-factory>
</hibernate-configuration>
没有连接池
tomcat也没有设置任何东西,应该我的程序有问题··谁能帮忙看看,顺便解决下,谢谢~~
··现在用的是SQL数据库,如果用oracle,当V$session这张表记录达到150左右就会报错··是什么原因呢
关于数据库连接的·就上面的代码,别的就没有了··还要加点什么 ,,谁给个指点

------解决方案--------------------
public static Session getSession(){
Configuration config = new Configuration().configure();
SessionFactory factory = config.buildSessionFactory();
Session session = factory.openSession();
return session;
}
这个方法感觉有问题,你把这个方法写成单例模式或是把工厂类的调用放到另一个static中看看
  
你获取了session,在执行sql后关闭了,sessionfactory 还在,然后再执行这个getsession()又创建了个SessionFactory ........