내용으로 건너뛰기
권남
사용자 도구
로그인
사이트 도구
검색
도구
문서 보기
이전 판
역링크
최근 바뀜
미디어 관리자
사이트맵
로그인
>
최근 바뀜
미디어 관리자
사이트맵
추적:
java:jpa:persistence.xml
이 문서는 읽기 전용입니다. 원본을 볼 수는 있지만 바꿀 수는 없습니다. 문제가 있다고 생각하면 관리자에게 문의하세요.
====== JPA persistence.xml ====== * [[http://www.oracle.com/webfolder/technetwork/jsc/xml/ns/persistence/index.html|JPA Persistence XML Schemas]] * [[http://docs.oracle.com/cd/E16439_01/doc.1013/e13981/cfgdepds005.htm|Configuring the persistence.xml File]] * ''META-INF/persistence.xml'' 위치 고정이다. 파일은 여러개일 수 있다. 모두 읽고 persistence-unit-name으로 구분한다. * 위치와 파일명을 변경하고자 한다면 스스로 XML 파일로부터 ''PersistenceUnitInfo'' 인스턴스를 생성하여 넘기는 방법만 있는 듯 하다. Spring이 이렇게 처리하는 듯. * [[http://docs.jboss.org/hibernate/core/4.3/devguide/en-US/html/apa.html|Appendix A. Configuration properties]] ===== 기본 persistence.xml 뼈대 ===== ==== 2.0 ==== <code xml> <?xml version="1.0" encoding="utf-8"?> <persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd" version="2.0"> <persistence-unit name="unitname" transaction-type="RESOURCE_LOCAL"> <provider>org.hibernate.ejb.HibernatePersistence</provider> <exclude-unlisted-classes>true</exclude-unlisted-classes> <mapping-file>ormap.xml</mapping-file> <!-- 필요할 경우 --> <class>org.acme.Employee</class> <class>org.acme.Person</class> <class>org.acme.Address</class> <properties> <property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect" /> <property name="hibernate.hbm2ddl.auto" value="create-drop"/> <property name="hibernate.show_sql" value="true" /> <property name="hibernate.format_sql" value="true" /> <property name="javax.persistence.jdbc.driver" value="org.h2.Driver"/> <property name="javax.persistence.jdbc.url" value="jdbc:h2:mem:db1"/> <property name="javax.persistence.jdbc.user" value="sa"/> <property name="javax.persistence.jdbc.password" value=""/> </properties> </persistence-unit> </persistence> </code> ==== 2.1 ==== <code xml> <?xml version="1.0" encoding="UTF-8" ?> <persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd" version="2.1"> <persistence-unit name="unitname" transaction-type="RESOURCE_LOCAL"> <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider> ... </persistence-unit> </persistence> </code> * ''exclude-unlisted-classes''를 ''true''로 하면 ''<class>xx</class>''로 명시한 클래스만 엔티티로 로딩한다. ''false''이면 CLASSPATH에서 자동 탐색한다. * 현재 Hibernate가 Java 클래스와 ''persistence.xml'' Resource가 존재하는 Classpath가 다를 경우 Entity 자동인식을 못한다. 따라서 ''<class>'' 명시가 더 확실할 수 있다. * JPA 2.1(Hibernate 4.3)에서 PersistenceProvider 이름이 변경되었다. ===== 기본 테스트 ===== JPA에 대한 기본 테스트는 다음과 같이 할 수 있다. ''/src/test/resources/META-INF/persistence.xml''이 있다고 간주한다. <code java> @Slf4j public class GenericJPATest { private static EntityManagerFactory emf; private EntityManager em; private EntityTransaction transaction; @BeforeClass public static void setUpClass() throws Exception { // 필요한 경우 아래에서 Map으로 프라퍼티들을 넘길 수 있다. emf = Persistence.createEntityManagerFactory("[test-persistence-unit]"); } @AfterClass public static void tearDownClass() throws Exception { if (emf != null) { emf.close(); } } @Before public void setUp() throws Exception { em = emf.createEntityManager(); transaction = em.getTransaction(); } @After public void tearDown() throws Exception { if (em != null) { em.close(); } } @Test public void test() throws Exception { transaction과 em을 사용해 테스트 } } </code>
java/jpa/persistence.xml.txt
· 마지막으로 수정됨: 2015/08/25 13:57 저자
kwon37xi
문서 도구
문서 보기
이전 판
역링크
맨 위로