首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

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

2012-10-31 
我的SSH项目之旅(5.提问回复功能)来看下面2张表插入几条测试数据 insert into item value(1,JAVASE,1)

我的SSH项目之旅(5.提问回复功能)
来看下面2张表小弟我的SSH项目之旅(5.提问回复功能)

插入几条测试数据

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');
小弟我的SSH项目之旅(5.提问回复功能)

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 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 /> </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 /> </id> <many-to-one name="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就行了,这个问题还是蛮奇怪的,忘了我以前是怎么弄的了。
小弟我的SSH项目之旅(5.提问回复功能)
设置环境变量
vi .bashrc 针对当前用户


小弟我的SSH项目之旅(5.提问回复功能)gedit /etc/profile 据说为了安全着想,不推荐此做法

小弟我的SSH项目之旅(5.提问回复功能)
注销一下就行了小弟我的SSH项目之旅(5.提问回复功能)

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

小弟我的SSH项目之旅(5.提问回复功能)
在linux实在没问题,原因是数据库根本就连接不到,现在还不知道原因。
在换个windows系统,问题依旧
问题总是存在着,究竟是什么原因呢?

热点排行