- 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.
- ASP.NET Core:Cloud-ready,Enterprise Web Application Development
- JavaScript+DHTML語法與范例詳解詞典
- Learning Spring 5.0
- Vue.js入門與商城開發(fā)實(shí)戰(zhàn)
- PyTorch Artificial Intelligence Fundamentals
- Data Analysis with IBM SPSS Statistics
- Learning DHTMLX Suite UI
- 劍指Java:核心原理與應(yīng)用實(shí)踐
- R語言與網(wǎng)絡(luò)輿情處理
- 速學(xué)Python:程序設(shè)計(jì)從入門到進(jìn)階
- Mobile Device Exploitation Cookbook
- C++程序設(shè)計(jì)教程(第2版)
- Natural Language Processing with Python Quick Start Guide
- MySQL 8從零開始學(xué)(視頻教學(xué)版)
- 大學(xué)計(jì)算機(jī)應(yīng)用基礎(chǔ)(Windows 7+Office 2010)(IC3)