2016-03-14 3 views
0

Возможно ли использовать только файл hibernate.properties для настройки спящего режима без файла hibernate.cfg.xml?Конфигурация спящего режима только с файлом hibernate.properties. Без hibernate.cfg.xml

Я определил требуемые свойства в файле hibernate.properties.

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 показывает:

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} 

, но она по-прежнему просит cfg.xml:

Exception in thread "main" org.hibernate.internal.util.config.ConfigurationException: Could not locate cfg.xml resource [hibernate.cfg.xml] 
+0

Это возможно. см. этот [учебник] (http://viralpatel.net/blogs/introduction-to-hibernate-framework-architecture/). место 'hibernate.properties' в корне ваших приложений CLASSPATH – Bikku

ответ

1

Можно

SessionFactory factory = new Configuration().buildSessionFactory(); 
Смежные вопросы