如何解决我的第一个Hibernate项目的错误? [英] How to fix error with my first Hibernate project?

查看:90
本文介绍了如何解决我的第一个Hibernate项目的错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直试图做我的第一个Hibernate项目。我在项目中添加了以下库:



antlr-2.7.7
commons-collections-3.2.1
dom4j-1.6.1
hibernate-commons-annotations-4.0.1.Final
hibernate-core-4.1.0.Final
hibernate-jpa-2.0-api-1.0.1.Final
javassist-3.15 .0 -GA
jboss-logging-3.1.0.CR2
jboss-transaction-api_1.1_spec-1.0.0.Final
mysql-connector-java-5.1.18-bin



hibernate.cfg.xml:

 <?xml version = 1.0encoding =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;


@实体
公共类人物{

私人字符串名称;

@Id
private int number;

public Person(){}
$ b $ 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,密码为空。服务器是本地主机,并具有数据库测试与表人(CHAR(50)名称,INT(10)号码 - 主键)

Main.class:

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

它不起作用。我有一些错误:

  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>
信息:HHH000206:找不到hibernate.properties
03.03.2012 14:11:07 org.hibernate.cfg.Environment buildBytecodeProvider
INFO:HHH000021:字节码提供程序名称:javassist
03.03.2012 14:11:07 org.hibernate.cfg.Configuration configure
INFO:HHH000043:从资源配置:/hibernate.cfg.xml
03.03.2012 14:11:07 org.hibernate。 cfg.Configuration getConfigurationInputStream
INFO:HHH000040:配置资源:/hibernate.cfg.xml
03.03.2012 14:11:07 org.hibernate.internal.util.xml.DTDEntityResolver resolveEntity
WARN :HHH000223:识别过时的hibernate命名空间http://hibernate.sourceforge.net/。改为使用命名空间http://www.hibernate.org/dtd/。参考Hibernate 3.6迁移指南!
03.03.2012 14:11:07 org.hibernate.cfg.Configuration doConfigure
INFO:HHH000041:配置SessionFactory:null
03.03.2012 14:11:07 org.hibernate.service。 jdbc.connections.internal.DriverManagerConnectionProviderImpl配置
INFO:HHH000402:使用Hibernate内置连接池(不适用于生产!)
03.03.2012 14:11:07 org.hibernate.service.jdbc。 connections.internal.DriverManagerConnectionProviderImpl configure
INFO:HHH000115:Hibernate连接池大小:20
03.03.2012 14:11:07 org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO:HHH000006:Autocommit模式:false
03.03.2012 14:11:07 org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO:HHH000401:使用驱动程序[com.mysql.jdbc .driver]在URL [jdbc:mysql:// localhost / test]
03.03.2012 14:11:07 org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl confi gure
INFO:HHH000046:连接属性:{user = root,password = ****}
03.03.2012 14:11:08 org.hibernate.dialect.Dialect< init>
INFO:HHH000400:使用方言:org.hibernate.dialect.MySQL5Dialect
03.03.2012 14:11:08 org.hibernate.engine.transaction.internal.TransactionFactoryInitiator initiateService
INFO:HHH000399:使用默认事务策略(直接JDBC事务)
03.03.2012 14:11:08 org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory< init>
INFO:HHH000397:使用ASTQueryTranslatorFactory

我该如何解决它?谢谢。

解决方案

这些看起来都不像我的错误 - 它们只是日志行。这里唯一的问题是一个警告:


警告:HHH000223:已识别的过时hibernate命名空间 http://hibernate.sourceforge.net/ 。改为使用名称空间 http://www.hibernate.org/dtd/ 。请参考Hibernate 3.6迁移指南!


这只是一个警告 - 值得修复,但听起来好像不是很糟糕 em>紧急。

其他一切都只是在INFO级别......所以不要担心它们。继续前进,看看你的代码在数据库访问方面是否符合你的期望。


I have been tried to make my first Hibernate project. I added following libraries into my project:

antlr-2.7.7 commons-collections-3.2.1 dom4j-1.6.1 hibernate-commons-annotations-4.0.1.Final hibernate-core-4.1.0.Final hibernate-jpa-2.0-api-1.0.1.Final javassist-3.15.0-GA jboss-logging-3.1.0.CR2 jboss-transaction-api_1.1_spec-1.0.0.Final mysql-connector-java-5.1.18-bin

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;
    }
}

I have Denwer installed. Parameters for using: login - root, password is empty. Server is localhost, and has database "test" with table "person"(CHAR(50) name, INT(10) number - primary key)

Main.class:

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

It doesn't work. I have got some errors:

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

How can I fix it? Thank you.

解决方案

None of those look like errors to me - they're just log lines. The only "problem" is a warning here:

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!

That's only a warning - worth fixing, but it sounds like it's not terribly urgent.

Everything else is just at INFO level... so don't worry about them. Just keep going, and see whether your code does what you expect in terms of database access.

这篇关于如何解决我的第一个Hibernate项目的错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