来看下面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"
<!--
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"
<!--
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?
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关闭才闪出一大堆错误
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就行了,这个问题还是蛮奇怪的,忘了我以前是怎么弄的了。
This is impressive poste for a long time i ‘ve ever read. Can i have your contact please? I have somthing to ask over. Spasiba.