4

I'm trying to establish a simple connection to my database using hibernate. Here is my configuration 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.hsqldb.jdbcDriver</property>
<property name="connection.url">jdbc:hsqldb:hsql://localhost</property>
<property name="connection.username">user</property>
<property name="connection.password">pass</property>

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

<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.HSQLDialect</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>

<!-- Drop and re-create the database schema on startup -->
<property name="hbm2ddl.auto">update</property>
<mapping resource="com/mycomp/pro/model/elem/elem.hbm.xml"/>
</session-factory>
</hibernate-configuration>

I get the following error:

Exception in thread "main" org.hibernate.internal.util.config.ConfigurationException: Unable to perform unmarshalling at line number 6 and column 26 in RESOURCE hibernate.cfg.xml. Message: cvc-elt.1: Cannot find the declaration of element 'hibernate-configuration'.
...

Seems bit illogical. Since I have 'hibernate-configuration' as the root element in the hibernate.cfg.xml file.

I'm using Hibernate 4.1.1 (just mentioning, since I've gotten some hints that the new hibernate could possibly have some issues)

Hopefully somebody can help since I'm new to Hibernate and right now I'm not getting any major help from google either.

4 Answers 4

2

Build the Session Factory using the below command -

new Configuration().configure().buildSessionFactory();

As for the Hibernate.cfg you could try the below header.

<hibernate-configuration 
 xmlns="http://www.hibernate.org/xsd/hibernate-configuration" 
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://www.hibernate.org/xsd/hibernate-configuration 
 https://github.com/hibernate/hibernate-orm/raw/master/hibernate-core/src/main/resources/org/hibernate/hibernate-configuration-4.0.xsd">

Currently Hibernate 4.1 seems to be suffering from bugs(Not sure about stability). I found the solution at a mailing list so check that out as well. Hope this helps.

http://www.mail-archive.com/[email protected]/msg06937.html

Sign up to request clarification or add additional context in comments.

1 Comment

ı already did but ı still get the some error
0

Create session factory as new AnnotationConfiguration (). configure (). buildSessionFactory (); Hope It will help you to build connection...

Comments

0

Try this code.

SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory(); 
    Session session = sessionFactory.openSession();
    session.beginTransaction();

Add header to your XML file like

<?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>
        --------
    <hibernate-configuration>

Comments

0

Do copy paste the hibernate configuration xml file from your D:\hibernate-release-5.1.17.Final\project folder >>>>>>> search for the hibernate.cfg.xml and selected the correct file which includes the create, DOCTYPE and the mappings...

And just change the values according to your Database and settings.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.