Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
724 views
in Technique[技术] by (71.8m points)

java - how to fix the error: "INFO: HHH000206: hibernate.properties not found"?

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...