양쪽 이전 판
이전 판
다음 판
|
이전 판
|
wiki:spring:jap [2020/12/21 10:16] hylee |
— (현재) |
====== Spring에 JPA 적용하기 ====== | |
<WRAP left notice 80%> | |
* description : | |
* author : 도봉산핵주먹 | |
* email : hylee@repia.com | |
* lastupdate : 2020-12-16 | |
</WRAP> | |
<WRAP clear/> | |
| |
| |
| |
| |
===== 적용파일 목록 ===== | |
| |
* context-hibernate.xml | |
* context-jpa-respository.xml | |
| |
| |
===== context-hibernate.xml ===== | |
| |
> Tip | |
| |
아래 코드에서 3곳만 고치면 된다. \\ | |
| |
''<property name="dataSource" ref="" />'' | |
* context-datasource.xml 에 JPA로 사용할 DB정보의 bean ID \\ | |
''<property name="packagesToScan" value="" >'' | |
* values는 패키지 정보를 입력 \\ | |
''<prop key="hibernate.dialect">'' | |
* JPA가 적용되는 DB 정보와 맞게 입력 | |
* 정보는 아래표 참고 | |
\\ | |
\\ | |
<code xml> | |
| |
<?xml version="1.0" encoding="utf-8"?> | |
<beans xmlns="http://www.springframework.org/schema/beans" | |
xmlns:context="http://www.springframework.org/schema/context" | |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd | |
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd"> | |
| |
<!-- 컨테이너가 관리하는 EntityManager 생성, @PersistenceContext와 함께 사용 --> | |
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> | |
<property name="dataSource" ref="egov.dataSource" /> | |
<!-- 어노테이션 매핑정보 스캔 --> | |
<property name="packagesToScan" value="com" /> | |
<!-- 구현체별 자체 기능을 표준화 --> | |
<property name="jpaVendorAdapter"> | |
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"> | |
<property name="showSql" value="true" /> | |
<property name="generateDdl" value="true" /> | |
</bean> | |
</property> | |
<!-- persistence.xml 설정정보와 함께 사용가능 --> | |
<property name="jpaProperties"> | |
<props> | |
<!-- <prop key="hibernate.ejb.naming_strategy">org.hibernate.cfg.EJB3NamingStrategy</prop> --> | |
<prop key="hibernate.ejb.naming_strategy">org.hibernate.cfg.ImprovedNamingStrategy</prop> | |
<!-- hibernate 5 버전에서의 세팅 (4 버전은 위에껄 사용)- | |
<prop key="hibernate.naming.implicit-strategy">org.hibernate.boot.model.naming.ImplicitNamingStrategyLegacyJpaImpl</prop> | |
<prop key="hibernate.naming.physical-strategy">org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl</prop> | |
--> | |
<prop key="hibernate.hbm2ddl.auto">validate</prop> | |
<prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop> | |
<prop key="hibernate.show_sql">true</prop> | |
<prop key="hibernate.format_sql">true</prop> | |
<prop key="hibernate.use_sql_comments">true</prop> | |
<prop key="hibernate.jdbc.batch_size">5</prop> | |
</props> | |
</property> | |
</bean> | |
| |
</beans> | |
| |
| |
| |
</code> | |
| |
\\ | |
\\ | |
==== hibernate.dialect 정보 ==== | |
| |
| |
| |
^ ^ ^ | |
| DB2 | org.hibernate.dialect.DB2Dialect | | |
| DB2 AS/400 | org.hibernate.dialect.DB2400Dialect | | |
| DB2 OS390 | org.hibernate.dialect.DB2390Dialect | | |
| PostgreSQL | org.hibernate.dialect.PostgreSQLDialect | | |
| MySQL5 | org.hibernate.dialect.MySQL5Dialect | | |
| MySQL5 with InnoDB | org.hibernate.dialect.MySQL5InnoDBDialect | | |
| MySQL with MyISAM | org.hibernate.dialect.MySQLMyISAMDialect | | |
| Oracle (any version) | org.hibernate.dialect.OracleDialect | | |
| Oracle 9i | org.hibernate.dialect.Oracle9iDialect | | |
| Oracle 10g | org.hibernate.dialect.Oracle10gDialect | | |
| Oracle 11g | org.hibernate.dialect.Oracle10gDialect | | |
| Sybase | org.hibernate.dialect.SybaseASE15Dialect | | |
| Sybase Anywhere | org.hibernate.dialect.SybaseAnywhereDialect | | |
| Microsoft SQL Server 2000 | org.hibernate.dialect.SQLServerDialect | | |
| Microsoft SQL Server 2005 | org.hibernate.dialect.SQLServer2005Dialect | | |
| Microsoft SQL Server 2008 | org.hibernate.dialect.SQLServer2008Dialect | | |
| SAP DB | org.hibernate.dialect.SAPDBDialect | | |
| Informix | org.hibernate.dialect.InformixDialect | | |
| HypersonicSQL | org.hibernate.dialect.HSQLDialect | | |
| H2 Database | org.hibernate.dialect.H2Dialect | | |
| Ingres | org.hibernate.dialect.IngresDialect | | |
| Progress | org.hibernate.dialect.ProgressDialect | | |
| Mckoi SQL | org.hibernate.dialect.MckoiDialect | | |
| Interbase | org.hibernate.dialect.InterbaseDialect | | |
| Pointbase | org.hibernate.dialect.PointbaseDialect | | |
| FrontBase | org.hibernate.dialect.FrontbaseDialect | | |
| Firebird | org.hibernate.dialect.FirebirdDialect | | |
| |
| |
| |
| |
| |
| |
===== context-jpa-respository.xml ===== | |
| |
> Tip | |
| |
아래 코드에서 한개만 고치면 된다. \\ | |
| |
''<jpa:repositories base-package="">'' | |
* base-package="" 는 패키지 정보 입력\\ | |
\\ | |
\\ | |
<code xml> | |
| |
<?xml version="1.0" encoding="UTF-8"?> | |
<beans xmlns="http://www.springframework.org/schema/beans" | |
xmlns:jpa="http://www.springframework.org/schema/data/jpa" | |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd | |
http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd"> | |
| |
<jpa:repositories base-package="com"></jpa:repositories> | |
| |
</beans> | |
| |
| |
</code> | |
| |
| |
===== POM.xml ===== | |
| |
<code xml> | |
| |
<properties> | |
<egovframework.jpa.version>3.7.0</egovframework.jpa.version> | |
<hibernate.version>4.3.11.Final</hibernate.version> | |
</properties> | |
<dependencies> | |
<dependency> | |
<groupId>egovframework.rte</groupId> | |
<artifactId>egovframework.rte.psl.data.jpa</artifactId> | |
<version>${egovframework.jpa.version}</version> | |
</dependency> | |
| |
<!-- Hibernate --> | |
<dependency> | |
<groupId>org.hibernate</groupId> | |
<artifactId>hibernate-core</artifactId> | |
<version>${hibernate.version}</version> | |
</dependency> | |
| |
<dependency> | |
<groupId>org.hibernate</groupId> | |
<artifactId>hibernate-validator</artifactId> | |
<version>5.4.2.Final</version> | |
</dependency> | |
<dependency> | |
<groupId>org.springframework.data</groupId> | |
<artifactId>spring-data-jpa</artifactId> | |
<version>1.11.10.RELEASE</version> | |
<exclusions> | |
<exclusion> | |
<groupId>org.slf4j</groupId> | |
<artifactId>slf4j-api</artifactId> | |
</exclusion> | |
<exclusion> | |
<groupId>org.slf4j</groupId> | |
<artifactId>jcl-over-slf4j</artifactId> | |
</exclusion> | |
</exclusions> | |
</dependency> | |
</dependencies> | |
| |
</code> | |
| |
| |
| |
| |
{{tag>도봉산핵주먹 spring jpa}} | |