java.lang.ExceptionInInitializerError
at com.mypackage.dao.AbcDAO.get(AbcDAO.java:67)
at com.mypackage.dao.AbcDAOTest.testGet(AbcDAOTest.java:41)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.junit.internal.runners.TestMethodRunner.executeMethodBody(TestMethodRunner.java:99)
at org.junit.internal.runners.TestMethodRunner.runUnprotected(TestMethodRunner.java:81)
at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34)
at org.junit.internal.runners.TestMethodRunner.runMethod(TestMethodRunner.java:75)
at org.junit.internal.runners.TestMethodRunner.run(TestMethodRunner.java:45)
at org.junit.internal.runners.TestClassMethodsRunner.invokeTestMethod(TestClassMethodsRunner.java:66)
at org.junit.internal.runners.TestClassMethodsRunner.run(TestClassMethodsRunner.java:35)
at org.junit.internal.runners.TestClassRunner$1.runUnprotected(TestClassRunner.java:42)
at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34)
at org.junit.internal.runners.TestClassRunner.run(TestClassRunner.java:52)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:45)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Caused by: org.hibernate.InvalidMappingException: Could not parse mapping document from resource com/mypackage/pojo/Abc.hbm.xml
at org.hibernate.cfg.Configuration.addResource(Configuration.java:616)
at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1635)
at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1603)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1582)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1556)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1476)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1462)
at com.mypackage.dao.HibernateSessionFactory.<clinit>(HibernateSessionFactory.java:9)
... 22 more
Caused by: org.hibernate.MappingException: Unable to determine entity name
at org.hibernate.cfg.HbmBinder.bindClass(HbmBinder.java:541)
at org.hibernate.cfg.HbmBinder.bindRootClass(HbmBinder.java:293)
at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:166)
at org.hibernate.cfg.Configuration.add(Configuration.java:716)
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:551)
at org.hibernate.cfg.Configuration.addResource(Configuration.java:613)
... 29 more报不能够解析这个类,是为什么
at com.mypackage.dao.AbcDAO.get(AbcDAO.java:67)
at com.mypackage.dao.AbcDAOTest.testGet(AbcDAOTest.java:41)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.junit.internal.runners.TestMethodRunner.executeMethodBody(TestMethodRunner.java:99)
at org.junit.internal.runners.TestMethodRunner.runUnprotected(TestMethodRunner.java:81)
at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34)
at org.junit.internal.runners.TestMethodRunner.runMethod(TestMethodRunner.java:75)
at org.junit.internal.runners.TestMethodRunner.run(TestMethodRunner.java:45)
at org.junit.internal.runners.TestClassMethodsRunner.invokeTestMethod(TestClassMethodsRunner.java:66)
at org.junit.internal.runners.TestClassMethodsRunner.run(TestClassMethodsRunner.java:35)
at org.junit.internal.runners.TestClassRunner$1.runUnprotected(TestClassRunner.java:42)
at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34)
at org.junit.internal.runners.TestClassRunner.run(TestClassRunner.java:52)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:45)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Caused by: org.hibernate.InvalidMappingException: Could not parse mapping document from resource com/mypackage/pojo/Abc.hbm.xml
at org.hibernate.cfg.Configuration.addResource(Configuration.java:616)
at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1635)
at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1603)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1582)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1556)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1476)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1462)
at com.mypackage.dao.HibernateSessionFactory.<clinit>(HibernateSessionFactory.java:9)
... 22 more
Caused by: org.hibernate.MappingException: Unable to determine entity name
at org.hibernate.cfg.HbmBinder.bindClass(HbmBinder.java:541)
at org.hibernate.cfg.HbmBinder.bindRootClass(HbmBinder.java:293)
at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:166)
at org.hibernate.cfg.Configuration.add(Configuration.java:716)
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:551)
at org.hibernate.cfg.Configuration.addResource(Configuration.java:613)
... 29 more报不能够解析这个类,是为什么
Caused by: org.hibernate.MappingException: Unable to determine entity name 应该是配置文件的问题,楼主仔细检查一下
这些我都有做了,我的配置文件如下:
Abc.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" >
<hibernate-mapping>
<class>
<id name="a" column="a">
</id>
<property name="b" column="b"></property>
</class>
</hibernate-mapping>hibernate.cfg.xml<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd" >
<hibernate-configuration>
<session-factory>
<property name="connection.driver_class">oracle.jdbc.OracleDriver</property>
<property name="connection.url">jdbc:oracle:thin:@localhost:1521:test</property>
<property name="connection.username">scott</property>
<property name="connection.password">test</property>
<property name="show_sql">true</property>
<property name="format_sql">false</property>
<property name="use_sql_comments">false</property>
<property name="dialect">org.hibernate.dialect.Oracle10gDialect</property>
<mapping resource="com/mypackage/pojo/Emp.hbm.xml"></mapping>
<mapping resource="com/mypackage/pojo/Dept.hbm.xml"></mapping>
<mapping resource="com/mypackage/pojo/Abc.hbm.xml"></mapping>
</session-factory>
</hibernate-configuration>类如下:
package com.mypackage.pojo;import java.io.Serializable;public class Abc implements Serializable {
private Integer a;
private String b;
public Integer getA() {
return a;
}
public void setA(Integer a) {
this.a = a;
}
public String getB() {
return b;
}
public void setB(String b) {
this.b = b;
}
public Abc() {
super();
}
}
package com.mypackage.dao;import java.util.List;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Transaction;
import org.hibernate.classic.Session;
import com.mypackage.pojo.Abc;public class AbcDAO {
public void save(Abc abc)
{
Session session = (Session) HibernateSessionFactory.getSession();
Transaction tr = session.beginTransaction();
try {
session.save(abc);
tr.commit();
} catch (HibernateException e) {
tr.rollback();
e.printStackTrace();
}finally{
if(session!=null)
{
session.close();
}
}
}
public void delete(Abc abc)
{
Session session = (Session) HibernateSessionFactory.getSession();
Transaction tr = session.beginTransaction();
try {
session.delete(abc);
tr.commit();
} catch (HibernateException e) {
tr.rollback();
e.printStackTrace();
}finally{
if(session!=null)
{
session.close();
}
}
}
public void update(Abc abc)
{
Session session = (Session) HibernateSessionFactory.getSession();
Transaction tr = session.beginTransaction();
try {
session.update(abc);
tr.commit();
} catch (HibernateException e) {
tr.rollback();
e.printStackTrace();
}finally{
if(session!=null)
{
session.close();
}
}
}
public Abc get(Integer a)
{
Session session = (Session) HibernateSessionFactory.getSession();
Transaction tr = session.beginTransaction();
Abc emp=null;
try {
emp = (Abc) session.get(Abc.class, a);
tr.commit();
} catch (HibernateException e) {
tr.rollback();
e.printStackTrace();
}finally{
if(session!=null)
{
session.close();
}
}
return emp;
}
public Abc load(Integer a)
{
Session session = (Session) HibernateSessionFactory.getSession();
Transaction tr = session.beginTransaction();
Abc emp=null;
try {
emp = (Abc) session.load(Abc.class, a);
tr.commit();
} catch (HibernateException e) {
tr.rollback();
e.printStackTrace();
}finally{
if(session!=null)
{
session.close();
}
}
return emp;
}
public List<Abc> list()
{
List<Abc> abcs=null;
Session session = (Session) HibernateSessionFactory.getSession();
Transaction tr = session.beginTransaction();
try {
Query query = session.createQuery("from Abc e join fetch e.dept order by e.sal");
abcs = query.list();
tr.commit();
} catch (HibernateException e) {
tr.rollback();
e.printStackTrace();
}finally{
if(session!=null)
{
session.close();
}
}
return abcs;
}
}
检查了好久没看见问题在哪
贴这个配置文件
<class>
<id name="a" column="a">
</id>
<property name="b" column="b"> </property>
</class>
</hibernate-mapping> 是错误的
<class name="com.mypackage.dao.Abc">
<id name="a" column="a">
<generator class="native"/>
</id>
<property name="b" column="b"> </property>
</class>
</hibernate-mapping>
注明:
name="com.mypackage.dao.Abc" 是你这个class具体的类对象
<generator class="native"/> 是你这个表的主键的生成方法可以使 uuid 是以32位的字符串来生成主键,
native 是自动生长的主键生成方式,
assigned 是你自己设定主键
foreign 是通过外键来生成主键,,在<one-to-one>的情况下通过共享主键来实现关联
没指定对应的表