Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to perform unmarshalling at line number 0 and column 0 in RESOURCE hibernate.cfg.xml. Message: null

Tags:

hibernate

Here is my configuration file hibernate.cfg.xml :

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

<hibernate-configuration>

<session-factory>


  <!-- Database connection settings -->
  <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
  <property name="connection.url">jdbc:mysql://localhost:3306/bdd_disc?useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT</property>
  <property name="connection.username">root</property>
  <property name="connection.password">MP18711922</property>

  <!-- JDBC connection pool (use the built-in) -->
  <property name="connection.pool_size">1</property>

  <!-- SQL dialect -->
  <property name="dialect">org.hibernate.dialect.MySQLDialect</property>

  <!-- Enable Hibernate's automatic session context management -->
  <property name="current_session_context_class">thread</property>

  <!-- Disable the second-level cache -->
  <property name="cache.provider_class">org.hibernate.cache.internal.NoCacheProvider</property>

  <!-- Echo all executed SQL to stdout -->
  <property name="show_sql">true</property>

  <mapping class="org.o7planning.tutorial.hibernate.entities.Artists" />
  <mapping class="org.o7planning.tutorial.hibernate.entities.Disc" />
  <mapping class="org.o7planning.tutorial.hibernate.entities.Song" />

 </session-factory>

</hibernate-configuration>

And the class to get the SessionFactory :

 public class HibernateUtils {

    private static final SessionFactory sessionFactory = buildSessionFactory();

    // Hibernate 5:
    private static SessionFactory buildSessionFactory() {
        try {
            // Create the ServiceRegistry from hibernate.cfg.xml
            ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder()//
                    .configure("hibernate.cfg.xml").build();

            // Create a metadata sources using the specified service registry.
            Metadata metadata = new MetadataSources(serviceRegistry).getMetadataBuilder().build();

            return metadata.getSessionFactoryBuilder().build();
        } catch (Throwable ex) {

            System.err.println("Initial SessionFactory creation failed." + ex);
            throw new ExceptionInInitializerError(ex);
        }
    }

    public static SessionFactory getSessionFactory() {
        return sessionFactory;
    }

    public static void shutdown() {
        // Close caches and connection pools
        getSessionFactory().close();
    }

}

I receive the error :

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

The class doing the main job is :

private static void getTagsFromFile(File f) {

    String artist = null;
    String disc = null;
    String song = null;
    Tag tag = null;
    AudioFile af;
    Artists artistInBase = null;
    Disc discInBase = null;
    Song songInBase = null;

     SessionFactory factory = HibernateUtils.getSessionFactory();
     Session session = factory.getCurrentSession();
       try {

           // All the action with DB via Hibernate
           // must be located in one transaction.
           // Start Transaction.            
           session.getTransaction().begin();

           af = AudioFileIO.read(f);
           tag = af.getTag();
           artist = tag.getFirst(FieldKey.ARTIST);
           artist = artist.replaceAll("'", " ");
           artist = artist.replaceAll("\"", " ");
           disc = tag.getFirst(FieldKey.ALBUM);
           disc = disc.replaceAll("'", " ");
           disc = disc.replaceAll("\"", "'");
           song = tag.getFirst(FieldKey.TITLE);
           song = song.replaceAll("\"", "'");

           int idArtist = -1;
           int idDisc = -1;

           Transaction tx = null;
           try {
               tx = session.beginTransaction();
               String queryAsString = "SELECT artists.name FROM artists WHERE          artists.name LIKE " + "'" + artist + "'";
           Query<Artists> query = session.createQuery(queryAsString);
           List<Artists> artists = query.getResultList();

          if (artists.isEmpty()) {
            artistInBase = new Artists(artist);
            session.save(artistInBase);
            session.flush();
            idArtist = artistInBase.getId();
          }
          else {
            artistInBase = artists.get(0);
            idArtist = artistInBase.getId();
        }
            tx.commit();
        }

        catch (Exception e) {
            if (tx != null)
                tx.rollback();
            e.printStackTrace();
        } finally {
            session.close();
        }
    } catch (CannotReadException | IOException | TagException | ReadOnlyFileException
            | InvalidAudioFrameException e) {
        System.err.println("Cannot parse " + f.getName());
    }

}
like image 564
ATN54 Avatar asked Oct 21 '25 16:10

ATN54


1 Answers

I had a similar issue in the maven build life cycle. I used the maven plugin maven-processor-plugin as described here. The maven log contained the following warning:

[INFO] --- maven-processor-plugin:3.3.3:process (process) @ orm-project ---
[INFO] diagnostic: Note: Hibernate JPA 2 Static-Metamodel Generator 5.4.12.Final
[WARNING] diagnostic: warning: Unable to parse persistence.xml: Unable to perform unmarshalling at line number 0 and column 0. Message: null

After I switched to maven 3.6.3 and JDK 11 I removed the maven-processor-plugin and added the hibernate-jpamodelgen to the dependency section. This solved the warning. The static metamodel classes are still generated.

like image 126
Easterwood Avatar answered Oct 26 '25 17:10

Easterwood



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!