jpa entity Manager 구성

5066 단어
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" 
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:p="http://www.springframework.org/schema/p"
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:tx="http://www.springframework.org/schema/tx"
	xmlns:task="http://www.springframework.org/schema/task"
	xsi:schemaLocation="http://www.springframework.org/schema/beans 
						http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
						http://www.springframework.org/schema/context 
						http://www.springframework.org/schema/context/spring-context-3.1.xsd
						http://www.springframework.org/schema/tx 
						http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
						http://www.springframework.org/schema/task
						http://www.springframework.org/schema/task/spring-task-3.1.xsd">
	<context:component-scan base-package="com.sharp.ssh">
		<context:include-filter type="regex" expression="com.sharp.ssh.service.dao.impl.*"/>
		<context:include-filter type="regex" expression="com.sharp.ssh.service.service.impl.*"/>
	</context:component-scan>
	<context:property-override location="classpath:dataSource.properties"/>
	<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"/>



	<!-- JPA        -->
	<bean id="entityManagerFactory"
		class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
		<property name="dataSource" ref="dataSource" />
		<property name="persistenceProvider" ref="persistenceProvider" />
		<property name="jpaVendorAdapter" ref="jpaVendorAdapter" />
		<property name="jpaDialect" ref="jpaDialect" />
		<property name="packagesToScan" value="com.sharp.ssh.domain" />

		<property name="jpaProperties">
			<props>
				<prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>
				<prop key="hibernate.max_fetch_depth">3</prop>
				<prop key="hibernate.jdbc.fetch_size">18</prop>
				<prop key="hibernate.jdbc.batch_size">10</prop>
				<prop key="hibernate.hbm2ddl.auto">update</prop>
				<prop key="hibernate.show_sql">true</prop>
				<prop key="hibernate.format_sql">true</prop>
				<prop key="javax.persistence.validation.mode">none</prop>
			</props>
		</property>
	</bean>
	
	
	<!--              -->
	<bean id="persistenceProvider" class="org.hibernate.ejb.HibernatePersistence" />
	
	
	<!--     JPA          -->
	<bean id="jpaVendorAdapter" class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"
		p:database="ORACLE" />
		
		
	<!--            -->
	<bean id="jpaDialect" class="org.springframework.orm.jpa.vendor.HibernateJpaDialect" />

	<!--       -->
	<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"
		p:entityManagerFactory-ref="entityManagerFactory" />
	
	<tx:annotation-driven/>
	
	
	<!-- <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"
		p:dataSource-ref="dataSource" p:packagesToScan="com.sharp.ssh.domain">
		<property name="hibernateProperties">
			<props>
				<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.hbm2ddl.auto">update</prop>
				<prop key="javax.persistence.validation.mode">none</prop>
			</props>
		</property>
	</bean>
	<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"
		p:sessionFactory-ref="sessionFactory"/>
	<tx:annotation-driven/> -->
</beans>

dao 주입:
package com.sharp.common.dao.impl;

import java.io.Serializable;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.springframework.dao.DataAccessException;

import com.sharp.common.dao.IBasicDao;
public class BasicDaoImpl<T>  implements IBasicDao<T>
{
	@PersistenceContext
	private EntityManager em;
	
	public void save(T entity) throws DataAccessException
	{
		em.persist(entity);
	}

	@Override
	public T get(Class<T> cls, Serializable id)
	{
		return em.find(cls, id);
	}

}

좋은 웹페이지 즐겨찾기