2016년 11월 30일 수요일

[C#교육,WPF교육,XAML교육,IT실무교육추천][강좌소개] C# WPF, XAML 프로그래밍 교육과정안내

탑크리에듀의 본 과정은 체계적 학습과 다양한 개발 방법을 익힘으로 WPF 개발의 기술적 기반을 마련하고자 하며 배운 기술들을 융합하여 간단한 미니프로젝트로 응용프로그램을 개발해 봄으로써 WPF 개발에 대한 자신감을 심어 드립니다.

2016년 11월 28일 월요일

[자바강의,스프링강의,JPA강의추천_탑크리에듀][JPA팁,JPa강좌]orphanRemoval = true vs DDL의 On Delete Cascade vs CascadeType.REMOVE 차이점

[JPA팁,JPa강좌]orphanRemoval = true vs DDL의 On Delete Cascade vs CascadeType.REMOVE 차이점

먼저 예문을 보자.

@Entity
class Emp {
@OneToOne(orphanRemoval=true)
    private Addr addr;
}
Emp 엔티티가 삭제될 때 참조가 끊어진 연관된 Addr 엔티티도 삭제하라는 의미이며 DB에서도 삭제되는데 참조(연결)가 끊어진 Addr 객체는 DB에서도 삭제된다는 뜻이다.

@Entity
class Emp {
@OneToOne(cascade=CascadeType.REMOVE)
    private Addr addr;
}
Emp 엔티티가 삭제될 때 연관된 Addr 엔티티도 삭제하라는 의미이며 DB에서도 삭제된다.


@Entity
class Emp {
@OneToMany(orphanRemoval=true)
    private List<Addr> addr;
}
addresses 컬렉션에서 Addr 객체가 제거되는 경우 DB에서도 삭제하라는 의미.

orphanRemoval은 JPA2.0 이상에서 지원하는 것으로 ORM 스펙, JPA 레벨에서의 정의이고 On Delete Cascade는 DBMS 레벨에서 작동되며 하는 일은 같다. orphanRemoval @OneToMany 연관에서 부모 엔티티의 컬렉션 등에서 자식 엔티티가 삭제될 때 참조가 끊어지므로 DB 레벨에서도 삭제되고 @OneToOne연관에서 엔티티가 삭제될 때 연관된 엔티티가 참조가 끊어지므로 DB에서 삭제된다즉 참조연결이 끊어진(Disconnected엔티티를 같이 삭제하라는 의미로 Owner 객체와 참조가 끊어진 객체들을 정리할 때 유용하다.

cascade=CascadeType.REMOVE는 연결이 끊어진다고 해서 자동 삭제되는 것은 아니고 명시적으로 연관 엔티티가 삭제될 때 같이 삭제하라는 영속성 전이와 관련된 옵션이다.

반면 On Delete Cascade는 DB레벨에서 부모 테이블의 레코드가 삭제될 때 자식레코드도 같이 삭제하라는 의미이다.

[자바강의,스프링강의,JPA강의추천_탑크리에듀]JPA강좌,QueryDSL4.X 조회, 수정, 삭제, update, delete 배치쿼리, JPADeleteClause, JPAUpdateClause

JPA강좌,QueryDSL4.X 조회수정삭제, update, delete 배치쿼리, JPADeleteClause, JPAUpdateClause

n  데이터 조회 쿼리작성
JPAQuery 직접 생성하는 경우

import static model.QEmp.emp;

@PersistenceContext
EntityManager em;

JPAQuery<?> query = new JPAQuery<Void>(em);
Emp emp = query.select(emp).from(emp)
           .where(emp.empno.eq(7369))
           .fetchOne();  //한건만 추출

JPAQueryFactory를 이용한다면
(내부적으로 JPAQuery 인스턴스를 가지고 있다.)

[스프링 설정 파일에서 JPAQueryFactory를 빈으,로 등록]
@Bean
public JPAQueryFactory queryFactory() {
           //return new JPAQueryFactory(JPQLTemplates.DEFAULT, em);
           return new JPAQueryFactory(em);
}

[Repository 구현체에서]

import static model.QEmp.emp;

@Autowired
JPAQueryFactory queryFactory;

Emp emp = queryFactory.selectFrom(emp)
           .where(emp.empno.eq(7369))
           .fetch();


n  수정
[JPAQuery 또는 JPAQueryFactory 두방법 모두 가능]
Long affectedRow  = new JPAUpdateClause(em, emp)
           .where(emp.empno.eq(empno))
           .set(emp.ename, newEname)
           .execute();        

[JPAQueryFactory 방법]
// update 메소드 내부에서 JPAUpdateClause를 사용한다.
Long affectedRow = queryFactory.update(emp)
           .where(emp.empno.eq(empno))
           .set(emp.ename, newEname)
           .execute();


n  삭제
[JPAQuery 또는 JPAQueryFactory 두방법 모두 가능]

Long affectedRow =new JPADeleteClause(em, emp)
        .where(emp.job.eq(job))
.execute();                 

[JPAQueryFactory 방법]
// delete 메소드 내부에서 JPADeleteClause를 사용한다.
Long affectedRow = queryFactory.delete(emp)
    .where(emp.job.eq(job))
    .execute();

[자바강의,스프링강의,JPA강의추천_탑크리에듀]JPA교육,QueryDSL4.X강좌:JPAQuery,JPAQueryFactory인스턴스 생성방법

JPA교육,QueryDSL4.X강좌:JPAQuery,JPAQueryFactory인스턴스 생성방법


첨부파일 참조하세요.

첨부파일 URL참조 - http://ojc.asia/bbs/board.php?bo_table=LecJpa&wr_id=203

[자바강의,스프링강의,JPA강의추천_탑크리에듀]JPA,QueryDSL4.X강좌,메이븐(Maven) 설정하기

JPA,QueryDSL4.X강좌,메이븐(Maven) 설정하기

n  JPA, JDO, MongoDB, Java Collection, Hibernate Search등에서 지원하며 Spring Data 프로젝트에서 지원하는 오픈소스 프로젝트 이다.
n  Criteria 처럼 JPQL을 위한 빌더이며 메소드코드 기반으로 컴파일 시점에 에러 확인이 가능하다.
첨부 파일 참조하세요~
감사합니다.

첨부파일 URL참조 - http://ojc.asia/bbs/board.php?bo_table=LecJpa&wr_id=202

[자바강의,스프링강의,JPA강의추천_탑크리에듀][Spring JPA교육]1 : 1 단방향, 대상테이블에 외래키(JPA 1.0, JPA2.0),@OneToOne,예문입니다.

[Spring JPA교육]1 : 1 단방향, 대상테이블에 외래키(JPA 1.0, JPA2.0),@OneToOne,예문입니다.

첨부 파일 참조 부탁 드립니다.
감사합니다.

첨부파일 URL참조 - http://ojc.asia/bbs/board.php?bo_table=LecJpa&wr_id=201

[자바강의,스프링강의,JPA강의추천_탑크리에듀][스프링JPA]Querydsl,SQLQueryFactory사용위한메이븐설정,pom.xml

[스프링JPA]Querydsl,SQLQueryFactory사용위한메이븐설정,pom.xml 

 DB스키마 구조대로 자바쪽에 쿼리 타입(Query Type)을 생성해야 하므로 querydsl-maven-plugin 플러그인을 추가해야 하고, Spring Data JPA에서 SQLQueryFactory를 이용하여 Native SQL을 JPA 메소드 기반으로 실행하기 위해 기존 Querydsl 설정에 추가로 querydsl-sql-spring 의존성과 쿼리 타입의 Hibernate Validation을 위해  hibernate-validator 추가해야 한다. 


[pom.xml] 

<?xml version="1.0" encoding="UTF-8"?> 
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
<modelVersion>4.0.0</modelVersion> 

<groupId>ojc.edu</groupId> 
<artifactId>ojc.nativesql</artifactId> 
<version>0.0.1-SNAPSHOT</version> 
<packaging>jar</packaging> 

<name>nativesql-exam1</name> 
<description>jpa native sql example</description> 

<parent> 
<groupId>org.springframework.boot</groupId> 
<artifactId>spring-boot-starter-parent</artifactId> 
<version>1.3.3.RELEASE</version> 
<relativePath /> <!-- lookup parent from repository --> 
</parent> 

<properties> 
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
<java.version>1.8</java.version> 
<querydsl.version>4.0.8</querydsl.version> 
</properties> 

<dependencies> 
<dependency> 
<groupId>org.springframework.boot</groupId> 
<artifactId>spring-boot-starter-data-jpa</artifactId> 
</dependency> 

<dependency> 
<groupId>mysql</groupId> 
<artifactId>mysql-connector-java</artifactId> 
<version>5.1.38</version> 
<scope>runtime</scope> 
</dependency> 
<dependency> 
<groupId>org.springframework.boot</groupId> 
<artifactId>spring-boot-starter-test</artifactId> 
<scope>test</scope> 
</dependency> 
<dependency> 
<groupId>com.querydsl</groupId> 
<artifactId>querydsl-jpa</artifactId> 
<version>${querydsl.version}</version> 
</dependency> 
<dependency> 
<groupId>com.querydsl</groupId> 
<artifactId>querydsl-sql-spring</artifactId> 
<version>${querydsl.version}</version> 
</dependency> 
<dependency> 
<groupId>org.hibernate</groupId> 
<artifactId>hibernate-validator</artifactId> 
</dependency> 
</dependencies> 
<build> 
<plugins> 
<plugin> 
<groupId>org.springframework.boot</groupId> 
<artifactId>spring-boot-maven-plugin</artifactId> 
</plugin> 
<plugin> 
<groupId>com.querydsl</groupId> 
<artifactId>querydsl-maven-plugin</artifactId> 
<version>${querydsl.version}</version> 
<executions> 
<execution> 
<goals> 
<goal>export</goal> 
</goals> 
</execution> 
</executions> 
<configuration> 
<jdbcDriver>com.mysql.jdbc.Driver</jdbcDriver> <jdbcUrl>jdbc:mysql://localhost/nativesql1?createDatabaseIfNotExist=true</jdbcUrl> 
<jdbcUser>root</jdbcUser> 
<jdbcPassword>1111</jdbcPassword> 
<packageName>jpa.model</packageName> 
<targetFolder>target/generated-sources/java</targetFolder> 
<namePrefix>S</namePrefix> 
<!-- targetFolder에 Dept.java, Emp.java를 생성 --> 
<exportBeans>true</exportBeans> 
</configuration> 
<dependencies> 
<dependency> 
<groupId>mysql</groupId> 
<artifactId>mysql-connector-java</artifactId> 
<version>5.1.38</version> 
<scope>compile</scope> 
</dependency> 
</dependencies> 
</plugin> 
</plugins> 
</build> 
</project>