- Java Hibernate Cookbook
- Yogesh Prajapati Vishal Ranapariya
- 295字
- 2021-07-16 19:59:46
Providing a hibernate configuration using the properties file
This is another way to configure hibernate; here, we will create a file with the .properties
extension. Usually called hibernate.properties
, this file is a replacement for hibernate.cfg.xml
. You can use any approach (either cfg.xml
or the properties file). However, the properties file is better for startup, and it is the easiest approach to get started quickly.
This is a simpler representation of an XML file. Hibernate searches for the XML file or the properties file at startup to find the configuration in your classpath. We can use any one of these options. You can use both of them at the same time, but this is uncommon because hibernate gives priority to the XML file over properties; the properties file is simply ignored in such cases.
How to do it…
Now, we will create a file called hibernate.properties
in our classpath and write the following properties in the file. The following code represents hibernate.cfg.xml
in the hibernate.properties
file:
… hibernate.dialect=org.hibernate.dialect.MySQLDialect hibernate.connection.driver_class=com.mysql.jdbc.Driver hibernate.connection.url=jdbc:mysql://localhost:3306/kode12 hibernate.connection.username=root hibernate.connection.password=root show_sql=true hbm2ddl.auto=update …
How it works…
When we create an instance of the Configuration
class, it will look for hibernate.cfg.xml
or hibernate.properties
in our classpath. If we use a .properties
file, it'll get all of the property defined in the file, rather than create a Configuration
object.
- Vue 3移動Web開發與性能調優實戰
- Getting Started with PowerShell
- 碼上行動:零基礎學會Python編程(ChatGPT版)
- 深入理解Java7:核心技術與最佳實踐
- Mathematica Data Analysis
- 深入剖析Java虛擬機:源碼剖析與實例詳解(基礎卷)
- Python 3.7從入門到精通(視頻教學版)
- 從零開始:UI圖標設計與制作(第3版)
- 分布式數據庫原理、架構與實踐
- Hands-On Robotics Programming with C++
- Learning Concurrency in Python
- Spark技術內幕:深入解析Spark內核架構設計與實現原理
- IBM RUP參考與認證指南
- Learning Shiny
- 系統分析師UML用例實戰