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

Hello, I’m trying to have my Hibernate util and my Hibernate entities in another maven project, so I can just depend on it in any of my projects and have already everything ready for hibernate. The problem is somehow hibernate isn’t detecting my hibernate.cfg.xml, but it is in the main class path of my built jar file.

Here is my config:

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD//EN"
        "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory>

        <property name="connection.url">jdbc:mysql://ip:port/database</property>
        <property name="connection.driver_class">com.mysql.cj.jdbc.Driver</property>
        <property name="connection.username">username</property>
        <property name="connection.password">password</property>
        <property name="connection.pool_size">8</property>
        <property name="hibernate.hbm2ddl.auto">update</property>
        <property name="hibernate.dialect">org.hibernate.dialect.MariaDBDialect</property>
        <property name="hibernate.temp.use_jdbc_metadata_defaults">false</property>
    </session-factory>
</hibernate-configuration>

Here is how i initialize / configure Hibernate:

    static public void init(){
        if(sessionFactory != null){
            return;
        }

        try{
            Configuration configuration = new Configuration();

            for (Class mapping : getMappings()){
                System.out.println("[HibernateProvider] Loading " + mapping.getSimpleName() + "...");
                configuration.addAnnotatedClass(mapping);
            }

            sessionFactory = configuration.configure().buildSessionFactory();
        }catch (Exception e){
            e.printStackTrace();
        }
    }
