We modify the configuration file hibernate.cfg.xml
XML Version = '1.0' encoding = 'UTF-8'?>
PUBLIC "- // Hibernate / Hibernate Configuration DTD // EN"
"http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">
session-factory>
Hibernate-Configuration>
Modify Web.xml Add
servlet>
The test servlet is as follows
Package com.test.Web;
Import javax.servlet.servletException;
Import javax.servlet.http.httpservlet;
Import net.sf.hibernate.hibernateException;
Import net.sf.hibelnate.mappingexception;
Import net.sf.hibernate.Session;
Import Net.sf.hibActory;
Import Net.sf.hibiBernate.cfg.configuration;
Import org.apache.log4j.logger;
Import com.yjsoft.hbm.userinfo;
/ **
* @Author yanghx
*
* Change the template for the generated type annotation for the window> Preferences> Java> Code Generation> Code and Notes
* /
Public class testhbmservlet extends httpservlet {
Private static logger log = logger.getlogger;
Public void init () throws servletexception {
Super.init ();
CONFIGURATION CFG = NULL;
SessionFactory sf = NULL;
// SchemaExport Ptemp = NULL;
Session s = null; try {
// cfg = new configuration ();
Cfg = new configuration (). configure ("/ hibernate.cfg.xml);
//cfg.addclass (userinfo.class);
} catch (mappingexception e1) {
E1.PrintStackTrace ();
Log.Error ("Map Error:" E1);
Return;
} catch (hibernateException e) {
// TODO automatically generates a Catch block
E.PrintStackTrace ();
Log.Error ("Map Error:" E);
Return;
}