如何修复错误:“INFO:HHH000206:找不到hibernate.properties”? [英] how to fix the error: "INFO: HHH000206: hibernate.properties not found"?

查看:134
本文介绍了如何修复错误:“INFO:HHH000206:找不到hibernate.properties”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图测试休眠配置是否正常工作。我试过了,但出现错误:

 信息:HHH000206:找不到hibernate.properties 
$ b hibernate配置文件[使用xml]

 <?xml version =1.0encoding =UTF-8?> 
<!DOCTYPE hibernate-configuration PUBLIC - // Hibernate / Hibernate配置DTD 3.0 // EN
http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd\"> ;
< hibernate-configuration>
< session-factory name =>
< property name =hibernate.connection.driver_class> com.mysql.jdbc.Driver< / property>
< property name =hibernate.connection.url> jdbc:mysql:// localhost:3306< / property>
< property name =hibernate.connection.username>根< / property>
< property name =hibernate.default_schema> explorecalifornia< / property>
< property name =hibernate.dialect> org.hibernate.dialect.MySQLDialect< / property>
< property name =hibernate.format_sql> true< / property>
< property name =hibernate.connection.password> abc123< / property>
< / session-factory>
< / hibernate-configuration>

[2]一个hibernate实用程序类

  public class HibernateUtilities {

private static SessionFactory sessionFactory;
private static ServiceRegistry serviceRegistry;

static {
try {
Configuration configuration = new Configuration()。configure();

serviceRegistry = new ServiceRegistryBuilder()。applySettings(configuration.getProperties())。buildServiceRegistry();
sessionFactory = configuration.buildSessionFactory(serviceRegistry);


catch(HibernateException异常){
System.out.println(Problem creating session factory);



public static SessionFactory getSessionFactory(){
return sessionFactory;
}

public static void setSessionFactory(SessionFactory sessionFactory){
HibernateUtilities.sessionFactory = sessionFactory;
}


}



<3>主程序:

  import org.hibernate.Session; 

public class Program {

public static void main(String [] args){
System.out.println(Hibernate);

会话会话= HibernateUtilities.getSessionFactory()。openSession();
session.close();

}

}

但是我得到了以下是我运行该程序时的情况:

  Hibernate 
Sep 29,2013 10:47:15 PM org。 hibernate.annotations.common.Version< clinit>
INFO:HCANN000001:Hibernate Commons Annotations {4.0.2.Final}
Sep 29,2013 10:47:15 PM org.hibernate.Version logVersion
INFO:HHH000412:Hibernate Core {4.2 .5.Final}
Sep 29,2013 10:47:15 PM org.hibernate.cfg.Environment< clinit>
INFO:HHH000206:找不到hibernate.properties
2013-09-29 10:47:15 org.hibernate.cfg.Environment buildBytecodeProvider
INFO:HHH000021:字节码提供程序名称:javassist
Sep 29,2013 10:47:15 PM org.hibernate.cfg.Configuration configure
INFO:HHH000043:从资源配置:/hibernate.cfg.xml
Sep 29,2013 10:47: 15下午org.hibernate.cfg.Configuration getConfigurationInputStream
INFO:HHH000040:配置资源:/hibernate.cfg.xml
创建会话工厂的问题
线程main中的异常java.lang.NullPointerException
at com.simpleprogrammer.Program.main(Program.java:10)

解决方案我尝试了Google,并运用了我找到的方式。但仍然无法解决问题。任何人都可以帮助我吗?

解决方案

这只是一条INFO消息,告诉您没有 hibernate.properties 文件。这个属性文件不是必需的,所以它不会阻止你的应用程序工作。



如果你想知道是什么导致 SessionFactory 创建失败,您需要将您的catch块更改为:
$ b

  catch(HibernateException异常){
System.out.println(创建会话工厂的问题);
exception.printStackTrace();

$ / code>

您应该使用日志框架。


I tried to test whether the hibernate configuration is working properly. I tried but I got an error:

INFO: HHH000206: hibernate.properties not found

To do this: I create:

[1] hibernate configuration file [using xml]

<?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 name="">
  <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
  <property name="hibernate.connection.url">jdbc:mysql://localhost:3306</property>
  <property name="hibernate.connection.username">root</property>
  <property name="hibernate.default_schema">explorecalifornia</property>
  <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
  <property name="hibernate.format_sql">true</property>
  <property name="hibernate.connection.password">abc123</property>
 </session-factory>
</hibernate-configuration>

[2] A hibernate utility class

public class HibernateUtilities {

    private static SessionFactory sessionFactory;
    private static ServiceRegistry serviceRegistry;

    static{
        try{
            Configuration configuration = new Configuration().configure();

            serviceRegistry = new ServiceRegistryBuilder().applySettings(configuration.getProperties()).buildServiceRegistry();
            sessionFactory = configuration.buildSessionFactory(serviceRegistry);
        }

        catch(HibernateException exception){
            System.out.println("Problem creating session factory");
        }
    }

    public static SessionFactory getSessionFactory() {
        return sessionFactory;
    }

    public static void setSessionFactory(SessionFactory sessionFactory) {
        HibernateUtilities.sessionFactory = sessionFactory;
    }


}

[3] The main program:

import org.hibernate.Session;

    public class Program {

        public static void main(String[] args) {
            System.out.println("Hibernate");

            Session session = HibernateUtilities.getSessionFactory().openSession();
            session.close();

        }

    }

But i got the following thing when I run the program:

Hibernate
Sep 29, 2013 10:47:15 PM org.hibernate.annotations.common.Version <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {4.0.2.Final}
Sep 29, 2013 10:47:15 PM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {4.2.5.Final}
Sep 29, 2013 10:47:15 PM org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
Sep 29, 2013 10:47:15 PM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
Sep 29, 2013 10:47:15 PM org.hibernate.cfg.Configuration configure
INFO: HHH000043: Configuring from resource: /hibernate.cfg.xml
Sep 29, 2013 10:47:15 PM org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: HHH000040: Configuration resource: /hibernate.cfg.xml
Problem creating session factory
Exception in thread "main" java.lang.NullPointerException
    at com.simpleprogrammer.Program.main(Program.java:10)

To solve this I tried Google and apply the ways which i found. but still i could not solve the problem. Can anybody please help me?

解决方案

That's only an INFO message telling that you don't have a hibernate.properties file. This property file is not mandatory and so it's not what prevents your application from working.

If you want to know what caused the SessionFactory creation failure, you need to change your catch block to:

catch(HibernateException exception){
     System.out.println("Problem creating session factory");
     exception.printStackTrace();
}

You should use a logging framework instead.

这篇关于如何修复错误:“INFO:HHH000206:找不到hibernate.properties”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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