[12.12 01:37:45.098] WARNING: [Lobby-1] org.hibernate.internal.util.config.ConfigurationException: Unable to perform unmarshalling at line number 0 and column 0 in RESOURCE hibernate.cfg.xml. Message: null
[12.12 01:37:45.098] WARNING: [Lobby-1]         at org.hibernate.boot.cfgxml.internal.JaxbCfgProcessor.unmarshal(JaxbCfgProcessor.java:132)
[12.12 01:37:45.098] WARNING: [Lobby-1]         at org.hibernate.boot.cfgxml.internal.JaxbCfgProcessor.unmarshal(JaxbCfgProcessor.java:66)
[12.12 01:37:45.098] WARNING: [Lobby-1]         at org.hibernate.boot.cfgxml.internal.ConfigLoader.loadConfigXmlResource(ConfigLoader.java:57)
[12.12 01:37:45.098] WARNING: [Lobby-1]         at org.hibernate.boot.registry.StandardServiceRegistryBuilder.configure(StandardServiceRegistryBuilder.java:244)
[12.12 01:37:45.098] WARNING: [Lobby-1]         at org.hibernate.cfg.Configuration.configure(Configuration.java:358)
[12.12 01:37:45.098] WARNING: [Lobby-1]         at org.hibernate.cfg.Configuration.configure(Configuration.java:343)
[12.12 01:37:45.098] WARNING: [Lobby-1]         at xyz.syodo.provider.HibernateProvider.init(HibernateProvider.java:32)
[12.12 01:37:45.098] WARNING: [Lobby-1]         at xyz.syodo.mgmt.ManagementSystem.onEnable(ManagementSystem.java:22)
[12.12 01:37:45.098] WARNING: [Lobby-1]         at cn.nukkit.plugin.PluginBase.setEnabled(PluginBase.java:107)
[12.12 01:37:45.098] WARNING: [Lobby-1]         at cn.nukkit.plugin.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:125)
[12.12 01:37:45.098] WARNING: [Lobby-1]         at cn.nukkit.plugin.PluginManager.enablePlugin(PluginManager.java:462)
[12.12 01:37:45.098] WARNING: [Lobby-1]         at cn.nukkit.Server.enablePlugin(Server.java:1878)
[12.12 01:37:45.098] WARNING: [Lobby-1]         at cn.nukkit.Server.enablePlugins(Server.java:1861)
[12.12 01:37:45.098] WARNING: [Lobby-1]         at cn.nukkit.Server.<init>(Server.java:957)
[12.12 01:37:45.098] WARNING: [Lobby-1]         at cn.nukkit.Nukkit.main(Nukkit.java:160)
[12.12 01:37:45.098] WARNING: [Lobby-1]         at cn.nukkit.JarStart.main(JarStart.java:20)
[12.12 01:37:45.098] WARNING: [Lobby-1]         at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[12.12 01:37:45.098] WARNING: [Lobby-1]         at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
[12.12 01:37:45.098] WARNING: [Lobby-1]         at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[12.12 01:37:45.098] WARNING: [Lobby-1]         at java.base/java.lang.reflect.Method.invoke(Method.java:568)
[12.12 01:37:45.098] WARNING: [Lobby-1]         at de.dytanic.cloudnet.wrapper.Wrapper.lambda$startApplication$5(Wrapper.java:487)
[12.12 01:37:45.098] WARNING: [Lobby-1]         at java.base/java.lang.Thread.run(Thread.java:840)
[12.12 01:37:45.098] WARNING: [Lobby-1] Caused by: jakarta.xml.bind.JAXBException: Implementation of Jakarta XML Binding-API has not been found on module path or classpath.
[12.12 01:37:45.098] WARNING: [Lobby-1]  - with linked exception:
[12.12 01:37:45.098] WARNING: [Lobby-1] [java.lang.ClassNotFoundException: org.glassfish.jaxb.runtime.v2.ContextFactory]
[12.12 01:37:45.098] WARNING: [Lobby-1]         at jakarta.xml.bind.ContextFinder.newInstance(ContextFinder.java:252)
[12.12 01:37:45.098] WARNING: [Lobby-1]         at jakarta.xml.bind.ContextFinder.newInstance(ContextFinder.java:240)
[12.12 01:37:45.098] WARNING: [Lobby-1]         at jakarta.xml.bind.ContextFinder.find(ContextFinder.java:381)
[12.12 01:37:45.098] WARNING: [Lobby-1]         at jakarta.xml.bind.JAXBContext.newInstance(JAXBContext.java:605)
[12.12 01:37:45.098] WARNING: [Lobby-1]         at jakarta.xml.bind.JAXBContext.newInstance(JAXBContext.java:546)
[12.12 01:37:45.098] WARNING: [Lobby-1]         at org.hibernate.boot.cfgxml.internal.JaxbCfgProcessor.unmarshal(JaxbCfgProcessor.java:121)
[12.12 01:37:45.098] WARNING: [Lobby-1]         ... 21 more
[12.12 01:37:45.098] WARNING: [Lobby-1] Caused by: java.lang.ClassNotFoundException: org.glassfish.jaxb.runtime.v2.ContextFactory
[12.12 01:37:45.098] WARNING: [Lobby-1]         at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
[12.12 01:37:45.098] WARNING: [Lobby-1]         at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
[12.12 01:37:45.098] WARNING: [Lobby-1]         at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:525)
[12.12 01:37:45.098] WARNING: [Lobby-1]         at jakarta.xml.bind.ServiceLoaderUtil.nullSafeLoadClass(ServiceLoaderUtil.java:113)
[12.12 01:37:45.098] WARNING: [Lobby-1]         at jakarta.xml.bind.ServiceLoaderUtil.safeLoadClass(ServiceLoaderUtil.java:146)
[12.12 01:37:45.098] WARNING: [Lobby-1]         at jakarta.xml.bind.ContextFinder.newInstance(ContextFinder.java:250)
[12.12 01:37:45.098] WARNING: [Lobby-1]         ... 26 more

Look at the exception:

jakarta.xml.bind.JAXBException: Implementation of Jakarta XML Binding-API has not been found on module path or classpath.

You are missing an implementation of the Jakarta XML Binding on the classpath. Actually, Hibernate ORM has a dependency on this already, so I assume you might have messed up something.

      <dependency>
        <groupId>org.glassfish.jaxb</groupId>
        <artifactId>jaxb-runtime</artifactId>
        <version>4.0.2</version>
      </dependency>

