测试用的servlet代码如下:
public class TestHBMServlet extends HttpServlet { private static Logger log = Logger.getLogger(TestHBMServlet.class);
public void init() throws ServletException {
super.init();
Configuration cfg = null;
SessionFactory sf = null;
Session s = null;
try {
cfg = new Configuration().configure();
}catch (MappingException e1) {
e1.printStackTrace();
log.error("映射错误:" + e1);
return;
}catch (HibernateException e) {
e.printStackTrace();
log.error("映射错误:" + e);
return;
} try {
sf = cfg.buildSessionFactory();
s = sf.openSession();
}catch (HibernateException e) {
e.printStackTrace();
log.error("Hibernate 错误" + e);
return;
} try {
log.info("Open Session OK");
long start = System.currentTimeMillis();
for (int i = 0; i < 10; i++) {
Userlist message = new Userlist();
message.setId(String.valueOf(i));
message.setUsername(String.valueOf(i));
message.setPassword(String.valueOf(i));
try {
s.save(message);
s.flush();
}
catch (HibernateException e4) {
e4.printStackTrace();
log.error("Hibernate Insert1 错误" + e4);
return;
}
}
long end = System.currentTimeMillis();
log.info(new Long(end - start));
}catch (Exception e) {
e.printStackTrace();
log.error("Hibernate Insert2 错误" + e);
return;
}finally {
try {
s.close();
}catch (HibernateException e4) {
e4.printStackTrace();
log.error("Hibernate Close 错误" + e4);
}
}
}
} }
catch (HibernateException e4) {
e4.printStackTrace();
log.error("Hibernate Insert1 错误" + e4);
return;
}
}
long end = System.currentTimeMillis();
log.info(new Long(end - start));
}catch (Exception e) {
e.printStackTrace();
log.error("Hibernate Insert2 错误" + e);
return;
}finally {
try {
s.close();
}catch (HibernateException e4) {
e4.printStackTrace();
log.error("Hibernate Close 错误" + e4);
}
}
userlist表的结构为:
SQL> desc userlist;
名称 空? 类型
----------------------------------------- -------- ----------------------- USERID NOT NULL VARCHAR2(10)
USERNAME NOT NULL VARCHAR2(20)
PASSWORD NOT NULL VARCHAR2(20)
public class TestHBMServlet extends HttpServlet { private static Logger log = Logger.getLogger(TestHBMServlet.class);
public void init() throws ServletException {
super.init();
Configuration cfg = null;
SessionFactory sf = null;
Session s = null;
try {
cfg = new Configuration().configure();
}catch (MappingException e1) {
e1.printStackTrace();
log.error("映射错误:" + e1);
return;
}catch (HibernateException e) {
e.printStackTrace();
log.error("映射错误:" + e);
return;
} try {
sf = cfg.buildSessionFactory();
s = sf.openSession();
}catch (HibernateException e) {
e.printStackTrace();
log.error("Hibernate 错误" + e);
return;
} try {
log.info("Open Session OK");
long start = System.currentTimeMillis();
for (int i = 0; i < 10; i++) {
Userlist message = new Userlist();
message.setId(String.valueOf(i));
message.setUsername(String.valueOf(i));
message.setPassword(String.valueOf(i));
try {
s.save(message);
s.flush();
}
catch (HibernateException e4) {
e4.printStackTrace();
log.error("Hibernate Insert1 错误" + e4);
return;
}
}
long end = System.currentTimeMillis();
log.info(new Long(end - start));
}catch (Exception e) {
e.printStackTrace();
log.error("Hibernate Insert2 错误" + e);
return;
}finally {
try {
s.close();
}catch (HibernateException e4) {
e4.printStackTrace();
log.error("Hibernate Close 错误" + e4);
}
}
}
} }
catch (HibernateException e4) {
e4.printStackTrace();
log.error("Hibernate Insert1 错误" + e4);
return;
}
}
long end = System.currentTimeMillis();
log.info(new Long(end - start));
}catch (Exception e) {
e.printStackTrace();
log.error("Hibernate Insert2 错误" + e);
return;
}finally {
try {
s.close();
}catch (HibernateException e4) {
e4.printStackTrace();
log.error("Hibernate Close 错误" + e4);
}
}
userlist表的结构为:
SQL> desc userlist;
名称 空? 类型
----------------------------------------- -------- ----------------------- USERID NOT NULL VARCHAR2(10)
USERNAME NOT NULL VARCHAR2(20)
PASSWORD NOT NULL VARCHAR2(20)
解决方案 »
- struts2中得到jsp页面中radio标签的value值的问题。
- Java是不是主要采用重写@Override方法来实现回调?感觉限制很大
- 编写一个SQL语句
- 懂MySql的来 !
- 多线程的问题
- 一个关于SPRING的singleton问题
- 新人求答案~~谢谢啊~~急用~~
- Spring+Hibernate+Dwr里出错:Write operations are not allowed in read-only mode (FlushMode.NEVER/MANUAL):
- spring+hibernate + jsp 中lib库中需要导入别的包?
- 怎样用jbuilder2005来启动Tomcat来编译struts项目?
- 请教关于在eclipse中Tomcat的配置问题
- ant问题
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="struts.hibernate.Userlist" schema="HYH" table="USERLIST">
<id column="USERID" length="10" name="id" type="string">
<generator class="uuid.hex"/>
</id>
<property column="USERNAME" length="20" name="username" not-null="true" type="string"/>
<property column="PASSWORD" length="20" name="password" not-null="true" type="string"/>
</class>
</hibernate-mapping>
还想请教一下<generator class="uuid.hex"/>与<generator class="assigned"/>的区别,什么时候用到哪一种?马上给分!