使用hibernate与数据库连接时出错

我正在尝试使用hibernate在我的数据库上创建一个表。 这是我的代码

java对象

package com.digitek.students;

import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.Table; @Entity @Table(name="studentInfo") public class StudentInfo { @Id private int rollNo; public int getRollNo() { return rollNo; } public void setRollNo(int rollNo) { this.rollNo = rollNo; } public String getName() { return name; } public void setName(String name) { this.name = name; } private String name; } 

数据访问对象

 package com.digitek.students; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.cfg.Configuration; public class Main { public static void main(String[] args){ StudentInfo student = new StudentInfo(); student.setName("Rishit"); student.setRollNo(47); SessionFactory sf = new Configuration().configure().buildSessionFactory(); Session session = sf.openSession(); session.beginTransaction(); session.save(student); session.getTransaction().commit(); session.close(); sf.close(); } } 

这是我的hibernate.config.xml文件

 >    "-//Hibernate/Hibernate Configuration DTD 3.0//EN" > "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> > > hibernate-configuration> > >  > >  > <!-- org.hsqldb.jdbcDriver > jdbc:hsqldb:hsql://localhost/TestDB > --> > > org.mysql.Driver > jdbc:mysql://localhost:3306/hibernatetutorials > root >  > >  > 1 > >  >  > org.hibernate.dialect.MySQLDialect >  > >  > thread > > true > true > true > org.hibernate.cache.EhCacheRegionFactory > /hibernate-config/ehcache.xml > >  > org.hibernate.cache.NoCacheProvider > >  > true > >  > create > >  > >  > >  

错误消息

 Nov 02, 2015 11:02:26 AM org.hibernate.Version logVersion INFO: HHH000412: Hibernate Core {5.0.2.Final} Nov 02, 2015 11:02:26 AM org.hibernate.cfg.Environment  INFO: HHH000206: hibernate.properties not found Nov 02, 2015 11:02:26 AM org.hibernate.cfg.Environment buildBytecodeProvider INFO: HHH000021: Bytecode provider name : javassist Nov 02, 2015 11:02:26 AM 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" 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.digitek.students.Main.main(Main.java:15) Caused by: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[12,1] Message: Content is not allowed in prolog. at com.sun.org.apache.xerces.internal.impl.XMLStreamReaderImpl.next(Unknown Source) at com.sun.xml.internal.stream.XMLEventReaderImpl.peek(Unknown Source) at org.hibernate.boot.cfgxml.internal.JaxbCfgProcessor.unmarshal(JaxbCfgProcessor.java:103) ... 6 more 

请帮我解释一下。 先谢谢你。

问题在于XML的评论方式。

  

试试这个

  

如何用XML注释单行?