2

I have a.properties file with configurations. How can I point to it in the code?

It is written everywhere that it is only possible to transmit .XML file. Why can't I use properties?

hibernate.properties

hibernate.connection.driver_class = com.mysql.jdbc.Driver
hibernate.dialect = org.hibernate.dialect.MySQLDialect
hibernate.connection.url = jdbc:mysql://localhost:3306/db_example?serverTimezone=Europe/Moscow
hibernate.connection.username = root
hibernate.connection.password = root
hibernate.show_sql = true
hibernate.hbm2ddl.auto = create

Hibernate 5

public class HiberUtil {

private static SessionFactory sessionFactory;

static {
    final StandardServiceRegistry registry = new StandardServiceRegistryBuilder()
            .configure()
            .build();

    try {
        sessionFactory = new MetadataSources(registry)
                .buildMetadata()
                .buildSessionFactory();
    }catch (Exception e){
        StandardServiceRegistryBuilder.destroy(registry);
    }
}

public static SessionFactory getSessionFactory() {
    return sessionFactory;
}
hdbgage
  • 123
  • 2
  • 8
  • can you please clarify what you mean by 'transmit the.xml file'! What are you trying to achieve here? Being as clear as possible in your question title and description helps you get an answer faster. Thanks – pedram bashiri Apr 16 '20 at 19:59
  • I want to access the "hibernate.properties" file from the code. But I don't understand. how to do this. In version 4, you could access it from Configuration. And in version 5, I don't know – hdbgage Apr 16 '20 at 20:05
  • By default, Hibernate searches for". xml". And I want ". properties – hdbgage Apr 16 '20 at 20:06
  • 1
    Look at the answer to https://stackoverflow.com/questions/25684785/how-to-read-database-configuration-parameter-using-properties-file-in-hibernate – pedram bashiri Apr 16 '20 at 20:52

0 Answers0