해결된 질문
작성
·
720
0
[질문 템플릿]
1. 강의 내용과 관련된 질문인가요? (예)
2. 인프런의 질문 게시판과 자주 하는 질문에 없는 내용인가요? (아니오)
3. 질문 잘하기 메뉴얼을 읽어보셨나요? (예)
[질문 내용]
테이블 생성 제대로 되는 것 확인하였으나 sql문이 터미널에 나타나지 않습니다.
이전 강의 참고하여 repository를 인터페이스 상속받는 형태로 만들어보긴 했는데 이 부분은 문제 없을 것으로 생각됩니다.
build.gradle
plugins {
id 'java'
id 'org.springframework.boot' version '3.2.0'
id 'io.spring.dependency-management' version '1.1.4'
}
group = 'jpabook'
version = '0.0.1-SNAPSHOT'
java {
sourceCompatibility = '17'
}
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
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 'org.springframework.boot:spring-boot-devtools'
compileOnly 'org.projectlombok:lombok'
runtimeOnly 'com.h2database:h2'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
//JUnit4 추가
testImplementation("org.junit.vintage:junit-vintage-engine") {
exclude group: "org.hamcrest", module: "hamcrest-core"
}
}
tasks.named('test') {
useJUnitPlatform()
}
application.yml
spring:
datasource:
url: jdbc:h2:tcp://localhost/~/databasesByH2/jpashop
username: sa
password:
driver-class-name: org.h2.Driver
jpa:
hibernate:
ddl-auto: create
properties:
hibernate:
#show_sql: true
format_sql: true
logging.level:
org.hibernate.orm.jdbc.bind: trace #스프링 부트 3.x, hibernate6
package jpabook.jpashop.entity;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import lombok.Getter;
import lombok.Setter;
@Entity
@Getter @Setter
public class Member {
@Id @GeneratedValue
private Long id;
private String username;
}
MemberRepository.java(인터페이스)
package jpabook.jpashop.repository;
import jpabook.jpashop.entity.Member;
public interface MemberRepository {
public Long save(Member member);
public Member find(Long id);
}
package jpabook.jpashop.repository;
import jakarta.persistence.EntityManager;
import jakarta.persistence.PersistenceContext;
import jpabook.jpashop.entity.Member;
import org.springframework.stereotype.Repository;
@Repository
public class JpaMemberRepository implements MemberRepository{
@PersistenceContext
EntityManager em;
@Override
public Long save(Member member) {
em.persist(member);
return member.getId();
}
@Override
public Member find(Long id) {
return em.find(Member.class, id);
}
}
package jpabook.jpashop.repository;
import jpabook.jpashop.entity.Member;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.transaction.annotation.Transactional;
import static org.junit.jupiter.api.Assertions.*;
@RunWith(SpringRunner.class)
@SpringBootTest
class JpaMemberRepositoryTest {
@Autowired MemberRepository memberRepository;
@Test
@Transactional
@Rollback(false)
void save() {
//given
Member member = new Member();
member.setUsername("조건우");
//when
Long resultId = memberRepository.save(member);
Member findMember = memberRepository.find(resultId);
//then
Assertions.assertThat(findMember.getUsername()).isEqualTo(member.getUsername());
Assertions.assertThat(findMember.getId()).isEqualTo(member.getId());
Assertions.assertThat(findMember).isEqualTo(member);
}
@Test
void find() {
}
}
JpaMemberRepositoryTest.java 실행로그
> Task :compileJava UP-TO-DATE
> Task :processResources UP-TO-DATE
> Task :classes UP-TO-DATE
> Task :compileTestJava UP-TO-DATE
> Task :processTestResources NO-SOURCE
> Task :testClasses UP-TO-DATE
15:29:18.352 [Test worker] INFO org.springframework.test.context.support.AnnotationConfigContextLoaderUtils -- Could not detect default configuration classes for test class [jpabook.jpashop.JpashopApplicationTests]: JpashopApplicationTests does not declare any static, non-private, non-final, nested classes annotated with @Configuration.
15:29:18.391 [Test worker] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper -- Found @SpringBootConfiguration jpabook.jpashop.JpashopApplication for test class jpabook.jpashop.JpashopApplicationTests
15:29:18.451 [Test worker] INFO org.springframework.boot.devtools.restart.RestartApplicationListener -- Restart disabled due to context in which it is running
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v3.2.0)
2023-12-18T15:29:18.567+09:00 INFO 2911 --- [ Test worker] j.jpashop.JpashopApplicationTests : Starting JpashopApplicationTests using Java 17.0.9 with PID 2911 (started by kangg in /Users/kangg/Coding/jpashop)
2023-12-18T15:29:18.568+09:00 INFO 2911 --- [ Test worker] j.jpashop.JpashopApplicationTests : No active profile set, falling back to 1 default profile: "default"
2023-12-18T15:29:18.865+09:00 INFO 2911 --- [ Test worker] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2023-12-18T15:29:18.875+09:00 INFO 2911 --- [ Test worker] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 6 ms. Found 0 JPA repository interfaces.
2023-12-18T15:29:19.077+09:00 INFO 2911 --- [ Test worker] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default]
2023-12-18T15:29:19.097+09:00 INFO 2911 --- [ Test worker] org.hibernate.Version : HHH000412: Hibernate ORM core version 6.3.1.Final
2023-12-18T15:29:19.111+09:00 INFO 2911 --- [ Test worker] o.h.c.internal.RegionFactoryInitiator : HHH000026: Second-level cache disabled
2023-12-18T15:29:19.201+09:00 INFO 2911 --- [ Test worker] o.s.o.j.p.SpringPersistenceUnitInfo : No LoadTimeWeaver setup: ignoring JPA class transformer
2023-12-18T15:29:19.213+09:00 INFO 2911 --- [ Test worker] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2023-12-18T15:29:19.245+09:00 INFO 2911 --- [ Test worker] com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Added connection conn0: url=jdbc:h2:tcp://localhost/~/databasesByH2/jpashop user=SA
2023-12-18T15:29:19.246+09:00 INFO 2911 --- [ Test worker] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2023-12-18T15:29:19.542+09:00 INFO 2911 --- [ Test worker] o.h.e.t.j.p.i.JtaPlatformInitiator : HHH000489: No JTA platform available (set 'hibernate.transaction.jta.platform' to enable JTA platform integration)
2023-12-18T15:29:19.554+09:00 INFO 2911 --- [ Test worker] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2023-12-18T15:29:19.634+09:00 WARN 2911 --- [ Test worker] JpaBaseConfiguration$JpaWebConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
2023-12-18T15:29:19.643+09:00 INFO 2911 --- [ Test worker] o.s.b.a.w.s.WelcomePageHandlerMapping : Adding welcome page: class path resource [static/index.html]
2023-12-18T15:29:19.812+09:00 INFO 2911 --- [ Test worker] j.jpashop.JpashopApplicationTests : Started JpashopApplicationTests in 1.367 seconds (process running for 1.814)
OpenJDK 64-Bit Server VM warning: Sharing is only supported for boot loader classes because bootstrap classpath has been appended
2023-12-18T15:29:20.098+09:00 INFO 2911 --- [ionShutdownHook] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
2023-12-18T15:29:20.099+09:00 INFO 2911 --- [ionShutdownHook] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown initiated...
2023-12-18T15:29:20.104+09:00 INFO 2911 --- [ionShutdownHook] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown completed.
> Task :test
Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0.
You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.
For more on this, please refer to https://docs.gradle.org/8.5/userguide/command_line_interface.html#sec:command_line_warnings in the Gradle documentation.
BUILD SUCCESSFUL in 2s
4 actionable tasks: 1 executed, 3 up-to-date
3:29:20 PM: Execution finished ':test --tests "jpabook.jpashop.JpashopApplicationTests"'.
추가하니 잘 나오는군요. 감사합니다!