[질문 템플릿] 1. 강의 내용과 관련된 질문인가요? (예) 2. 인프런의 질문 게시판과 자주 하는 질문에 없는 내용인가요? (예) 3. 질문 잘하기 메뉴얼을 읽어보셨나요? (예) [질문 내용] 엔티티 클래스 개발2에서 FK 관련 질문입니다! FK를 안걸고 인덱스를 거는 방식도 있고 시스템마다 다르다고 하셨는데, Id값은 똑같이 가지고 있고 거기에 인덱스를 거는 것인가요? 그리고 이렇게 하면 속도가 왜 더 빨라지는 것인가요?
안녕하세요 해당 수업에서 만약 Book 의 모든 필드를 변경하고자 한다면 실제 실무에서는 어떻게 사용하면 좋을까 하면서 만들어 보았는데, 틀린 부분이나 고쳐야할 부분이 있다면 말씀해주실 수 있을까요 ? 작은 부분이라도 조언 해주시면 감사하겠습니다! 1. DTO @Getter @Setter public class UpdateBookDto { private String name ; private int price ; private int stockQuantity ; private String author ; private String isbn ; public static UpdateBookDto updateBookAll ( String name , int price , int stockQuantity , String author , String isbn) { UpdateBookDto bookDto = new UpdateBookDto() ; bookDto. name = name ; bookDto. price = price ; bookDto. stockQuantity = stockQuantity ; bookDto. author = author ; bookDto. isbn = isbn ; return bookDto ; } } 2. Controller public class ItemController { @PostMapping ( "/{itemId}/edit" ) public String updateItem ( @PathVariable String itemId , @ModelAttribute ( "form" ) BookForm form) { UpdateBookDto bookDto = UpdateBookDto. updateBookAll ( form.getName() , form.getPrice() , form.getStockQuantity() , form.getAuthor() , form.getIsbn() ) ; itemService.updateItem(form.getId() , bookDto) ; return "redirect:/items" ; } } 3. Service public class ItemService { @Transactional public void updateItem (Long itemId , UpdateBookDto dto) { Book findBook = (Book) itemRepository.findOne(itemId) ; findBook.changeBook( dto.getName() , dto.getPrice() , dto.getStockQuantity() , dto.getAuthor() , dto.getIsbn() ) ; } } 4. Book public class Book extends Item { public void changeBook (String name , int price , int stockQuantity , String author , String isbn) { super .changeItem(name , price , stockQuantity) ; this .author = author ; this .isbn = isbn ; } }
안녕하세요. JPA 활용 1편을 모두 듣고 복습을 위해 코드를 다시 보는데 다음과 같이 몇몇 라이브러리 적용이 안 됩니다. (lombok 플러그인 설치와 적용 모두 마친 상태입니다.) 아래는 build.gradle입니다. plugins { id 'org.springframework.boot' version '2.6.7' id 'io.spring.dependency-management' version '1.0.11.RELEASE' id 'java' } group = 'homepage' version = '0.0.1-SNAPSHOT' sourceCompatibility = '11' repositories { mavenCentral() } dependencies { implementation 'org.springframework.boot:spring-boot-starter-data-jpa' implementation 'org.springframework.boot:spring-boot-starter-thymeleaf' implementation 'org.springframework.boot:spring-boot-starter-validation' implementation 'org.springframework.boot:spring-boot-starter-web' implementation 'junit:junit:4.13.1' implementation 'junit:junit:4.13.1' implementation 'junit:junit:4.13.1' implementation 'junit:junit:4.13.1' compileOnly 'org.projectlombok:lombok' runtimeOnly 'com.h2database:h2' annotationProcessor 'org.projectlombok:lombok' testImplementation 'org.springframework.boot:spring-boot-starter-test' } tasks .named( 'test' ) { useJUnitPlatform() }
학습하는 분들께 도움이 되고, 더 좋은 답변을 드릴 수 있도록 질문전에 다음을 꼭 확인해주세요. 1. 강의 내용과 관련된 질문을 남겨주세요. 2. 인프런의 질문 게시판과 자주 하는 질문(링크)을 먼저 확인해주세요. (자주 하는 질문 링크: https://bit.ly/3fX6ygx) 3. 질문 잘하기 메뉴얼(링크)을 먼저 읽어주세요. (질문 잘하기 메뉴얼 링크: https://bit.ly/2UfeqCG) 질문 시에는 위 내용은 삭제하고 다음 내용을 남겨주세요. ========================================= [질문 템플릿] 1. 강의 내용과 관련된 질문인가요? (예/아니오) 2. 인프런의 질문 게시판과 자주 하는 질문에 없는 내용인가요? (예/아니오) 3. 질문 잘하기 메뉴얼을 읽어보셨나요? (예/아니오) [질문 내용] 안녕하세요. 1. 2. 사진첨부해드리고 말씀드리겠습니다 1) member객체를 인스턴스하고, em.persist(member)를 할 시점에서 List<Order>에 여러 order객체들이 있을경우 같이 저장하기위해 CASCADE를 ALL로 지정한게 맞는지 궁금합니다. 2) 위의 내용이 맞을 때, 밑에 내용에서 createOrder 메소드 for문 안에서 order.addOrderItem(orderItem)를 하고나서 order를 persist 할경우, 여러개의 orderItem이 같이 저장되기위해서 해당 Order 엔티티안에 orderItems 리스트객체를 cascade cascadeType.All선언해야하는데, OrderItem이 Item과 연관관계가 있어서 cascade all를 선언 안하는게 맞는지 궁금합니다. 만약 그게 맞다면 caseCade.All를 선언 안하면 order 객체을 persist 할 시점에 List<orderItem>들을 같이 저장이 안되는걸로 알고 있습니다. 그렇다면 order 엔티티 안에 createOrder 메소드로 반환값 받는 order에 있는 OrderItems 리스트 객체를 for문으로 돌려서 각각의 OrderItem객체를 persist 하여 order값도 같이 persist 시키는게 맞는건지 궁금합니다.
안녕하세요. 도메인 내에서 비즈니스 로직을 작성하는 것이 객체지향적이다 라는 말씀을 듣고 생각해보다가, 양방향 연관 관계 편의 메서드에서의 setter 사용이 생각났습니다. public class Order { public void setDelivery (Delivery delivery) { this .delivery = delivery ; delivery.setOrder( this ) ; } } 이와 같이 양방향 연관 관계에서는 한쪽에 setter 함수가 불가필 할듯 한데, setter 함수를 무조건적으로 사용하면 안되는 것은 아니고 지양한다는 정도로만 받아들여도 될까요 ? 감사합니다.
[질문 템플릿] 1. 강의 내용과 관련된 질문인가요? 일부 예 2. 인프런의 질문 게시판과 자주 하는 질문에 없는 내용인가요? 예 3. 질문 잘하기 메뉴얼을 읽어보셨나요? 예 [질문 내용] 안녕하세요, 스프링 부트와 JPA 활용 강의를 듣고 토이프로젝트를 진행하려고 하는데, entity relation diagram을 간단하게 그릴 툴이 뭐가 있을까 싶어서 질문 남깁니다. Draw.io나 erdcloud 등의 사이트를 봤지만 초심자가 무턱대고 접하기엔 생각보다 벽이 있어서, 강사님께서 직접 사용하시는 툴은 어떤 것인지 궁금해 질문합니다.
일단 상품등록하는데 문제는 없습니다. 위와 연결된 Controller에 매핑과 BookForm 설정 똑같이 했는데 강의에 영한님이 한것처럼 html에서 th:object="${form}" 나 th:field="*{name}" 을 command+click 으로 연결된곳으로 갈수도 없고 Cannot resolve 'form' 오류 뜨면서 빨간줄 그어지는데 해결할수 있는 방법있을까요? 저도 그 편한 기능 쓰고 싶습니다 진짜루 ..ㅠㅠ 인텔리제이는 IntelliJ IDEA 2022.1.2 (Ultimate Edition) 쓰고 있습니다.
npm ERR! code 1 npm ERR! path C:\Users\지은\Downloads\boilerplate-mern-stack-master\boilerplate-mern-stack-master\node_modules\bcrypt npm ERR! command failed npm ERR! command C:\WINDOWS\system32\cmd.exe /d /s /c node-pre-gyp install --fallback-to-build npm ERR! Failed to execute 'C:\Program Files\nodejs\node.exe C:\Users\지은\AppData\Roaming\nvm\v16.15.0\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js configure --fallback-to-build --module=C:\Users\지은\Downloads\boilerplate-mern-stack-master\boilerplate-mern-stack-master\node_modules\bcrypt\lib\binding\bcrypt_lib.node --module_name=bcrypt_lib --module_path=C:\Users\지은\Downloads\boilerplate-mern-stack-master\boilerplate-mern-stack-master\node_modules\bcrypt\lib\binding --napi_version=8 --node_abi_napi=napi --napi_build_version=0 --node_napi_label=node-v93' (1) npm ERR! node-pre-gyp info it worked if it ends with ok npm ERR! node-pre-gyp info using node-pre-gyp@0.14.0 npm ERR! node-pre-gyp info using node@16.15.0 | win32 | x64 npm ERR! node-pre-gyp WARN Using needle for node-pre-gyp https download npm ERR! node-pre-gyp info check checked for "C:\Users\지은\Downloads\boilerplate-mern-stack-master\boilerplate-mern-stack-master\node_modules\bcrypt\lib\binding\bcrypt_lib.node" (not found) npm ERR! node-pre-gyp http GET https://github.com/kelektiv/node.bcrypt.js/releases/download/v3.0.8/bcrypt_lib-v3.0.8-node-v93-win32-x64-unknown.tar.gz npm ERR! node-pre-gyp http 404 https://github.com/kelektiv/node.bcrypt.js/releases/download/v3.0.8/bcrypt_lib-v3.0.8-node-v93-win32-x64-unknown.tar.gz npm ERR! node-pre-gyp WARN Tried to download(404): https://github.com/kelektiv/node.bcrypt.js/releases/download/v3.0.8/bcrypt_lib-v3.0.8-node-v93-win32-x64-unknown.tar.gz npm ERR! node-pre-gyp WARN Pre-built binaries not found for bcrypt@3.0.8 and node@16.15.0 (node-v93 ABI, unknown) (falling back to source compile with node-gyp) npm ERR! node-pre-gyp http 404 status code downloading tarball https://github.com/kelektiv/node.bcrypt.js/releases/download/v3.0.8/bcrypt_lib-v3.0.8-node-v93-win32-x64-unknown.tar.gz npm ERR! gyp info it worked if it ends with ok npm ERR! gyp info using node-gyp@9.0.0 npm ERR! gyp info using node@16.15.0 | win32 | x64 npm ERR! gyp info ok npm ERR! gyp info it worked if it ends with ok npm ERR! gyp info using node-gyp@9.0.0 npm ERR! gyp info using node@16.15.0 | win32 | x64 npm ERR! gyp ERR! find Python npm ERR! gyp ERR! find Python Python is not set from command line or npm configuration npm ERR! gyp ERR! find Python Python is not set from environment variable PYTHON npm ERR! gyp ERR! find Python checking if "python3" can be used npm ERR! gyp ERR! find Python - "python3" is not in PATH or produced an error npm ERR! gyp ERR! find Python checking if "python" can be used npm ERR! gyp ERR! find Python - "python" is not in PATH or produced an error npm ERR! gyp ERR! find Python checking if Python is C:\Users\지은\AppData\Local\Programs\Python\Python39\python.exe npm ERR! gyp ERR! find Python - "C:\Users\지은\AppData\Local\Programs\Python\Python39\python.exe" could not be run npm ERR! gyp ERR! find Python checking if Python is C:\Program Files\Python39\python.exe npm ERR! gyp ERR! find Python - "C:\Program Files\Python39\python.exe" could not be run npm ERR! gyp ERR! find Python checking if Python is C:\Users\지은\AppData\Local\Programs\Python\Python39-32\python.exe npm ERR! gyp ERR! find Python - "C:\Users\지은\AppData\Local\Programs\Python\Python39-32\python.exe" could not be run npm ERR! gyp ERR! find Python checking if Python is C:\Program Files\Python39-32\python.exe npm ERR! gyp ERR! find Python - "C:\Program Files\Python39-32\python.exe" could not be run npm ERR! gyp ERR! find Python checking if Python is C:\Program Files (x86)\Python39-32\python.exe npm ERR! gyp ERR! find Python - "C:\Program Files (x86)\Python39-32\python.exe" could not be run npm ERR! gyp ERR! find Python checking if Python is C:\Users\지은\AppData\Local\Programs\Python\Python38\python.exe npm ERR! gyp ERR! find Python - "C:\Users\지은\AppData\Local\Programs\Python\Python38\python.exe" could not be run npm ERR! gyp ERR! find Python checking if Python is C:\Program Files\Python38\python.exe npm ERR! gyp ERR! find Python - "C:\Program Files\Python38\python.exe" could not be run npm ERR! gyp ERR! find Python checking if Python is C:\Users\지은\AppData\Local\Programs\Python\Python38-32\python.exe npm ERR! gyp ERR! find Python - "C:\Users\지은\AppData\Local\Programs\Python\Python38-32\python.exe" could not be run npm ERR! gyp ERR! find Python checking if Python is C:\Program Files\Python38-32\python.exe npm ERR! gyp ERR! find Python - "C:\Program Files\Python38-32\python.exe" could not be run npm ERR! gyp ERR! find Python checking if Python is C:\Program Files (x86)\Python38-32\python.exe npm ERR! gyp ERR! find Python - "C:\Program Files (x86)\Python38-32\python.exe" could not be run npm ERR! gyp ERR! find Python checking if Python is C:\Users\지은\AppData\Local\Programs\Python\Python37\python.exe npm ERR! gyp ERR! find Python - "C:\Users\지은\AppData\Local\Programs\Python\Python37\python.exe" could not be run npm ERR! gyp ERR! find Python checking if Python is C:\Program Files\Python37\python.exe npm ERR! gyp ERR! find Python - "C:\Program Files\Python37\python.exe" could not be run npm ERR! gyp ERR! find Python checking if Python is C:\Users\지은\AppData\Local\Programs\Python\Python37-32\python.exe npm ERR! gyp ERR! find Python - "C:\Users\지은\AppData\Local\Programs\Python\Python37-32\python.exe" could not be run npm ERR! gyp ERR! find Python checking if Python is C:\Program Files\Python37-32\python.exe npm ERR! gyp ERR! find Python - "C:\Program Files\Python37-32\python.exe" could not be run npm ERR! gyp ERR! find Python checking if Python is C:\Program Files (x86)\Python37-32\python.exe npm ERR! gyp ERR! find Python - "C:\Program Files (x86)\Python37-32\python.exe" could not be run npm ERR! gyp ERR! find Python checking if Python is C:\Users\지은\AppData\Local\Programs\Python\Python36\python.exe npm ERR! gyp ERR! find Python - "C:\Users\지은\AppData\Local\Programs\Python\Python36\python.exe" could not be run npm ERR! gyp ERR! find Python checking if Python is C:\Program Files\Python36\python.exe npm ERR! gyp ERR! find Python - "C:\Program Files\Python36\python.exe" could not be run npm ERR! gyp ERR! find Python checking if Python is C:\Users\지은\AppData\Local\Programs\Python\Python36-32\python.exe npm ERR! gyp ERR! find Python - "C:\Users\지은\AppData\Local\Programs\Python\Python36-32\python.exe" could not be run npm ERR! gyp ERR! find Python checking if Python is C:\Program Files\Python36-32\python.exe npm ERR! gyp ERR! find Python - "C:\Program Files\Python36-32\python.exe" could not be run npm ERR! gyp ERR! find Python checking if Python is C:\Program Files (x86)\Python36-32\python.exe npm ERR! gyp ERR! find Python - "C:\Program Files (x86)\Python36-32\python.exe" could not be run npm ERR! C:\Users\지은\AppData\Local\npm-cache\_logs\2022-05-25T05_57_34_949Z-debug-0.lognpm ERR! code 1 npm ERR! path C:\Users\지은\Downloads\boilerplate-mern-stack-master\boilerplate-mern-stack-master\node_modules\bcrypt npm ERR! command failed npm ERR! command C:\WINDOWS\system32\cmd.exe /d /s /c node-pre-gyp install --fallback-to-build npm ERR! Failed to execute 'C:\Program Files\nodejs\node.exe C:\Users\지은\AppData\Roaming\nvm\v16.15.0\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js configure --fallback-to-build --module=C:\Users\지은\Downloads\boilerplate-mern-stack-master\boilerplate-mern-stack-master\node_modules\bcrypt\lib\binding\bcrypt_lib.node --module_name=bcrypt_lib --module_path=C:\Users\지은\Downloads\boilerplate-mern-stack-master\boilerplate-mern-stack-master\node_modules\bcrypt\lib\binding --napi_version=8 --node_abi_napi=napi --napi_build_version=0 --node_napi_label=node-v93' (1) npm ERR! node-pre-gyp info it worked if it ends with ok npm ERR! node-pre-gyp info using node-pre-gyp@0.14.0 npm ERR! node-pre-gyp info using node@16.15.0 | win32 | x64 npm ERR! node-pre-gyp WARN Using needle for node-pre-gyp https download npm ERR! node-pre-gyp info check checked for "C:\Users\지은\Downloads\boilerplate-mern-stack-master\boilerplate-mern-stack-master\node_modules\bcrypt\lib\binding\bcrypt_lib.node" (not found) npm ERR! node-pre-gyp http GET https://github.com/kelektiv/node.bcrypt.js/releases/download/v3.0.8/bcrypt_lib-v3.0.8-node-v93-win32-x64-unknown.tar.gz npm ERR! node-pre-gyp http 404 https://github.com/kelektiv/node.bcrypt.js/releases/download/v3.0.8/bcrypt_lib-v3.0.8-node-v93-win32-x64-unknown.tar.gz npm ERR! node-pre-gyp WARN Tried to download(404): https://github.com/kelektiv/node.bcrypt.js/releases/download/v3.0.8/bcrypt_lib-v3.0.8-node-v93-win32-x64-unknown.tar.gz npm ERR! node-pre-gyp WARN Pre-built binaries not found for bcrypt@3.0.8 and node@16.15.0 (node-v93 ABI, unknown) (falling back to source compile with node-gyp) npm ERR! node-pre-gyp http 404 status code downloading tarball https://github.com/kelektiv/node.bcrypt.js/releases/download/v3.0.8/bcrypt_lib-v3.0.8-node-v93-win32-x64-unknown.tar.gz npm ERR! gyp info it worked if it ends with ok npm ERR! gyp info using node-gyp@9.0.0 npm ERR! gyp info using node@16.15.0 | win32 | x64 npm ERR! gyp info ok npm ERR! gyp info it worked if it ends with ok npm ERR! gyp info using node-gyp@9.0.0 npm ERR! gyp info using node@16.15.0 | win32 | x64 npm ERR! gyp ERR! find Python npm ERR! gyp ERR! find Python Python is not set from command line or npm configuration npm ERR! gyp ERR! find Python Python is not set from environment variable PYTHON npm ERR! gyp ERR! find Python checking if "python3" can be used npm ERR! gyp ERR! find Python - "python3" is not in PATH or produced an error npm ERR! gyp ERR! find Python checking if "python" can be used npm ERR! gyp ERR! find Python - "python" is not in PATH or produced an error npm ERR! gyp ERR! find Python checking if Python is C:\Users\지은\AppData\Local\Programs\Python\Python39\python.exe npm ERR! gyp ERR! find Python - "C:\Users\지은\AppData\Local\Programs\Python\Python39\python.exe" could not be run npm ERR! gyp ERR! find Python checking if Python is C:\Program Files\Python39\python.exe npm ERR! gyp ERR! find Python - "C:\Program Files\Python39\python.exe" could not be run npm ERR! gyp ERR! find Python checking if Python is C:\Users\지은\AppData\Local\Programs\Python\Python39-32\python.exe npm ERR! gyp ERR! find Python - "C:\Users\지은\AppData\Local\Programs\Python\Python39-32\python.exe" could not be run npm ERR! gyp ERR! find Python checking if Python is C:\Program Files\Python39-32\python.exe npm ERR! gyp ERR! find Python - "C:\Program Files\Python39-32\python.exe" could not be run npm ERR! gyp ERR! find Python checking if Python is C:\Program Files (x86)\Python39-32\python.exe npm ERR! gyp ERR! find Python - "C:\Program Files (x86)\Python39-32\python.exe" could not be run npm ERR! gyp ERR! find Python checking if Python is C:\Users\지은\AppData\Local\Programs\Python\Python38\python.exe npm ERR! gyp ERR! find Python - "C:\Users\지은\AppData\Local\Programs\Python\Python38\python.exe" could not be run npm ERR! gyp ERR! find Python checking if Python is C:\Program Files\Python38\python.exe npm ERR! gyp ERR! find Python - "C:\Program Files\Python38\python.exe" could not be run npm ERR! gyp ERR! find Python checking if Python is C:\Users\지은\AppData\Local\Programs\Python\Python38-32\python.exe npm ERR! gyp ERR! find Python - "C:\Users\지은\AppData\Local\Programs\Python\Python38-32\python.exe" could not be run npm ERR! gyp ERR! find Python checking if Python is C:\Program Files\Python38-32\python.exe npm ERR! gyp ERR! find Python - "C:\Program Files\Python38-32\python.exe" could not be run npm ERR! gyp ERR! find Python checking if Python is C:\Program Files (x86)\Python38-32\python.exe npm ERR! gyp ERR! find Python - "C:\Program Files (x86)\Python38-32\python.exe" could not be run npm ERR! gyp ERR! find Python checking if Python is C:\Users\지은\AppData\Local\Programs\Python\Python37\python.exe npm ERR! gyp ERR! find Python - "C:\Users\지은\AppData\Local\Programs\Python\Python37\python.exe" could not be run npm ERR! gyp ERR! find Python checking if Python is C:\Program Files\Python37\python.exe npm ERR! gyp ERR! find Python - "C:\Program Files\Python37\python.exe" could not be run npm ERR! gyp ERR! find Python checking if Python is C:\Users\지은\AppData\Local\Programs\Python\Python37-32\python.exe npm ERR! gyp ERR! find Python - "C:\Users\지은\AppData\Local\Programs\Python\Python37-32\python.exe" could not be run npm ERR! gyp ERR! find Python checking if Python is C:\Program Files\Python37-32\python.exe npm ERR! gyp ERR! find Python - "C:\Program Files\Python37-32\python.exe" could not be run npm ERR! gyp ERR! find Python checking if Python is C:\Program Files (x86)\Python37-32\python.exe npm ERR! gyp ERR! find Python - "C:\Program Files (x86)\Python37-32\python.exe" could not be run npm ERR! gyp ERR! find Python checking if Python is C:\Users\지은\AppData\Local\Programs\Python\Python36\python.exe npm ERR! gyp ERR! find Python - "C:\Users\지은\AppData\Local\Programs\Python\Python36\python.exe" could not be run npm ERR! gyp ERR! find Python checking if Python is C:\Program Files\Python36\python.exe npm ERR! gyp ERR! find Python - "C:\Program Files\Python36\python.exe" could not be run npm ERR! gyp ERR! find Python checking if Python is C:\Users\지은\AppData\Local\Programs\Python\Python36-32\python.exe npm ERR! gyp ERR! find Python - "C:\Users\지은\AppData\Local\Programs\Python\Python36-32\python.exe" could not be run npm ERR! gyp ERR! find Python checking if Python is C:\Program Files\Python36-32\python.exe npm ERR! gyp ERR! find Python - "C:\Program Files\Python36-32\python.exe" could not be run npm ERR! gyp ERR! find Python checking if Python is C:\Program Files (x86)\Python36-32\python.exe npm ERR! gyp ERR! find Python - "C:\Program Files (x86)\Python36-32\python.exe" could not be run npm ERR! C:\Users\지은\AppData\Local\npm-cache\_logs\2022-05-25T05_57_34_949Z-debug-0.log 루트 디렉토리에서 npm install 오류가 계속뜹니다ㅠ 버전의 문제인가요...? 이 강의 꼭 듣고싶은데 해결방법이 있을까요..?
강의 내용중, Order 도메인을 작성할때 다음 스크린샷처럼 Member, Delivery 엔티티를 사용하여 this 키워드를 사용할때 Cannot access jpabook.jpashop.domain.Member 에러가 나고 있습니다. Member와 Delivery, Order 는 모두 예시로 올려주신 코드와 확인하여 똑같이 작성한걸 확인했지만 혹시 몰라 제가 작성한 코드를 같이 올리겠습니다. package jpabook.jpashop.domain; import lombok.Getter; import lombok.Setter; import javax.persistence.*; import java.util.ArrayList; import java.util.List; @Entity @Getter @Setter public class Member { @Id @GeneratedValue @Column(name = "member_id") private Long id; private String name; @Embedded private Address address; @OneToMany(mappedBy = "member") private List<Order> orders = new ArrayList<>(); } package jpabook.jpashop.domain; import lombok.Getter; import lombok.Setter; import javax.persistence.*; @Entity @Getter @Setter public class Delivery { @Id @GeneratedValue @Column(name = "delivery_id") private Long id; @OneToOne(mappedBy = "delivery", fetch = FetchType.LAZY) private Order order; @Embedded private Address address; @Enumerated(EnumType.STRING) private DeliveryStatus deliveryStatus; } package jpabook.jpashop.domain; import lombok.AccessLevel; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; import javax.persistence.*; import java.time.LocalDateTime; import java.util.ArrayList; import java.util.List; import static javax.persistence.FetchType.*; @Entity @Table(name="orders") @Getter @Setter @NoArgsConstructor(access = AccessLevel.PROTECTED) // 이거는 한 도메인 안에서 생성 메서드 등을 통해 로직을 구현했을 경우에 // 접근을 막기위해 사용한다 // 누구는 여기 만들어진 createOrder 를 통해서 주문을 생성하고 // 누구는 Order order = new Order -> order.setOrder로 생성하고 하면 나중에 골치아파치므로 // 애초에 public 으로 지정되어 있지 않은거 + 롬복통한 getter setter 를 통한 코딩을 막아준다 public class Order { @Id @GeneratedValue @Column(name = "order_id") private Long id; @ManyToOne (fetch = LAZY) @JoinColumn(name="member_id") private Member member; @OneToMany(mappedBy = "order", cascade = CascadeType.ALL) // cascade all 걸어주면 private List<OrderItem> orderItems = new ArrayList<>(); // persist(orderItemA) // persist(orderItemB) // persist(orderItemC) // persist(order) 를 cascase all 안걸어주면 이렇게 넣어야하는데 // 걸어주면 persist(order)하면 자동적으로 다 넣어줌 딜리트도 마찬가지로 다 같이 지워줌 // 즉, 원래는 order 에 들어가는 delivery 나 orderItems 등은 다른 테이블에 같이 걸려있잖아 그걸 // 일일히 다 테이블마다 찾아가서 넣어줘야하는데 cascade all 걸어주면 알아서 그걸 다 연동해서 cd 해줌 @OneToOne (fetch = FetchType.LAZY, cascade = CascadeType.ALL) @JoinColumn(name="delivery_id") private Delivery delivery; private LocalDateTime orderDate; @Enumerated(EnumType.STRING) private OrderStatus status; // 주문상태 order cancel //연관관계 편의 메서드 = 양방향일때 쓰면 편한 메소드 //이게 뭐냐면 연관관계 맺어줬으면 DB딴에서는 이런거 안해줘도 다 알아서 동작하긴 하는데 // 비지니스 로직상에서는 이렇게 set할수 있는 연관관계 메서드가 있어야 구현할때 편함 public void setMember(Member member){ this.member = member; member.getOrders().add(this); } public void addOrderItem(OrderItem orderItem){ orderItems.add(orderItem); orderItem.setOrder(this); } public void setDelivery(Delivery delivery){ this.delivery=delivery; delivery.setOrder(this); } //연관관계 메서드 위치는 컨트롤하는쪽에 위치하는게 좋음 비지니스 로직에 의하면 // public static void main (String[] args){ // Member m = new Member(); // Order o = new Order(); // // m.getOrders().add(o); --> 이거 할필요가 없어짐 // o.setMember(m); // } // 원래는 연관관계 메서드가 없으면 이렇게 일일히 비지니스 로직딴에서 데이터 객체 생성후 member 에도 넣어주고 order 에도 넣어주고 해야하는데 // 연관관계 메서드를 만들어 놓으면 로직딴에서 저짓할필요가 없이 편해짐 // ... 은 가변파라미터, String 이라 치면 몇개를 넣어도 다 카바 가능 -> list = 가변파라미터 하면 다 리스트에 들어감 차곡차곡 //생성메서드 public static Order createOrder(Member member, Delivery delivery, OrderItem... orderItems){ Order order = new Order(); order.setMember(member); order.setDelivery(delivery); for (OrderItem orderItem:orderItems) { order.addOrderItem(orderItem); } order.setStatus(OrderStatus.ORDER); order.setOrderDate(LocalDateTime.now()); return order; } //비지니스 로직 //주문취소 public void cancel(){ if(delivery.getDeliveryStatus()==DeliveryStatus.COMP){ throw new IllegalStateException("배송 완료된 상품은 취소불가"); } this.setStatus(OrderStatus.CANCEL); for(OrderItem orderItem:orderItems){ orderItem.cancel(); } } //전체주문가격 조회 public int getTotalPrice(){ int totalprice = 0; for(OrderItem orderItem:orderitems){ totalprice += orderItem.getTotalPrice(); } return totalprice; } } import 구문을 직접 작성하여 엔티티들을 직접 임포트까지 해보고, 로직상에서 아예 jpabook.jpashop.~~ 처럼 직접 임포트 구문을 작성해서 시도도 해보았지만 해결이 되지 않아 질문을 올리게 되었습니다. 확인부탁드립니다.
OrderService에서 OrderItem접근이 어떻게 가능한지 궁금합니다. OrderService @Transactional public Long order (Long memberId , Long itemId , int count) { // memberId 를 가져오기 위해선 MemberRepository 있어야 함 // 엔티티 조회 Member member = memberRepository .findOne(memberId) ; Item item = itemRepository .findOne(itemId) ; // 배송정보 생성 ( 회원정보 Address) Delivery delivery = new Delivery() ; delivery.setAddress(member.getAddress()) ; // 주문상품 생성 OrderItem. createOrderItem () // [질문한 부분] } 혹시 어떠한 도메인 이든 , Controller, Service, Repository에 접근 가능해서 그런걸까요?!
학습하는 분들께 도움이 되고, 더 좋은 답변을 드릴 수 있도록 질문전에 다음을 꼭 확인해주세요. 1. 강의 내용과 관련된 질문을 남겨주세요. 2. 인프런의 질문 게시판과 자주 하는 질문(링크)을 먼저 확인해주세요. (자주 하는 질문 링크: https://bit.ly/3fX6ygx) 3. 질문 잘하기 메뉴얼(링크)을 먼저 읽어주세요. (질문 잘하기 메뉴얼 링크: https://bit.ly/2UfeqCG) 질문 시에는 위 내용은 삭제하고 다음 내용을 남겨주세요. ========================================= [질문 템플릿] 1. 강의 내용과 관련된 질문인가요? (예/아니오) 2. 인프런의 질문 게시판과 자주 하는 질문에 없는 내용인가요? (예/아니오) 3. 질문 잘하기 메뉴얼을 읽어보셨나요? (예/아니오) [질문 내용] Order에 생성 메서드를 구현할때 파라미터에 ... 넣는 의미를 모르겠습니다. 어느 경우에 사용하나요? public static Order createOrder (Member member , Delivery delivery , OrderItem... orderItems) { }
안녕하세요, 저는 처음부터 H2데이터베이스가 아닌 MySQL을 연결해서 사용하고 있습니다. 테스트 코드 작성 후 여러 이점으로 메모리디비 연결 하는 방법을 알려주셨는데, Mysql의 경우도 할 수 있나요? 현재 dependencies에 implementation 'mysql:mysql-connector-java' 추가된 상태입니다. 추가적으로 로그에 쿼리남기는 것도 보고싶어서, dependencies에 implementation 'com.github.gavlyukovskiy:p6spy-spring-boot-starter:1.5.6' 만을 추가한 상태입니다. 로그에 남는것 같기는 한데 선생님처럼 예쁘게 보이는 것이아닌 줄글처럼 나오는데요, 혹시 추가하거나 봐야할 게 있을까요? application.properties에는 이렇게 설정했습니다, # JPA Settings spring.jpa.hibernate.ddl-auto = create spring.jpa.properties.hibernate.format_sql = true spring.jpa.properties.hibernate.show_sql = true
========================================= [질문 템플릿] 1. 강의 내용과 관련된 질문인가요? 예 2. 인프런의 질문 게시판과 자주 하는 질문에 없는 내용인가요? 예 3. 질문 잘하기 메뉴얼을 읽어보셨나요? 예 [질문 내용] Spring이 런타임에서는 상품을 잘 저장하고, 불러오는 것도 정상적입니다. 그런데 스프링을 Re-Run 하게 되면, 상품이 전부 사라지네요. ddl-auto: create를 update로 바꿨더니 데이터가 안 사라지네요. 이거 말고 다른 이유는 없는 건가요?
[질문 템플릿] 1. 강의 내용과 관련된 질문인가요? 예 2. 인프런의 질문 게시판과 자주 하는 질문에 없는 내용인가요? 예 3. 질문 잘하기 메뉴얼을 읽어보셨나요? 예 [질문 내용] 안녕하세요!! 강의를 보면서 팩토리 메서드에 대해 궁금증이 몇가지 생겼는데 구글링을 해봐도 잘 나오지 않아서 질문 올립니다🥲 1. 팩토리 메서드를 사용하는 기준이 있을까요? 생성자를 통해 객체를 생성하지 않고, 팩토리 메서드를 사용하는 경우 이름을 가질 수 있다, 하위 타입 객체를 반환할 수 있다 등등의 장점이 있고, 이에 반해 몇몇 단점도 있는것 같은데 단순히 팩토리 메서드 내부에서 생성자만 호출하는 경우에도 실무에서는 팩토리 메서드를 웬만하면 다 사용하는 편인가요?? 생성자 대신 팩토리 메서드를 사용하여 객체를 생성하는 상황이나 기준이 있는지 궁금합니다! 2. 팩토리 메서드를 사용하는 경우 프로젝트에서 네이밍 규칙을 어떻게 가져가는 것이 좋을까요? 강의를 듣고 복습하면서 Order와 같이 연관 관계들이 얽혀있는 팩토리 메서드는 createOrder와 같은 좀 더 의미있는 이름을 사용하고, 그냥 단순히 객체만 생성하는 경우에는 of를 사용해서 실습을 해보았습니다! 실무에서 프로젝트를 진행하면 위와 같이 어떠한 룰을 만들어서 사용하시는지, 아니면 하나의 이름으로 통일해서 가져가시는지 궁금합니다 ㅎㅎ 감사합니다 😀