Hibernate.cfg.xml은?
아래와 같이 예시를 볼수있습니다.
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- JDBC Database connection settings -->
<property name="hibernate.connection.driver_class">com.mysql.cj.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/your_database</property>
<property name="hibernate.connection.username">your_username</property>
<property name="hibernate.connection.password">your_password</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<!-- JDBC connection pool settings -->
<property name="hibernate.c3p0.min_size">5</property>
<property name="hibernate.c3p0.max_size">20</property>
<property name="hibernate.c3p0.timeout">300</property>
<property name="hibernate.c3p0.max_statements">50</property>
<property name="hibernate.c3p0.idle_test_period">3000</property>
<!-- Specify dialect -->
<property name="hibernate.show_sql">true</property>
<property name="hibernate.format_sql">true</property>
<!-- Echo all executed SQL to stdout -->
<property name="hibernate.hbm2ddl.auto">update</property>
</session-factory>
</hibernate-configuration>
hibernate.cfg.xml는 application.yml으로도 표현이 가능한데 둘의 차이는
hibernate가 지원하는 설정cfg.xml을 사용할것인지? 스프링에서 지원하는 application.yml을 사용해서 지정할지 이다
아래는 application.yml파일로 위와같은 설정들을 쓸땐 어떻게 써야하는지에 대한 예제이다.
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/your_database
username: your_username
password: your_password
jpa:
hibernate:
dialect: org.hibernate.dialect.MySQLDialect
show-sql: true
format-sql: true
hbm2ddl:
auto: update
properties:
hibernate:
c3p0:
min-size: 5
max-size: 20
timeout: 300
max-statements: 50
idle-test-period: 3000
이번 글은 여기까지 작성하며
다음 글로 hibernate의 ddl auto의 위험성에 대해 다뤄 보겠습니다.
감사합니다.
[JPA&Hibernate] 지연로딩을 가능하게 하는 Proxy란? (1) | 2023.12.28 |
---|---|
[스프링] Hibernate DDL AUTO 주의할점(단점) (0) | 2023.12.24 |
[SpringBoot] JPA (Java Persistence API)란? (1) | 2023.12.21 |
[Spring] ORM(Object Relational Mapping)란? (0) | 2023.12.21 |
[Spring Boot]MVC 와 MVC2 패턴이란? (0) | 2023.12.19 |