본문 바로가기

JPA

JPA - Join 커뮤니티 게시판 테이블 쿼리: 특정 직업을 가진 사람들이 쓴 글의 정보와 사용자 정보를 조회하는 SQL 는 다음과 같을 것이다 select t.topic_seq '번호',t.title '제목',m.name '작성자',p.title '직업',t.created_at '작성일' from `member` m join `topic` t on m.member_seq = t.member_seq join `profile` p on p.profile_seq = m.profile_seq where p.profile_seq=1; query 결과는 아래와 같을 것이다. JPA 로 해당 부분을 구현 하는 과정은 아래와 같다. JPAQueryFactory 설.. 더보기
usage spring data jpa with query dsl -- dependency com.querydsl querydsl-apt com.querydsl querydsl-jpa org.springframework.boot spring-boot-maven-plugin com.mysema.maven apt-maven-plugin 1.1.3 process target/generated-sources/java com.querydsl.apt.jpa.JPAAnnotationProcessor -- created databaseConfig.java @Configuration public class Databaseconfig { @Bean public JPAQueryFactory queryFactory(EntityManager em) { return new JPAQueryFac.. 더보기
JPA 와 JDBCTemplate 저장 속도 비교 spring boot 에서 jpa 와 jdbctemplate 을 제공해주며 , jpa 와 jdbctemplate 동시에 둘다 사용 가능 하다. pom.xml org.springframework.boot spring-boot-starter-data-jpa org.springframework.boot spring-boot-starter-jdbc 접속 정보는 properties 에 아래와 같이 한다. spring.datasource.username=xxxx spring.datasource.password=xxxx spring.datasource.driver-class-name=com.mysql.jdbc.Driver spring.datasource.url=jdbc:mysql://xxxx:xxxx/parcelab.. 더보기
JPA 사용시 Lombok 의 Data 어노테이션 사용 이슈 아래 예시로 설명 하도록 한다. @Dataclass A{ @Id @GeneratedValue(strategy = GenerationType.AUTO) private Long id; @OneToMany(fetch=FetchType.LAZY,cascade = CascadeType.ALL) @JoinColumn(name="a_id") private List bList; } @Dataclass B{ @Id @GeneratedValue(strategy = GenerationType.AUTO) private Long id; @OneToMany(fetch=FetchType.LAZY,cascade = CascadeType.ALL) @JoinColumn(name="a_id") private Long a_id; A 와 B.. 더보기
JPA Indexing 설정 방법 Entity 클래스에 인덱싱 설정 하려는 컬럼 명을 명시해주면 인덱싱 설정이 된다.@Table(indexes = {@Index(columnList="mycol1"), @Index(columnList="mycol2")})참고로 JPA 를 사용하여 자동 테이블 생성시 기본키, 참조키 는 자동으로 인덱싱을 해주게 된다. 참고자료 :https://stackoverflow.com/questions/3405229/specifying-an-index-non-unique-key-using-jpa 더보기
PersistentObjectException: detached entity passed to persist 아래 에러는 JPA 사용시 Entity 들간 매핑시 Cascadetype 으로 인하여 발생한 에러이다. PersistentObjectException: detached entity passed to persist해당 엔티티 관계는 아래와 같다 (에러발생 엔티티들의 관계 )@Entity @Table(name="parent") class Parent{ @Id @GeneratedValue(strategy = GenerationType.AUTO) private Long id; } @Entity @Table(name="child") class Parent{ @Id @GeneratedValue(strategy = GenerationType.AUTO) private Long id; @OneToOne(fetch = F.. 더보기