2012-03-03 12 views
4

私は最初のHibernateプロジェクトを作ろうとしました。私は自分のプロジェクトに以下のライブラリを追加しました:私の最初のHibernateプロジェクトでエラーを修正するには?

ANTLR-2.7.7 コモンズ・コレクション-3.2.1 のdom4j-1.6.1 hibernate-commons-annotations-4.0.1.Final 休止状態 - コア - 4.1。 0.Final hibernate-jpa-2.0-api-1.0.1.Final Javassistの-3.15.0-GA のJBossロギング-3.1.0.CR2 jboss-transaction-api_1.1_spec-1.0.0.Final MySQLのコネクタ-のjava-5.1.18-ビン

はhibernate.cfg.xml:

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN" 
    "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> 
<hibernate-configuration> 
<session-factory> 
    <property name="hibernate.connection.url">jdbc:mysql://localhost/test</property> 
    <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property> 

    <property name="hibernate.connection.username">root</property> 
    <property name="hibernate.connection.password"></property> 
    <property name="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</property> 

    <mapping class="com.nda.hibernate.Person"/> 
</session-factory> 
</hibernate-configuration> 

Person.class:

package com.nda.hibernate; 

import javax.persistence.Entity; 
import javax.persistence.Id; 


@Entity 
public class Person { 

    private String name; 

    @Id 
    private int number; 

    public Person() {} 

    public Person(String name, int number) { 

     this.name=name; 
     this.number=number; 
    } 

    public void setName(String name) { 
     this.name=name; 
    } 

    public String getName() { 
     return name; 
    } 

    public void setNumber(int number) { 
     this.number=number; 
    } 

    public int getNumber() { 
     return number; 
    } 
} 

私はDenwerがインストールされています。使用するためのパラメータ:login - root、passwordは空です。そうでない

SessionFactory sessions=new AnnotationConfiguration().configure().buildSessionFactory(); 
    Session session=sessions.openSession(); 

:Main.class

- サーバーはlocalhost、およびテーブル "人"(主キーCHAR(50)の名前、INT(10)番号)とデータベース "test" を持っています作業。いくつかのエラーがあります:

03.03.2012 14:11:07 org.hibernate.annotations.common.Version <clinit> 
INFO: HCANN000001: Hibernate Commons Annotations {4.0.1.Final} 
03.03.2012 14:11:07 org.hibernate.Version logVersion 
INFO: HHH000412: Hibernate Core {4.1.0.Final} 
03.03.2012 14:11:07 org.hibernate.cfg.Environment <clinit> 
INFO: HHH000206: hibernate.properties not found 
03.03.2012 14:11:07 org.hibernate.cfg.Environment buildBytecodeProvider 
INFO: HHH000021: Bytecode provider name : javassist 
03.03.2012 14:11:07 org.hibernate.cfg.Configuration configure 
INFO: HHH000043: Configuring from resource: /hibernate.cfg.xml 
03.03.2012 14:11:07 org.hibernate.cfg.Configuration getConfigurationInputStream 
INFO: HHH000040: Configuration resource: /hibernate.cfg.xml 
03.03.2012 14:11:07 org.hibernate.internal.util.xml.DTDEntityResolver resolveEntity 
WARN: HHH000223: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/. Use namespace http://www.hibernate.org/dtd/ instead. Refer to Hibernate 3.6 Migration Guide! 
03.03.2012 14:11:07 org.hibernate.cfg.Configuration doConfigure 
INFO: HHH000041: Configured SessionFactory: null 
03.03.2012 14:11:07 org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure 
INFO: HHH000402: Using Hibernate built-in connection pool (not for production use!) 
03.03.2012 14:11:07 org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure 
INFO: HHH000115: Hibernate connection pool size: 20 
03.03.2012 14:11:07 org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure 
INFO: HHH000006: Autocommit mode: false 
03.03.2012 14:11:07 org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure 
INFO: HHH000401: using driver [com.mysql.jdbc.Driver] at URL [jdbc:mysql://localhost/test] 
03.03.2012 14:11:07 org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure 
INFO: HHH000046: Connection properties: {user=root, password=****} 
03.03.2012 14:11:08 org.hibernate.dialect.Dialect <init> 
INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect 
03.03.2012 14:11:08 org.hibernate.engine.transaction.internal.TransactionFactoryInitiator initiateService 
INFO: HHH000399: Using default transaction strategy (direct JDBC transactions) 
03.03.2012 14:11:08 org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory <init> 
INFO: HHH000397: Using ASTQueryTranslatorFactory 

どうすれば修正できますか?ありがとうございました。

+1

にライン

http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd 

を変更する必要がある構成を休止状態ファイルのXMLで 簡単です。例外を含むログを表示してください。 –

答えて

12

私にはエラーのように見えるものはありません。

がWARN:HHH000223:認識廃止されたHibernateの名前空間 http://hibernate.sourceforge.net/のみ "の問題は、" ここに警告です。代わりにネームスペース http://www.hibernate.org/dtd/を使用してください。 Hibernate 3.6 Migration Guideを参照してください。固定価値は、それがひどく緊急 ないように聞こえる - 警告のみです

その他の情報はすべてINFOレベルです...心配しないでください。ちょうど行くと、あなたのコードは、データベースアクセスの面で期待するかどうかを参照してください。

25

私も同じ問題を抱えていました。 グーグルで何とかして、私は問題を解決します。

あなたがしなければならないのは、Hibernate 3.6 Migration Guideに指定されている「http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd」 に名前空間「http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd」を変更することです。

+1

ありがとうございました!私のために働いた。 –

0

Person.class、シリアライズを実装する必要があり、あなたが持っている主な問題は、休止状態3.6への移行ガイドであるようです!

お会いしましょう。

5

それは私がそのログに例外が表示されていないあなたは

http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd 
関連する問題