java hibernate.cfg.xml上的hibernate错误

ca1c2owp  于 2023-04-04  发布在  Java
关注(0)|答案(2)|浏览(186)

我得到这个错误当我尝试开始编译我的项目

dic 27, 2017 11:55:50 AM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {5.2.12.Final}
dic 27, 2017 11:55:50 AM org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
Initial SessionFactory creation 
failed.org.hibernate.internal.util.config.ConfigurationException: Unable to 
perform unmarshalling at line number 0 and column 0 in RESOURCE  
hibernate.cfg.xml. Message: null  
Exception in thread "main" java.lang.ExceptionInInitializerError
    at progetto1java.HibernateUtil.buildSessionFactory(HibernateUtil.java:15)
    at progetto1java.HibernateUtil.<clinit>(HibernateUtil.java:8)
    at progetto1java.Gestore_Utenti.VerificaUtente(Gestore_Utenti.java:59)
    at progetto1java.Sistema.main(Sistema.java:48)
Caused by: org.hibernate.internal.util.config.ConfigurationException: Unable 
    to perform unmarshalling at line number 0 and column 0 in RESOURCE  
    hibernate.cfg.xml. Message: null
    at org.hibernate.boot.cfgxml.internal.JaxbCfgProcessor.unmarshal(JaxbCfgProcessor.java:133)
    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:258)
    at org.hibernate.cfg.Configuration.configure(Configuration.java:244)
    at progetto1java.HibernateUtil.buildSessionFactory(HibernateUtil.java:12)
... 3 more
Caused by: javax.xml.bind.JAXBException
 - with linked exception:
[java.lang.ClassNotFoundException: 
com.sun.xml.internal.bind.v2.ContextFactory]
    at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:241)
    at javax.xml.bind.ContextFinder.find(ContextFinder.java:477)
    at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:656)
    at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:599)
    at org.hibernate.boot.cfgxml.internal.JaxbCfgProcessor.unmarshal(JaxbCfgProcessor.java:122)
... 9 more
Caused by: java.lang.ClassNotFoundException: 
com.sun.xml.internal.bind.v2.ContextFactory
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(Unknown Source)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(Unknown Source)
    at java.base/java.lang.ClassLoader.loadClass(Unknown Source)
    at javax.xml.bind.ContextFinder.safeLoadClass(ContextFinder.java:594)
    at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:239)
... 13 more

我仔细看了我的配置文件,但我不知道有什么问题..这些都是为了我的配置文件

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
    "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
    "http://hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory>
        <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/sistema_musicale</property>
        <property name="hibernate.connection.username">root</property>
        <property name="hibernate.connection.password"></property>
        <property name="hibernate.connection.pool_size">1</property>
        <property name="hibernate.current_session_context_class">thread</property>
        <property name="hbm2ddl.auto">create</property>
        <property name="hibernate.show_sql">true</property>
        <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
        <mapping class="progetto1java.Utente"/>
        <mapping class="progetto1java.Brano"/>

    </session-factory>
</hibernate-configuration>

Hibernate class util。
class hibernate to create session
对不起,我使用的图像,而不是代码,但我有缩进问题...

fumotvh3

fumotvh31#

我刚解决了一个

failed.org.hibernate.internal.util.config.ConfigurationException: Unable to 
perform unmarshalling at line number 0 and column 0 in RESOURCE  
hibernate.cfg.xml.

错误建立我自己的应用程序。
解决方案实际上非常简单,即我在pom.xml文件中缺少依赖项。我只有一个:

...
<dependency>
  <groupId>javax.xml.bind</groupId>
  <artifactId>jaxb-api</artifactId>
  <version>2.3.1</version>
</dependency>
...

添加以下三个解决了问题:

<dependency>
  <groupId>com.sun.xml.bind</groupId>
  <artifactId>jaxb-core</artifactId>
  <version>2.2.11</version>
</dependency>
<dependency>
  <groupId>com.sun.xml.bind</groupId>
  <artifactId>jaxb-impl</artifactId>
<version>2.3.2</version>
</dependency>
<dependency>
  <groupId>javax.activation</groupId>
  <artifactId>activation</artifactId>
  <version>1.1.1</version>
</dependency>

希望这能帮到什么人。

j13ufse2

j13ufse22#

请确保您的“hibernate.cfg.xml”文件位于项目的“src”文件夹中。

相关问题