为了账号安全,请及时绑定邮箱和手机立即绑定

Exception in thread "main" java.lang.ExceptionInInitializerError 这是啥错误,求教

2017-7-4 20:06:39 org.hibernate.Version logVersion

INFO: HHH000412: Hibernate Core {5.1.5.Final}

2017-7-4 20:06:39 org.hibernate.cfg.Environment <clinit>

INFO: HHH000206: hibernate.properties not found

2017-7-4 20:06:39 org.hibernate.cfg.Environment buildBytecodeProvider

INFO: HHH000021: Bytecode provider name : javassist

2017-7-4 20:06:39 org.hibernate.boot.jaxb.internal.stax.LocalXmlResourceResolver resolveEntity

WARN: HHH90000012: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/hibernate-configuration. Use namespace http://www.hibernate.org/dtd/hibernate-configuration instead.  Support for obsolete DTD/XSD namespaces may be removed at any time.

Exception in thread "main" java.lang.ExceptionInInitializerError

at com.imooc.entity.Test.findStudentsByGrade(Test.java:32)

at com.imooc.entity.Test.main(Test.java:14)

Caused by: org.hibernate.HibernateException: Error accessing stax stream

at org.hibernate.boot.cfgxml.internal.JaxbCfgProcessor.unmarshal(JaxbCfgProcessor.java:107)

at org.hibernate.boot.cfgxml.internal.JaxbCfgProcessor.unmarshal(JaxbCfgProcessor.java:65)

at org.hibernate.boot.cfgxml.internal.ConfigLoader.loadConfigXmlResource(ConfigLoader.java:57)

at org.hibernate.boot.registry.StandardServiceRegistryBuilder.configure(StandardServiceRegistryBuilder.java:163)

at org.hibernate.cfg.Configuration.configure(Configuration.java:259)

at org.hibernate.cfg.Configuration.configure(Configuration.java:245)

at com.imooc.util.HibernateUtil.<clinit>(HibernateUtil.java:13)

... 2 more

Caused by: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[3,2]

Message: The markup in the document preceding the root element must be well-formed.

at com.sun.org.apache.xerces.internal.impl.XMLStreamReaderImpl.next(XMLStreamReaderImpl.java:588)

at com.sun.xml.internal.stream.XMLEventReaderImpl.peek(XMLEventReaderImpl.java:271)

at org.hibernate.boot.cfgxml.internal.JaxbCfgProcessor.unmarshal(JaxbCfgProcessor.java:103)

... 8 more






package com.imooc.entity;



import java.util.Set;


import org.hibernate.Session;

import org.hibernate.Transaction;


import com.imooc.util.HibernateUtil;


public class Test {

public static void main(String[] args) {

//add();

findStudentsByGrade();

}

public static void add(){

Grade g=new Grade("zl班", "私有");

Student stu1=new Student("zl学生", '女');

Student stu2=new Student("李四", '男');

g.getStudents().add(stu1);

g.getStudents().add(stu2);

Session session=HibernateUtil.getSession();

Transaction tx=session.beginTransaction();

session.save(g);

session.save(stu1);

session.save(stu2);

tx.commit();

HibernateUtil.closeSession(session);

}

public static void findStudentsByGrade(){

Session session=HibernateUtil.getSession();

Grade grade=session.get(Grade.class, 1);

System.out.println(grade.getGname()+","+grade.getGdesc());

Set<Student>students=grade.getStudents();

for(Student stu:students){

System.out.println(stu.getSname()+","+stu.getSex());

}

}

}


正在回答

3 回答

是不是你hibernate的版本不对?


0 回复 有任何疑惑可以回复我~

但是我是按照视频中的教程来的,都没有报错,也不知道配置上哪里出错了

0 回复 有任何疑惑可以回复我~

你的配置文件中方的配置信息没弄对?

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消
Hibernate初探之一对多映射
  • 参与学习       42171    人
  • 解答问题       295    个

Hibernate中一对多关联映射配置,以及cascade和inverse属性作用

进入课程

Exception in thread "main" java.lang.ExceptionInInitializerError 这是啥错误,求教

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信