我做了个登录的例子
可总是报错 郁闷啊
我的HibernateUtil文件package Login.hibernate;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2007</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.io.File;import org.hibernate.Transaction;
public class HibernateUtil { private static Log log = LogFactory.getLog(HibernateUtil.class); private static final SessionFactory sessionFactory;
public static final ThreadLocal session = new ThreadLocal(); private static String CONFIG_FILE_LOCATION = "/hibernate.cfg.xml";
static {
try {
sessionFactory = new Configuration().configure(CONFIG_FILE_LOCATION).buildSessionFactory();
}catch (Throwable ex) {
ex.printStackTrace();
throw new ExceptionInInitializerError(ex); }
}
public static final ThreadLocal tLocalsess = new ThreadLocal(); public static final ThreadLocal tLocaltx = new ThreadLocal();
public static Session currentSession() throws HibernateException {
Session s = (Session) session.get();
if (s == null||!s.isOpen()) {
s = sessionFactory.openSession();
session.set(s);
}
return s;
} public static void closeSession() throws HibernateException { Session s = (Session) session.get(); if (s != null)
s.close();
session.set(null); }
/*
* begin the transaction
*/
public static void beginTransaction() {
System.out.println("begin tx");
Transaction tx = (Transaction) tLocaltx.get();
try {
if (tx == null) {
tx = currentSession().beginTransaction();
tLocaltx.set(tx);
}
} catch (HibernateException e) {
// throw new InfrastructureException(e);
}
} /*
* close the transaction
*/
public static void commitTransaction() {
Transaction tx = (Transaction) tLocaltx.get();
try {
if (tx != null && !tx.wasCommitted() && !tx.wasRolledBack())
tx.commit();
tLocaltx.set(null);
System.out.println("commit tx");
} catch (HibernateException e) {
// throw new InfrastructureException(e);
}
}}
可总是报错 郁闷啊
我的HibernateUtil文件package Login.hibernate;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2007</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.io.File;import org.hibernate.Transaction;
public class HibernateUtil { private static Log log = LogFactory.getLog(HibernateUtil.class); private static final SessionFactory sessionFactory;
public static final ThreadLocal session = new ThreadLocal(); private static String CONFIG_FILE_LOCATION = "/hibernate.cfg.xml";
static {
try {
sessionFactory = new Configuration().configure(CONFIG_FILE_LOCATION).buildSessionFactory();
}catch (Throwable ex) {
ex.printStackTrace();
throw new ExceptionInInitializerError(ex); }
}
public static final ThreadLocal tLocalsess = new ThreadLocal(); public static final ThreadLocal tLocaltx = new ThreadLocal();
public static Session currentSession() throws HibernateException {
Session s = (Session) session.get();
if (s == null||!s.isOpen()) {
s = sessionFactory.openSession();
session.set(s);
}
return s;
} public static void closeSession() throws HibernateException { Session s = (Session) session.get(); if (s != null)
s.close();
session.set(null); }
/*
* begin the transaction
*/
public static void beginTransaction() {
System.out.println("begin tx");
Transaction tx = (Transaction) tLocaltx.get();
try {
if (tx == null) {
tx = currentSession().beginTransaction();
tLocaltx.set(tx);
}
} catch (HibernateException e) {
// throw new InfrastructureException(e);
}
} /*
* close the transaction
*/
public static void commitTransaction() {
Transaction tx = (Transaction) tLocaltx.get();
try {
if (tx != null && !tx.wasCommitted() && !tx.wasRolledBack())
tx.commit();
tLocaltx.set(null);
System.out.println("commit tx");
} catch (HibernateException e) {
// throw new InfrastructureException(e);
}
}}
try {
sessionFactory = new Configuration().configure(CONFIG_FILE_LOCATION).buildSessionFactory();
}catch (Throwable ex) {
ex.printStackTrace();
throw new ExceptionInInitializerError(ex); }
抛出异常
这是怎么回事啊
但我输入用户名和密码后
报错
Error 500--Internal Server Errorjava.lang.ExceptionInInitializerError
at Login.hibernate.HibernateUtil.(HibernateUtil.java:46)
at Login.struts.LoginAction.execute(LoginAction.java:34)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:421)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:226)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1164)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:415)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(ServletStubImpl.java:1072)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:465)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:348)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:6981)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:121)
at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java:3892)
at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java:2766)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:224)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:183)
Caused by: org.hibernate.MappingException: entity class not found: Login.hibernate.Usertable
at org.hibernate.mapping.PersistentClass.getMappedClass(PersistentClass.java:99)
at org.hibernate.tuple.PropertyFactory.getGetter(PropertyFactory.java:166)
at org.hibernate.tuple.PropertyFactory.buildIdentifierProperty(PropertyFactory.java:44)
at org.hibernate.tuple.EntityMetamodel.(EntityMetamodel.java:115)
at org.hibernate.persister.entity.AbstractEntityPersister.(AbstractEntityPersister.java:412)
at org.hibernate.persister.entity.SingleTableEntityPersister.(SingleTableEntityPersister.java:108)
at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:55)
at org.hibernate.impl.SessionFactoryImpl.(SessionFactoryImpl.java:216)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1176)
at Login.hibernate.HibernateUtil.(HibernateUtil.java:43)
... 17 more
Caused by: java.lang.ClassNotFoundException: Login.hibernate.Usertable
at weblogic.utils.classloaders.GenericClassLoader.findClass(GenericClassLoader.java:199)
at weblogic.utils.classloaders.ChangeAwareClassLoader.findClass(ChangeAwareClassLoader.java:61)
at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
at weblogic.utils.classloaders.GenericClassLoader.loadClass(GenericClassLoader.java:224)
at weblogic.utils.classloaders.ChangeAwareClassLoader.loadClass(ChangeAwareClassLoader.java:41)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:141)
at org.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:108)
at org.hibernate.mapping.PersistentClass.getMappedClass(PersistentClass.java:96)
... 26 more
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"><hibernate-mapping package="Login.hibernate"> <class name="Usertable"
table="user_table"
discriminator-value="C"> <id name="id" column="id" type="string">
<generator class="uuid.hex"/>
</id>
<property name="name" column="name" type="string"/>
<property name="password" column="password" type="string"/>
<property name="utype" column="utype" type="string" /> </class></hibernate-mapping>
应该是User.hbm.xml文件 如下
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"><hibernate-mapping package="Login.hibernate"> <class name="Usertable"
table="user_table"
discriminator-value="C"> <id name="id" column="id" type="string">
<generator class="uuid.hex"/>
</id>
<property name="name" column="name" type="string"/>
<property name="password" column="password" type="string"/>
<property name="utype" column="utype" type="string" /> </class></hibernate-mapping>
Usertable.java文件如下
package Login.hibernate;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2007</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class Usertable{
private String id;
private String name;
private String password;
private String utype;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getUtype() {
return utype;
}
public void setUtype(String utype) {
this.utype = utype;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
NAME VARCHAR2
PASSWORD VARCHAR2
UTYPE VARCHAR2
U_LIMIT VARCHAR2
U_REG_DATE DATE 可以为空