분류 전체보기
-
[Java] 문자열 비교 - equals() 메서드 vs == 연산자카테고리 없음 2024. 7. 14. 17:31
String 선언 차이 (literal vs new)new로 선언하면 java heap memory에 개별 객체가 생성됨String strA = new String("Hello World");literal로 선언하면 String Constant Pool에 생성된 객체를 참조함String strB = "Hello World"; equals() 메소드두 문자열의 내용을 비교하는 메서드String strA = "Hello World";String strB = "Hello World";String strC = new String("Hello World");System.out.println(strA.equals(strB)); // trueSystem.out.println(strA.equals(strC)); //..
-
Spring Transactional 사용 시 주의사항카테고리 없음 2024. 6. 27. 14:20
@Transactional은 Spring AOP 기반이며, Spring AOP는 Proxy 기반으로 동작함@Transactional 메소드가 호출되면, Proxy 객체를 생성하고 트랜잭션 생성/커밋/롤백 등의 작업을 proxy 객체에게 위임함Proxy 객체가 호출될 때, 이 메소드를 가로채서 부가 기능들을 proxy 객체에게 위임함참고) Spring AOP proxy mechanisms (JDK dynamic and CGLIB) - TedBlob - Technical Posts Spring AOP proxy mechanisms (JDK dynamic and CGLIB) - TedBlob - Technical PostsHow would Spring AOP intercept the call to the ta..
-
JPA Auditing카테고리 없음 2024. 6. 27. 12:28
JPA AuditingJPA를 사용하는 애플리케이션에서 entity 클래스의 생성 및 수정 시점에 대한 자동 기록 기능을 제공하는 방법이를 통해 데이터베이스에 저장된 entity 객체의 생성 시간, 마지막 수정 시간, 생성자, 수정자 등을 자동으로 기록할 수 있음자동으로 데이터 변경 이력을 관리할 수 있어 편리함 JPA Annotation @MappedSuperclass 공통 필드나 매핑 정보를 여러 엔티티에서 공유할 수 있도록 하기 위해 사용되는 어노테이션@MappedSuperclass가 선언된 클래스는 실제 엔티티가 아니며 데이터베이스 테이블과 직접적으로 매핑되지 않음대신 이 클래스를 상속받는 엔티티 클래스에 매핑 정보가 전달됨여러 엔티티에 공통적으로 적용되는 필드 (ex. 생성 시간, 수정 시간..
-
JPA Dirty Checking카테고리 없음 2024. 6. 25. 15:13
JPA Dirty Checking 코드에서 데이터베이스에 엔티티를 update하는 쿼리가 존재하지 않는데, entity의 값을 변경하는 것 만으로도 데이터베이스의 데이터가 변경됨이는 JPA의 Dirty Checking 때문이며, Dirty Checking은 entity의 상태 변경을 검사하는 것을 의미함JPA에서 트랜잭션이 끝나는 시점에 변화가 있는 모든 entity 객체를 데이터베이스에 자동으로 반영함JPA는 commit하는 순간 flush를 호출하고, 이때 entity와 snapshot을 비교함영속성 컨텍스트에 처음 저장된 순간 entity의 최초 상태를 1차 캐시에 저장함 (snapshot)commit하는 순간 entity와 snapshot을 비교하여 변경된 값이 있는지 확인하고, 변경된 값이 있다..
-
Spring JPA카테고리 없음 2024. 6. 24. 20:11
JPA (Java Persistence API)자바 어플리케이션에서 관계형 데이터베이스를 사용하는 방식을 정의한 인터페이스자바 ORM 기술에 대한 API 표준 명세를 의미JPA를 구현한 구현체로는 Hibernate, EclipseLink, DataNucleus 등 여러 프레임워크가 존재JPA의 모든 데이터 변경은 트랜잭션 안에서 실행됨 ORM (Object Relational Mapping)객체와 DB 테이블을 매핑하는 기술SQL 문법 대신 객체에 대한 코드(메소드)로 데이터베이스를 조작할 수 있어서 직관적이고 객체지향적임ex. SELECT * FROM device; 라는 SQL 쿼리 대신 device.findAll() 이라는 메소드를 사용함ERD를 보는 의존도를 낮출 수 있음 복잡한 쿼리는 별도의 튜..
-
[Spring Boot 오류] HikariPool-1 - Exception during pool initialization. Could not connect to address Unknown database 'database name'카테고리 없음 2024. 6. 11. 10:55
Spring Boot 프로젝트의 application.yml 파일을 아래와 같이 구성하고, 어플리케이션을 실행시 오류가 발생함 application.ymlspring: profiles: active: local # default group: local: - common prod: - common---spring: config: activate: on-profile: common# ...---spring: config: activate: on-profile: local datasource: driver-class-name: org.mariadb.jdbc.Driver url: jdbc:mariadb://loc..
-
Spring Profile카테고리 없음 2024. 6. 9. 17:24
Spring Profile어플리케이션 설정을 특정 환경에서만 적용되게 할 때 사용개발 환경 단계 (Local, Dev, Prod) 별로 다르게 이용할 때 사용Spring Boot는 어플리케이션이 실행될 때 자동으로 application.properties 또는 application.yml을 찾는다application.properties와 application.yml를 동시에 사용하지 않도록 주의하자.application.properties가 항상 나중에 로드되기 때문에 yaml에 정의한 profile 설정이 덮어 씌어질 수 있기 때문!application.properties 파일 위치: {root}\src\main\resources\application.propertiesapplication.proper..