반응형

이클립스 단축키 


Ctrl+Alt+J

코드 정렬을 다음줄 문장 끝까지 한줄로 연결해준다.

블럭지정 하면 블럭지정 영역 만큼 한 라인으로 연결해준다.


Ctrl+Shift+F , 혹은 Ctrl+I 로 자동 포멧 정렬후 한줄로 하고 싶은 영역을 사용하면 좋을듯 하다.



Alt+위, 아래 

포커스된 라인통으로 위로 아래로 이동한다.


영역지정 Alt+위,아래

영역지정된 영역의 라인을 위로 아래로 이동한다.


Ctrl+D 

라인단위 삭제


영역지정 Ctrl+D

영역지정 부분 라인 삭제

반응형
반응형

포린키 생성 실패


메시지 내용


2017-10-20 14:53:53 c8ca8b70 Error in foreign key constraint of table CYBER_EDU_MUSEUM_UPDATE/#sql-532_1dca:

 FOREIGN KEY (`DSPY_SIL_CODE`, `PART_NO`) REFERENCES `JNT_DSPY_PART` (`DSPY_SIL_CODE`, `PART_NO`):

Cannot find an index in the referenced table where the

referenced columns appear as the first columns, or column types

in the table and the referenced table do not match for constraint.

Note that the internal storage type of ENUM and SET changed in

tables created with >= InnoDB-4.1.12, and such columns in old tables

cannot be referenced by such columns in new tables.

See http://dev.mysql.com/doc/refman/5.6/en/innodb-foreign-key-constraints.html

for correct foreign key definition.



내가 찾아봐서 해결한 방법은

컬럼에 utf8_unicode_ci , utf8_general_ci 두개를 참조 컬럼과 외래키 컬럼의 콜렉션타입을 다르게 해서 였다.

각각의 테이블 키 컬럼의 타입과 참조 컬럼의 타입을 같게 아무거나 맞춰주니 포린키 생성 성공했다.


utf8_general_ci 에는 악센트 문자가 없어서 엑센트 없는문자로만 나온다네요.

utf8_general_ci로 해야 속도가 빠르다고는 한다. 


제일 중요한건 한가지 타입으로 맞춰주는거.



반응형
반응형


 

 

book, publication relationbook, publication relation



 

 

 

 

@Entity(name = "Book")

@Table(name = "book")

public static class Book

implements Serializable {

@Id

@GeneratedValue

private Long id;

private String title;

private String author;

@NaturalId

private String isbn;

//Getters and setters omitted for brevity

}

 

 

Book은 관계에서의 부모쪽을 나타낸다.

isbn컬럼은 isbn컬럼은 비즈니스 키로 잘 사용할수 있기 때문에 @NaturalId로 맵핑 됩니다.

 

 

 

@Entity(name = "Publication")

@Table(name = "publication")

public static class Publication {

@Id

@GeneratedValue

private Long id;

private String publisher;

@ManyToOne(fetch = FetchType.LAZY)

@JoinColumn(

name = "isbn",

referencedColumnName = "isbn"

)

private Book book;

@Column(

name = "price_in_cents",

nullable = false

)

private Integer priceCents;

private String currency;

//Getters and setters omitted for brevity

}

 

Publication은 관계에서 자식이다.

기본적으로 @ManyToOne 연결에서는 부모측 엔터티 식별자가 자식의 외부키 열과 조인하는데 사용된다고 가정 되나, 비식별자 연관을 할때는 referencedColumnName을 사용하여 ManyToOne 관계를 설정하기 위해 부모측에 어떤컬럼이 사용되어야 하는지를 설정합니다.

 

 

 

Publication publication = entityManager.createQuery(

"select p " +

"from Publication p " +

"join fetch p.book b " +

"where " +

" b.isbn = :isbn and " +

" p.currency = :currency", Publication.class)

.setParameter( "isbn", "978-9730228236" )

.setParameter( "currency", "&" )

.getSingleResult();

assertEquals(

"amazon.co.uk",

publication.getPublisher()

);

assertEquals(

"High-Performance Java Persistence",

publication.getBook().getTitle()

);

 

 

JQPL쿼리를 실행

 

SELECT

p.id AS id1_1_0_, b.id AS id1_0_1_,

p.isbn AS isbn5_1_0_, p.currency AS currency2_1_0_,

p.price_in_cents AS price_in3_1_0_,

p.publisher AS publishe4_1_0_,

b.author AS author2_0_1_, b.isbn AS isbn3_0_1_,

b.title AS title4_0_1_

FROM publication p

INNER JOIN

book b ON p.isbn = b.isbn

WHERE b.isbn = '978-9730228236'

AND p.currency = '&'

반응형

+ Recent posts