{
6 |
7 | }
8 |
--------------------------------------------------------------------------------
/src/main/java/com/example/r_mapping/onetoone/OnetoOneController.java:
--------------------------------------------------------------------------------
1 | package com.example.r_mapping.onetoone;
2 |
3 | import org.springframework.beans.factory.annotation.Autowired;
4 | import org.springframework.stereotype.Controller;
5 | import org.springframework.ui.Model;
6 | import org.springframework.web.bind.annotation.RequestMapping;
7 | import org.springframework.web.bind.annotation.ResponseBody;
8 |
9 | import com.example.App;
10 |
11 | @Controller
12 | public class OnetoOneController {
13 | @Autowired MemberRepository repository;
14 |
15 | @RequestMapping("onetoone")
16 | public String member(Model model){
17 | Member member = new Member();
18 | member.setName("arahansa");
19 | MemberDetail memberDetail = new MemberDetail();
20 | memberDetail.setAddress("incheon");
21 | member.setMemberDetail(memberDetail);
22 | repository.save(member);
23 | model.addAttribute("data", member.toString()
24 | +" "
25 | +" "
26 | +" "
27 | );
28 | return App.index;
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | server.port: 9000
2 | spring.profiles.active: local
3 |
4 | spring:
5 | view:
6 | prefix: /WEB-INF/views/
7 | suffix: .jsp
--------------------------------------------------------------------------------
/src/main/resources/db-config.yml:
--------------------------------------------------------------------------------
1 | ---
2 | spring.profiles: test2
3 |
4 | spring.datasource:
5 | url: jdbc:mysql://localhost:3306/learnspringdatajpa
6 | driverClassName: com.mysql.jdbc.Driver
7 | username: arahansa
8 | password: 1234
9 | spring.jpa:
10 | database-platform: org.hibernate.dialect.MySQL5InnoDBDialect
11 | show-sql: true
12 | ddl-auto: create-drop
13 |
14 | ---
15 | spring.profiles: test
16 |
17 | spring.datasource:
18 | url: jdbc:h2:tcp://localhost/~/learnspringdatajpa;DB_CLOSE_ON_EXIT=FALSE
19 | driverClassName: org.h2.Driver
20 | username: sa
21 | password:
22 | spring.jpa.database-platform: org.hibernate.dialect.H2Dialect
23 |
24 | ---
25 | spring.profiles: local
26 |
27 | spring.datasource:
28 | url: jdbc:h2:~/learningspringdatajpa;DB_CLOSE_ON_EXIT=FALSE
29 | driverClassName: org.h2.Driver
30 | username: sa
31 | password:
32 | spring.jpa.database-platform: org.hibernate.dialect.H2Dialect
33 | spring.jpa.show-sql: true
34 | spring.jpa.hibernate.ddl-auto: create-drop
35 |
--------------------------------------------------------------------------------
/src/main/resources/locale/messages_kr_KR.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | messages.properties
5 | 주소의 최대 길이는 {1} 자입니다.
6 |
7 |
8 |
--------------------------------------------------------------------------------
/src/main/resources/rebel.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/src/main/resources/static/images/inheritancesingle.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/arahansa/learnspringdatajpa/262c9d658ad8d2f59947691edb5df8b304a9b4ae/src/main/resources/static/images/inheritancesingle.png
--------------------------------------------------------------------------------
/src/main/resources/static/images/inheritancesingle2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/arahansa/learnspringdatajpa/262c9d658ad8d2f59947691edb5df8b304a9b4ae/src/main/resources/static/images/inheritancesingle2.png
--------------------------------------------------------------------------------
/src/main/resources/static/images/inheritancesingle3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/arahansa/learnspringdatajpa/262c9d658ad8d2f59947691edb5df8b304a9b4ae/src/main/resources/static/images/inheritancesingle3.png
--------------------------------------------------------------------------------
/src/main/resources/static/images/justone.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/arahansa/learnspringdatajpa/262c9d658ad8d2f59947691edb5df8b304a9b4ae/src/main/resources/static/images/justone.png
--------------------------------------------------------------------------------
/src/main/resources/static/images/manytomany.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/arahansa/learnspringdatajpa/262c9d658ad8d2f59947691edb5df8b304a9b4ae/src/main/resources/static/images/manytomany.png
--------------------------------------------------------------------------------
/src/main/resources/static/images/manytomany2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/arahansa/learnspringdatajpa/262c9d658ad8d2f59947691edb5df8b304a9b4ae/src/main/resources/static/images/manytomany2.png
--------------------------------------------------------------------------------
/src/main/resources/static/images/manytomany3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/arahansa/learnspringdatajpa/262c9d658ad8d2f59947691edb5df8b304a9b4ae/src/main/resources/static/images/manytomany3.png
--------------------------------------------------------------------------------
/src/main/resources/static/images/mappedsupper.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/arahansa/learnspringdatajpa/262c9d658ad8d2f59947691edb5df8b304a9b4ae/src/main/resources/static/images/mappedsupper.png
--------------------------------------------------------------------------------
/src/main/resources/static/images/mappedsupper2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/arahansa/learnspringdatajpa/262c9d658ad8d2f59947691edb5df8b304a9b4ae/src/main/resources/static/images/mappedsupper2.png
--------------------------------------------------------------------------------
/src/main/resources/static/images/mappedsupper3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/arahansa/learnspringdatajpa/262c9d658ad8d2f59947691edb5df8b304a9b4ae/src/main/resources/static/images/mappedsupper3.png
--------------------------------------------------------------------------------
/src/main/resources/static/images/me.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/arahansa/learnspringdatajpa/262c9d658ad8d2f59947691edb5df8b304a9b4ae/src/main/resources/static/images/me.jpg
--------------------------------------------------------------------------------
/src/main/resources/static/images/onetomany.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/arahansa/learnspringdatajpa/262c9d658ad8d2f59947691edb5df8b304a9b4ae/src/main/resources/static/images/onetomany.png
--------------------------------------------------------------------------------
/src/main/resources/static/images/onetomany2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/arahansa/learnspringdatajpa/262c9d658ad8d2f59947691edb5df8b304a9b4ae/src/main/resources/static/images/onetomany2.png
--------------------------------------------------------------------------------
/src/main/resources/static/images/onetomany3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/arahansa/learnspringdatajpa/262c9d658ad8d2f59947691edb5df8b304a9b4ae/src/main/resources/static/images/onetomany3.png
--------------------------------------------------------------------------------
/src/main/resources/static/images/onetoone.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/arahansa/learnspringdatajpa/262c9d658ad8d2f59947691edb5df8b304a9b4ae/src/main/resources/static/images/onetoone.png
--------------------------------------------------------------------------------
/src/main/resources/static/images/onetoone2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/arahansa/learnspringdatajpa/262c9d658ad8d2f59947691edb5df8b304a9b4ae/src/main/resources/static/images/onetoone2.png
--------------------------------------------------------------------------------
/src/main/resources/static/images/onetoone3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/arahansa/learnspringdatajpa/262c9d658ad8d2f59947691edb5df8b304a9b4ae/src/main/resources/static/images/onetoone3.png
--------------------------------------------------------------------------------
/src/main/resources/static/images/secondary.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/arahansa/learnspringdatajpa/262c9d658ad8d2f59947691edb5df8b304a9b4ae/src/main/resources/static/images/secondary.png
--------------------------------------------------------------------------------
/src/main/resources/static/images/secondary2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/arahansa/learnspringdatajpa/262c9d658ad8d2f59947691edb5df8b304a9b4ae/src/main/resources/static/images/secondary2.png
--------------------------------------------------------------------------------
/src/main/resources/static/images/secondary3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/arahansa/learnspringdatajpa/262c9d658ad8d2f59947691edb5df8b304a9b4ae/src/main/resources/static/images/secondary3.png
--------------------------------------------------------------------------------
/src/main/webapp/WEB-INF/views/index.jsp:
--------------------------------------------------------------------------------
1 | <%@ page language="java" contentType="text/html; charset=UTF-8"
2 | pageEncoding="UTF-8"%>
3 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
4 | <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
5 |
6 |
7 |
8 |
9 | 아라한사의 jpa정리
10 |
17 |
18 |
19 |
20 |
21 |
22 |
받은 데이터
23 | ${data }
24 |
25 |
26 |
27 | 홈
28 |
29 | 관계매핑
30 |
31 |
32 | 단일 매핑해본 것 /one = 영속성 컨텍스트로 인해 마지막 JustOne은 값을 캐싱하고 있다.
33 | 고로 이것을 누를 수록 마지막에의 저스트원 값만 다른 것을 볼 수가 있을 것이다.
34 | 패키지 이름 : com.example.r_mapping.justone
35 |
36 |
37 | 일대일매핑 /onetoone = 멤버와 멤버 세부사항이 일대일로 묶여있다.
38 | 패키지 이름 : com.example.r_mapping.onetoone
39 |
40 |
41 | 일대다매핑 /onetomany = 대학 하나에 묶인 학생들을 가져온다.
42 | 패키지 이름 : com.example.r_mapping.onetomany
43 |
44 |
45 | 다대다매핑 /manytomany = 다대다매핑이다. 카테고리 하나에 대해서 책을 가져옵니다.
46 | 패키지 이름 : com.example.r_mapping.manytomany
47 |
48 |
49 |
50 | Spring Data Jpa, Query DSL 를 이용한 검색
51 |
52 | 잠시 설명 :
53 | 게시글(BoardArticle), 사용자(User), 댓글(Comment), 태그(Tags) 를 가지고 있다고 가정해보자.
54 | 게시글과 사용자는 일대일 매핑을 하고 있으며 , 게시글과 댓글은 일대다, 태그와 게시글은 다대다 관계를 가진다.
55 | 사용자와 댓글또한 일대일 관계를 가진다. 여기에 무작위로 데이터를 넣어보고 조건에 따라 가져와보겠다!!
56 |
57 |
58 |
59 | spring data jpa 기본 :
60 |
68 | 레퍼런스 : http://docs.spring.io/spring-data/jpa/docs/current/reference/html/#jpa.query-methods.query-creation
69 | 슬립(하단에도 검색 나옴^^) : http://slipp.net/wiki/pages/viewpage.action?pageId=24641728
70 |
71 | springdatajpa- specification
72 | query dsl
73 |
74 |
75 |
76 | 다른 매핑
77 |
78 |
79 | 세컨더리테이블 /secondary = 필드를 바깥 테이블로 빼낼 수 있다.
80 | 패키지 이름 : com.example.mapping.secondary
81 |
82 |
83 | @MappedSuperclass /mappedSuperclass = 상속을 하면서 부모클래스의 필드를 모두 가져온다.
84 | 패키지 이름 : com.example.mapping.mappedsuperclass
85 | @PrePersist, @PreUpdate 어노테이션을 BasicEntity에 포함.(petri님 소스 참고)
86 |
87 |
88 | 상속매핑(단일테이블) : /inheritanceSingle = 각각의 상속을 단일테이블로 묶는다
89 | 패키지 이름 : com.example.mapping.inheritance.singletable
90 |
91 |
92 | 상속매핑(클래스당테이블) : /inheritancePerClass = 상속한 클래스마다 테이블을 만든다.
93 | 패키지 이름 : com.example.mapping.inheritance.perclass
94 |
95 |
96 | 상속매핑(조인) : /inheritanceJoin = 공통부분을 분리시키고 조인으로 가져온다.
97 | 패키지 이름 : com.example.mapping.inheritance.join
98 | 참고할만한 링크 : http://www.javaroots.com/2013/07/hibernate-inheritance-joined-strategy.html
99 |
100 |
101 |
102 | 컴파운드키 : /compoundkey = 변수를 조합해서 하나의 키로 써본다.
103 | 패키지 이름 : com.example.mapping.compoundkey
104 | 여기서 이름, 성, 사는 도시 세개 합친 세트([이름,성,도시]) 중에 하나라도 겹치면 데이터가 안 들어간다.
105 | 비슷한 기능으로 @UniqueConstrains 어노테이션도 있다
106 |
113 |
114 |
115 |
116 | Embedded : /embedded = 다른 엔티티에 내장시킬 수 있다.
117 | 패키지 이름 : com.example.mapping.embedded
118 | @AttributeOverrides 도 같이 나온다. 속성을 오버라이딩해서 재정의 하는 것이다.
119 |
120 |
121 |
122 | 콜렉션 매핑
123 |
126 |
127 |
128 | 다른 검색
129 |
130 | JPQL : /jpql = jpql을 이용한 검색
131 | Criteria :
132 | NamedQuery :
133 |
134 |
135 | 검증
136 |
148 |
149 |
150 | 주의사항과 기타 :
151 | 코드와 매뉴얼로 이야기합니다 by 아라한사
152 |
153 |
--------------------------------------------------------------------------------
/src/main/webapp/WEB-INF/web.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/src/test/java/com/example/mapping/justone/JustOneRepositoryTest.java:
--------------------------------------------------------------------------------
1 | package com.example.mapping.justone;
2 |
3 | import static org.junit.Assert.assertEquals;
4 | import static org.junit.Assert.assertNotNull;
5 |
6 | import java.util.Calendar;
7 | import java.util.Date;
8 | import java.util.GregorianCalendar;
9 | import java.util.List;
10 |
11 | import javax.transaction.Transactional;
12 |
13 | import org.junit.Before;
14 | import org.junit.Test;
15 | import org.junit.runner.RunWith;
16 | import org.springframework.beans.factory.annotation.Autowired;
17 | import org.springframework.boot.test.SpringApplicationConfiguration;
18 | import org.springframework.data.domain.Page;
19 | import org.springframework.data.domain.PageRequest;
20 | import org.springframework.data.domain.Pageable;
21 | import org.springframework.data.domain.Sort;
22 | import org.springframework.data.domain.Sort.Direction;
23 | import org.springframework.test.context.ActiveProfiles;
24 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
25 |
26 | import com.example.App;
27 | import com.example.r_mapping.justone.JustOne;
28 | import com.example.r_mapping.justone.JustOneEnum;
29 | import com.example.r_mapping.justone.JustOneRepository;
30 |
31 |
32 | @RunWith(SpringJUnit4ClassRunner.class)
33 | @SpringApplicationConfiguration(classes=App.class)
34 | @Transactional
35 | @ActiveProfiles("test")
36 | public class JustOneRepositoryTest {
37 |
38 | private static final int numRequest = 10;
39 | private static final String _1234 = "1234";
40 | private static final String HELLO_WORLD = "hello world";
41 |
42 | @Autowired JustOneRepository repository;
43 |
44 | @Before
45 | public void setUp() throws Exception {
46 | //Justone객체를 하나 만들고 save 로 저장합니다.
47 | //asserteq 에서 총 개수가 1이란 것을 확인해봅니다.
48 | JustOne one = new JustOne();
49 | one.setDateJoin(new Date());
50 | one.setEnumOne(JustOneEnum.TWO);
51 | one.setMessage(HELLO_WORLD);
52 | one.setPasswordConfirm(_1234);
53 | repository.save(one);
54 | assertEquals(repository.count(), 1);
55 | }
56 |
57 | @Test
58 | public void 읽고난뒤수정() throws Exception {
59 | //먼저 맨끝의 하나를 읽어보겠습니다. 읽어온 것의 메시지가 헬로월드가 맞는지 확인해보고
60 | List ones = repository.findAll();
61 | JustOne one = ones.get(ones.size()-1);
62 | assertEquals(one.getMessage(), HELLO_WORLD);
63 | //메시지를 수정한 뒤에 저장후, 다시 받아와서 문자열이 변했는지를 확인해봅니다.
64 | one.setMessage("ni3hao3");
65 | repository.save(one);
66 | JustOne getOne = repository.getOne(one.getId());
67 | assertEquals(getOne.getMessage(), one.getMessage());
68 | }
69 |
70 |
71 | @Test
72 | public void 삭제() throws Exception {
73 | //repository.deleteAll 로 모두 지우고서 count를 0 확인해봅니다.
74 | repository.deleteAll();
75 | assertEquals(repository.count(), 0);
76 | }
77 |
78 |
79 | @Test
80 | public void 페이징테스트() throws Exception {
81 | repository.deleteAll();
82 | //자 일단 40개 정도 저장을 해봅시다.
83 | for (int i = 0; i < 40; i++) {
84 | JustOne one = new JustOne();
85 | one.setDateJoin(new Date());
86 | one.setEnumOne(JustOneEnum.TWO);
87 | one.setMessage(HELLO_WORLD+i);
88 | one.setPasswordConfirm(_1234);
89 | repository.save(one);
90 | }
91 | //PageRequest 에 시작페이지와 요청갯수를 넣어주고 repository에 넣어줍니다.
92 | Pageable pageable = new PageRequest(0, numRequest);
93 | Page ones = repository.findAll(pageable);
94 |
95 | // 페이지 객체에서 받은 것에서 getContent 하시면 리스트가 뿅 나옵니다~_~
96 | //메시지를 잘 뽑아오는 지 테스트해보고~
97 | List onesList = ones.getContent();
98 | for (int i = 0; i < numRequest; i++) {
99 | assertEquals(onesList.get(i).getMessage(), HELLO_WORLD+i);
100 | }
101 | assertEquals(onesList.size(), numRequest);
102 |
103 | //역순으로 하고 싶으시다면?! 소트를 써봅시다.
104 | // 0개부터 39개까지 헬로월드 메시지를 넣었는데, id 역순으로 출력해서
105 | // 39부터 30까지 가져와보도록 하겠습니다. pagerequest끝에 sort객체를 넣어주면 됩니다.
106 | Sort sort = new Sort(Direction.DESC, "id");
107 | pageable = new PageRequest(0, 10, sort);
108 | ones = repository.findAll(pageable);
109 | onesList = ones.getContent();
110 | for (int i = 39, j = 0; i >= 30 ; i--,j++) {
111 | assertEquals(onesList.get(j).getMessage(), HELLO_WORLD+i);
112 | }
113 | }
114 |
115 | @Test
116 | public void 특정메시지로_가져오기() throws Exception {
117 | JustOne one = repository.findByMessage(HELLO_WORLD);
118 | assertNotNull(one);
119 | assertEquals(one.getMessage(), HELLO_WORLD);
120 | }
121 |
122 | @Test
123 | public void 날짜이전_특정메시지로찾기() throws Exception {
124 | repository.deleteAll();
125 | /**주의 * 자바 날짜는 자바8, joda time 같은 걸로 해주는게 더 좋다고 합니다.
126 | * 여기선 그냥 간단하게 java date 로 이미 가버렸습니다;; 삐질 */
127 | //먼저 데이터를 삽입하고
128 | Calendar calendar;
129 | for(int i=0;i<10;i++){
130 | calendar = new GregorianCalendar(2010+i,1,1,13,24,56);
131 | JustOne one = new JustOne();
132 | one.setDateJoin(calendar.getTime());
133 | one.setMessage(i%2==0? HELLO_WORLD: _1234);
134 | repository.save(one);
135 | }
136 | //기준 데이터를 가져와서 특정날짜이전과 해당 메시지에 해당하는 리스트를 뽑아봅니다.
137 | calendar = new GregorianCalendar(2015,1,1,13,24,56);
138 | List getList =
139 | repository.findBydateJoinBeforeAndMessage(calendar.getTime(), HELLO_WORLD);
140 | //그리고 검사
141 | int year=2010;
142 | for (JustOne justOne : getList) {
143 | calendar.set(year,1,1,13,24,56);
144 | assertEquals(justOne.getMessage(), HELLO_WORLD);
145 | assertEquals(justOne.getDateJoin(), calendar.getTime());
146 | year+=2;
147 | }
148 | }
149 |
150 |
151 |
152 | }
153 |
--------------------------------------------------------------------------------
/src/test/java/com/example/mapping/manytomany/BookRepositoryTest.java:
--------------------------------------------------------------------------------
1 | package com.example.mapping.manytomany;
2 |
3 | import org.junit.Test;
4 | import org.junit.runner.RunWith;
5 | import org.springframework.beans.factory.annotation.Autowired;
6 | import org.springframework.boot.test.SpringApplicationConfiguration;
7 | import org.springframework.test.context.ActiveProfiles;
8 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
9 |
10 | import com.example.App;
11 | import com.example.r_mapping.manytomany.Book;
12 | import com.example.r_mapping.manytomany.BookRepository;
13 | import com.example.r_mapping.manytomany.Category;
14 | import com.example.r_mapping.manytomany.CategoryRepository;
15 |
16 | @RunWith(SpringJUnit4ClassRunner.class)
17 | @SpringApplicationConfiguration(classes=App.class)
18 | @ActiveProfiles("test")
19 | public class BookRepositoryTest {
20 | @Autowired BookRepository repoBook;
21 | @Autowired CategoryRepository repoCate;
22 |
23 | @Test
24 | public void testName() throws Exception {
25 | Book book = new Book("MB의 비용");
26 | Book book1 = new Book("기획된");
27 | Book book2 = new Book("잡놈들");
28 | Book book3 = new Book("소탕하라");
29 |
30 | Category category = new Category();
31 | category.setName("정치비평에세이");
32 | category.getBooks().add(book);
33 | category.getBooks().add(book1);
34 | category.getBooks().add(book2);
35 | category.getBooks().add(book3);
36 |
37 | repoBook.save(book);
38 | repoBook.save(book1);
39 | repoBook.save(book2);
40 | repoBook.save(book3);
41 | repoCate.save(category);
42 | }
43 |
44 |
45 |
46 | }
47 |
--------------------------------------------------------------------------------
/src/test/java/com/example/mapping/onetoone/MemberRepositoryTest.java:
--------------------------------------------------------------------------------
1 | package com.example.mapping.onetoone;
2 |
3 | import static org.junit.Assert.assertEquals;
4 |
5 | import javax.transaction.Transactional;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 | import org.springframework.beans.factory.annotation.Autowired;
10 | import org.springframework.boot.test.SpringApplicationConfiguration;
11 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
12 |
13 | import com.example.App;
14 | import com.example.r_mapping.onetoone.Member;
15 | import com.example.r_mapping.onetoone.MemberDetail;
16 | import com.example.r_mapping.onetoone.MemberRepository;
17 |
18 | @RunWith(SpringJUnit4ClassRunner.class)
19 | @SpringApplicationConfiguration(classes=App.class)
20 | @Transactional
21 | public class MemberRepositoryTest {
22 |
23 | @Autowired MemberRepository repository;
24 |
25 | @Test
26 | public void test() {
27 | Member member = new Member();
28 | member.setName("arahansa");
29 |
30 | MemberDetail memberDetail = new MemberDetail();
31 | memberDetail.setAddress("incheon");
32 |
33 | member.setMemberDetail(memberDetail);
34 |
35 | repository.save(member);
36 | assertEquals(repository.count(), 1);
37 | }
38 |
39 | }
40 |
--------------------------------------------------------------------------------
/src/test/java/com/example/mapping/secondary/SecondarymasterTest.java:
--------------------------------------------------------------------------------
1 | package com.example.mapping.secondary;
2 |
3 | import static org.junit.Assert.*;
4 |
5 | import java.util.List;
6 |
7 | import javax.transaction.Transactional;
8 |
9 | import org.junit.Before;
10 | import org.junit.Test;
11 | import org.junit.runner.RunWith;
12 | import org.springframework.beans.factory.annotation.Autowired;
13 | import org.springframework.boot.test.SpringApplicationConfiguration;
14 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
15 |
16 | import com.example.App;
17 | import com.example.mapping.secondary.SecondaryRepository;
18 | import com.example.mapping.secondary.Secondarymaster;
19 | @RunWith(SpringJUnit4ClassRunner.class)
20 | @SpringApplicationConfiguration(classes=App.class)
21 | @Transactional
22 | public class SecondarymasterTest {
23 |
24 | @Autowired SecondaryRepository repository;
25 |
26 | @Before
27 | public void setup(){
28 | Secondarymaster master = new Secondarymaster();
29 | master.setSub1("hello");
30 | master.setSub2("world");
31 |
32 | repository.save(master);
33 | }
34 |
35 | @Test
36 | public void test()
37 | {
38 | Secondarymaster getMasters =repository.findBySub2("world");
39 | System.out.println("lazy loading?");
40 | System.out.println("master :"+getMasters.getSub2());
41 |
42 | }
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/target/m2e-wtp/web-resources/META-INF/MANIFEST.MF:
--------------------------------------------------------------------------------
1 | Manifest-Version: 1.0
2 | Implementation-Title: LearnSpringDataJpa Maven Webapp
3 | Implementation-Version: 0.0.1-SNAPSHOT
4 | Built-By: arahansa
5 | Implementation-Vendor-Id: com.example
6 | Build-Jdk: 1.8.0_45
7 | Created-By: Maven Integration for Eclipse
8 | Implementation-Vendor: Pivotal Software, Inc.
9 | Main-Class: com.springcamp.env.SampleProfileApplication
10 |
11 |
--------------------------------------------------------------------------------
/target/m2e-wtp/web-resources/META-INF/maven/com.example/LearnSpringDataJpa/pom.properties:
--------------------------------------------------------------------------------
1 | #Generated by Maven Integration for Eclipse
2 | #Fri Jul 10 01:25:24 KST 2015
3 | version=0.0.1-SNAPSHOT
4 | groupId=com.example
5 | m2e.projectName=LearnSpringDataJpa
6 | m2e.projectLocation=C\:\\Users\\arahansa\\workspace\\LearnSpringDataJpa
7 | artifactId=LearnSpringDataJpa
8 |
--------------------------------------------------------------------------------
/target/m2e-wtp/web-resources/META-INF/maven/com.example/LearnSpringDataJpa/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 | com.example
5 | LearnSpringDataJpa
6 | war
7 | 0.0.1-SNAPSHOT
8 | LearnSpringDataJpa Maven Webapp
9 | http://maven.apache.org
10 |
11 |
12 | UTF-8
13 | com.springcamp.env.SampleProfileApplication
14 | 1.7
15 |
16 |
17 |
18 |
19 | org.springframework.boot
20 | spring-boot-starter-parent
21 | 1.2.5.RELEASE
22 |
23 |
24 |
25 |
26 | org.apache.maven.plugins
27 | maven-resources-plugin
28 | 2.4.3
29 |
30 |
31 | org.springframework.boot
32 | spring-boot-starter
33 |
34 |
35 | org.springframework.boot
36 | spring-boot-starter-web
37 |
38 |
39 | org.springframework.boot
40 | spring-boot-starter-data-jpa
41 |
42 |
43 | javax.servlet
44 | jstl
45 |
46 |
47 |
48 |
49 |
50 |
51 | org.springframework.boot
52 | spring-boot-starter-test
53 | test
54 |
55 |
56 |
57 |
58 |
59 |
60 | joda-time
61 | joda-time
62 | 2.5
63 |
64 |
65 | joda-time
66 | joda-time-jsptags
67 | 1.1.1
68 |
69 |
70 | org.jadira.usertype
71 | usertype.spi
72 | 3.0.0.GA
73 |
74 |
75 |
76 | org.jadira.usertype
77 | usertype.core
78 | 3.0.0.GA
79 |
80 |
81 |
82 |
83 |
84 | mysql
85 | mysql-connector-java
86 |
87 |
88 | com.h2database
89 | h2
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 | LearnSpringDataJpa
101 |
102 |
103 |
104 | org.apache.maven.plugins
105 | maven-compiler-plugin
106 |
107 | 1.8
108 | 1.8
109 |
110 |
111 |
112 |
113 |
114 |
--------------------------------------------------------------------------------