Reputation: 300
Is it possible to use only hibernate.properties
file to configure hibernate without any hibernate.cfg.xml
file?
I have defined the required properties in hibernate.properties file.
hibernate.dialect=org.hibernate.dialect.MySQLDialect
hibernate.connection.driver_class=com.mysql.jdbc.Driver
hibernate.connection.url=jdbc:mysql://localhost:3306/dev
hibernate.connection.username=root
hibernate.connection.password=
hibernate.connection.pool_size=1
hibernate.show_sql=true
hibernate.format_sql=true
hibernate.cache.provider_class=org.hibernate.cache.NoCacheProvider
hibernate.hbm2ddl.auto=update
Hibernate shows :
Loaded properties from resource hibernate.properties: {hibernate.connection.driver_class=com.mysql.jdbc.Driver, hibernate.cache.provider_class=org.hibernate.cache.NoCacheProvider, hibernate.dialect=org.hibernate.dialect.MySQLDialect, hibernate.format_sql=true, hibernate.connection.username=root, hibernate.hbm2ddl.auto=update, hibernate.connection.url=jdbc:mysql://localhost:3306/dev, hibernate.bytecode.use_reflection_optimizer=false, hibernate.show_sql=true, hibernate.connection.password=****, hibernate.connection.pool_size=1}
but it still asks for cfg.xml
:
Exception in thread "main" org.hibernate.internal.util.config.ConfigurationException: Could not locate cfg.xml resource [hibernate.cfg.xml]
Upvotes: 0
Views: 683
Reputation: 19956
It is possible
SessionFactory factory = new Configuration().buildSessionFactory();
Upvotes: 1