Cat c;
c = new Cat();
csetName(name);
hsessionsave(c);
hsessionflush();
txcommit();
HibernateUtilcloseSession();
outprintln(Done);
}
%>
Add New Cats:<br>
<form method=post action=addCatjsp>
Name:<input name=name><br>
<input type=submit name=Go value=Add><br>
</form>
</body>
</html>
第六个文件 getCatsjsp
<%@ page contentType=
text/html; charset=GB
%>
<%@ page import=hb* netsfhibernate*
javautil* %>
<html>
<head>
<title>Hibernate Test</title>
</head>
<body bgcolor=#ffffff]
<h>Test Hibernate</h>
<a href=addCatjsp>Add Cat<br>
<p> ID Name </p>
<%
SessionFactory sessionFactory;
netsfhibernateSession hsession;
hsession = HibernateUtilcurrentSession();
Transaction tx = hsessionbeginTransaction();
Query query = hsessioncreateQuery (select cat from Cat as cat );
for (Iterator it = queryiterate(); ithasNext();) {
Cat cat = (Cat) itnext();
outprintln(catgetId()+ + catgetName() + <br>);
}
txcommit();
HibernateUtilcloseSession();
outprintln(Done);
%>
</body>
</html>
说明
对HibernateUtiljava的编译
javac classpath /lib/hibernatejar HibernateUtiljava
有个警告可以忽略之
[] [] [] []