Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java Hibernate Basics Persisting Data with Hibernate Saving Data with Hibernate

ERROR on netbeans :Unable to perform unmarshalling at line number 0 and column 0 in RESOURCE hibernate.cfg.xml

Followed the videos as said on netbeans,but unable to save data with the above mentioned error.

5 Answers

Rodrigo Castro
Rodrigo Castro
15,652 Points

Hi Anshika,

I was getting the same error. The problem was that I had placed the 'show_sql' property at the end of the hibernate.cgf.xml file, like this:

<hibernate-configuration> <session-factory> <!-- Database connection setting--> <property name="connection.driver_class">org.h2.Driver</property> <property name="connection.url">jdbc:h2:./data/contactmgr</property>

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

    <!-- Create database schema on application startup-->
    <property name="hbm2ddl.auto">create</property>


    <!-- Names the annotated entity classes -->
    <mapping class="com.rodrigo.contactmgr.model.Contact"/>

    <!-- show the queries prepared by Hibernate-->               <------ THE PROBLEM WAS HERE
    <property name="show_sql">true</property>

</session-factory>

</hibernate-configuration>

I solved the problem by placing the 'show_sql' property right after the 'hbm2ddl.auto' property, like this:

<hibernate-configuration> <session-factory> <!-- Database connection setting--> <property name="connection.driver_class">org.h2.Driver</property> <property name="connection.url">jdbc:h2:./data/contactmgr</property>

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

    <!-- Create database schema on application startup-->
    <property name="hbm2ddl.auto">create</property>

    <!-- show the queries prepared by Hibernate-->        <----------- PLACED IT HERE
    <property name="show_sql">true</property>

    <!-- Names the annotated entity classes -->
    <mapping class="com.rodrigo.contactmgr.model.Contact"/>

</session-factory>

</hibernate-configuration>

Hope it helps.

Alexander Nikiforov
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Alexander Nikiforov
Java Web Development Techdegree Graduate 22,175 Points

It looks like you have some syntax problems in your hibernate.cfg.xml file...

Have you tried solutions in Stack? Take a look at answer here:

http://stackoverflow.com/questions/32499073/error-in-configuring-hibernate-5-0-1-and-mysql

Could you push project on GitHub, or at least just hibernate.cfg.xml file...

Bakhtiyar Seidakhmetov
Bakhtiyar Seidakhmetov
11,936 Points

I have the same problem. In fact i had typo in hibernate.cfg.xml file. Call one field as proprety. Check it first

Just joined here recently, I also ran into this problem and it took some time to solve but here is a fix for those using java 8 and up.

Make sure to include the following dependencies

 compile 'javax.xml.bind:jaxb-api:2.3.0'

// https://mvnrepository.com/artifact/com.sun.xml.bind/jaxb-impl
compile group: 'com.sun.xml.bind', name: 'jaxb-impl', version: '2.3.0'

// https://mvnrepository.com/artifact/com.sun.xml.bind/jaxb-core
compile group: 'com.sun.xml.bind', name: 'jaxb-core', version: '2.3.0'

// https://mvnrepository.com/artifact/javax.activation/activation
compile group: 'javax.activation', name: 'activation', version: '1.1.1'
Kareem Jeiroudi
Kareem Jeiroudi
14,984 Points

Had the same error. To resolve it I had to 'escape' the ampersand & sign with &amp in my database url. Even if you have your character set encoding set to utf-8, that won't work, simply because xml uses & as a predefined character.

I hope this's been helpful!