我的SSH项目之旅(5.提问回复功能)

来看下面 2 张表

插入几条测试数据

insert into item value(1,'JAVASE','1');
insert into item value(2,'JAVAEE','2');

insert into subitem(subname,itemid,subcode) value('IO','1','1');
insert into subitem(subname,itemid,subcode) value('多线程','1','2');
insert into subitem(subname,itemid,subcode) value('socket','1','3');
insert into subitem(subname,itemid,subcode) value('jsp','2','1');
insert into subitem(subname,itemid,subcode) value('servlet','2','2');


public class Item {

private int itemid ;
private String itemname ;
private String itemcode ;
private Set subitems;//item 包含多个subitem
省略 setter getter 方法


}

public class Subitem {
private int subid ;
private String subname ;
private String itemid ;
private String subcode ;
private Item item;// 一个subitem属于一个item
}
Item.hbm.xml
<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <!-- Mapping file autogenerated by MyEclipse - Hibernate Tools --> <hibernate-mapping> <class name="dj.fantlam.myssh.vo.Item" table="item"> <id name="itemid" type="java.lang.Integer"> <column name="itemid" /> <generator class="native"></generator> </id> <property name="itemname" type="java.lang.String"> <column name="itemname" length="50" /> </property> <property name="itemcode" type="java.lang.Integer"> <column name="itemcode" /> </property> <set name="subitems" inverse="true" cascade="all" talbe="subitem" 表示一对多 lazy="false"(默认) order-by="subcode"> <key> <column name="itemid" /> </key> <one-to-many class="dj.fantlam.myssh.vo.Subitem" /> </set> </class> </hibernate-mapping>
  
Subitem.hbm.xml

 

<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <!-- Mapping file autogenerated by MyEclipse - Hibernate Tools --> <hibernate-mapping> <class name="dj.fantlam.myssh.vo.Subitem" table="subitem"> <id name="subid" type="java.lang.Integer"> <column name="subid" /> <generator class="native" /> </id> <many-to-one name="item" class="dj.fantlam.myssh.vo.Item" fetch="select"> <column name="itemid" /> </many-to-one> <property name="subname" type="java.lang.String"> <column name="subname" length="50" /> </property> <property name="subcode" type="java.lang.Integer"> <column name="subcode" /> </property> </class> </hibernate-mapping>


 

2008-07-19 23:14:25,484 WARN [org.hibernate.jdbc.ConnectionManager] - unclosed connection, forgot to call close() on your session?



JDNI 的方式执行 5 次就报错
org.hibernate.exception.GenericJDBCException: Cannot open connection

Caused by: java.util.NoSuchElementException: Timeout waiting for idle object

Caused by: org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot get a connection, pool error Timeout waiting for idle object
JDBC则执行了8次就卡在那里 错误也不显示 等到tomcat关闭才闪出一大堆错误

这到底是怎么回事呢?

log4j 发现了这样的信息
2008-07-20 15:47:04,671 WARN [org.hibernate.jdbc.ConnectionManager] – finalizing with closed connection
感觉就好像执行了一会session没了 connection也没了

我现在有个想法,把项目部署到 linux 环境下运行试试,看是我代码的错误还是环境的问题
Linux 平台就选择 redhat9 因为之前在这个系统上已经配有 JAVA 环境了
测试了一下之后发现不会出现这些问题,但我的 linux 没有 mysql ,所以我真的不知道到底是环境的问题还是别的,在 windows 下我又把 tomcat 给换了,但问题依旧,郁闷中 ….


Mysql 由于以前不知道什么时候装过个源码的,所以现在想卸也麻烦,重新装个 redhat 吧,反正也不很快,从头来一遍。
注意设置上网的时候新建一个连接,用第一个 Bridged, DHCP ,还是不行的话 先建个静态 IP 连一下,然后再用 DHCP 就行了,这个问题还是蛮奇怪的,忘了我以前是怎么弄的了。

设置环境变量
vi .bashrc 针对当前用户


gedit /etc/profile 据说为了安全着想,不推荐此做法


注销一下就行了


ps -ef | grep mysql 验证服务是否启动
rpm -qa | grep MySQL 验证包是否装上


linux 实在没问题,原因是数据库根本就连接不到,现在还不知道原因。
在换个 windows 系统,问题依旧
问题总是存在着,究竟是什么原因呢?

你可能感兴趣的:(tomcat,mysql,Hibernate,linux,ssh)