Hello @beickvon ,
Even i have the same issue i have added all required JAXB- API related jar but no luck .
am using Hibernate 5.6.15.Final and java17 .Actually we are migrating java 8 to java17 and ealrier Hibernate was 3.1.3 and not migrating to 5.6.15.Final which has java17 support

Your question is about using Hibernate ORM 5 which uses the javax packages on a JDK that doesn’t ship with JAXB dependencies anymore. In your case, you will have to add the jaxb-runtime that is compatible with that version of Hibernate ORM. It’s best not to mess with the dependencies though, because this was fixed in Hibernate ORM 5.4 already. See [HHH-12946] - Hibernate JIRA

1 Like

we are migrating from Hibernate 3.1.3 to 5.6.15.Final and for session creating we are having session.opensession and to make thread safe we have Threadlocal implementation. in scenario RMI call session is closed before Transaction is null while commit method is called. SessionFactory is name is coming null while initializing .
we are using java17 from java8 migration.

You are missing the JARs for jaxb-runtime and jaxb-api on your classpath. I don’t know what to tell you other than “you will have to add the jaxb-runtime that is compatible with that version of Hibernate ORM”.

am using Hibernate-core-jakarata:5.6.15.FInal now . And also we have hibernate.cfg.xml and hbm.xml files .
Session creation as below …--------------
public static Session currentSession(String instance) throws
HibernateException {

	log.finest("currentSession called for " + instance +
			" [" + Thread.currentThread().getName() + "]");

	// Check if the thread local object is registered with the instance
	ThreadLocal tl = null;
	synchronized (sessionFactoryLock) {
		tl = (ThreadLocal) sessionPerThreadMap.get(instance);
		if (tl == null) {
			log.finest("Session not found for instance " + instance +
					" [" + Thread.currentThread().getName() + "]");
			// Check if the session factory is created. If not, initialise it
			SessionFactory factory = (SessionFactory) sessionFactoryMap.get(
					instance);
			if (factory == null) {
				log.finest("Session factory not found for instance " + instance);
				HibernateUtil.initFactory(instance);
			}

			tl = (ThreadLocal) sessionPerThreadMap.get(instance);
		}
	}

	Session s = (Session) tl.get();
	// Open a new Session, if this Thread has none yet
	if (s == null) {
		log.finest("Opening new session for instance " + instance +
				" [" + Thread.currentThread().getName() + "]");
        s = ((SessionFactory) sessionFactoryMap.get(instance)).openSession();
		((ThreadLocal) sessionPerThreadMap.get(instance)).set(s);
	}
	return s;
}

------session factory creation –
Configuration cfg = new Configuration();

        //Read in the defaults from persistence.jar
		cfg.configure(HibernateUtil.class.getResource("/hibernate.cfg.xml"));

        //Read in list of persistable POJOs
		cfg.configure("/hibernate_" + instance + ".cfg.xml");

		if(!useDataSource(cfg)) {
			// Name for connectionpool
			cfg.setProperty(HibernateConnectionProvider.POOL_ID_PROPERTY_NAME,
					instance);

			// Resolve database name used in DB_INFO_FILE
			String dbName = resolveDatabaseName(cfg, instance);

			// Read connection information from DB_INFO_FILE and set
			// Hibernate configration parameters
			if ((dbinfo != null) && (dbinfo.getProperties(dbName) != null)) {
				configureDBInfo(cfg, dbName);
			}
			else {
				log.info("Database connection information not set in the " +
						"DB_INFO_FILE for " + dbName + ". Expecting " +
				"information to be found from Hibernate configuration");
			}
		}

		log.info("Calling Hibernate configuration listeners for " + instance + " ...");
		cfg = callConfigurationListeners(cfg, instance);

        log.info("Building Hinernate session factory for " + instance + " ...");
		// create session factory
		SessionFactory sf = cfg.buildSessionFactory();

		// add session factory to a map
		sessionFactoryMap.put(instance, sf);

		// add ThreadLocal to a session map
		sessionPerThreadMap.put(instance, new ThreadLocal());

		return sf;