2012-03-27 36 views
4

私は、hibernateを使用してデータベースへの簡単な接続を確立しようとしています。Hibernate設定エラー(要素 'hibernate-configuration'の宣言が見つかりません)

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'. 
... 

ビットは非論理的なようだ:私は次のエラーを取得する

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

:ここに私の設定ファイルです。私はhibernate.cfg.xmlファイルのルート要素として 'hibernate-configuration'を持っています。

私はHibernateに新しく、右だので、うまくいけば、誰かが助けることができます(私は新しいHibernateは、おそらくいくつかの問題を持っていることができることをいくつかのヒントを得ていることから、言及)

を休止4.1.1を使用しています今私はGoogleからも大きな助けを得ていない。

答えて

2

は、以下のコマンドを使用して、セッション工場を建設 -

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

Hibernate.cfg用として、あなたは以下のヘッダを試みることができます。

<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"> 

現在、Hibernate 4.1はバグ(安定性については不明)に悩まされているようです。私はメーリングリストで解決策を見つけましたので、それもチェックしてください。お役に立てれば。

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

0

新しいAnnotationConfiguration()としてセッションファクトリを作成します。 configure()。 buildSessionFactory(); 希望すると、接続を確立するのに役立ちます。

0

このコードを試してください。

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

<?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> 
のようなあなたのXMLファイルにヘッダを追加します。
関連する問題