I can't find what's wrong with my hibernate.cfg.xml file.
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd" >
<hibernate-configuration>
<session-factory>
- <!-- Database connection settings
-->
<property name="connection.driver_class">org.h2.Driver</property>
<property name="connection.url">jdbc:h2://localhost:1527/hibernatedb</property>
<property name="connection.username">h2</property>
<property name="connection.password" />
- <!-- JDBC connection pool (use the built-in)
-->
<property name="connection.pool_size">1</property>
- <!-- Disable the second-level cache
-->
<property name="cache.provider_class">org.hibernate.cache.internal.CollectionCacheInvalidator
</property>
- <!-- Echo all executed SQL to stdout
-->
<property name="show_sql">true</property>
- <!-- Drop and re-create the database schema on startup
-->
<property name="hbm2ddl.auto">create</property>
- <!-- SQL dialect
-->
<property name="dialect">org.hibernate.dialect.H2Dialect</property>
- <!-- Names the annotated entity class
-->
<mapping class="firsthibernateproj.UserDetails" />
</session-factory>
</hibernate-configuration>
Here is the class that I use:
public class HibernateTest {
private static Object configuration;
public static void main(String[] args) {
UserDetails user = new UserDetails();
user.setUserId(1);
user.setUserName("First User");
Configuration configuration = new Configuration().configure("hibernate.cfg.xml");
StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder().
applySettings(configuration.getProperties());
SessionFactory factory = configuration.buildSessionFactory(builder.build());
Session session = factory.openSession();
session.beginTransaction();
session.save(user);
session.getTransaction().commit();
}
}
xml file was checked, there no grammar mistakes.
Any ideas how can I solve this problem?
Your file copied to my project also reports the same error, but the error goes away when those
-
characters before every comment are removed. Did you copy the content from some app that formats the xml? e.g. Internet Explorer does thatEDIT :)
Try this