사용자 도구

사이트 도구


java:jpa:entity

차이

문서의 선택한 두 판 사이의 차이를 보여줍니다.

차이 보기로 링크

다음 판
이전 판
java:jpa:entity [2020/07/05 10:29]
kwon37xi 만듦
java:jpa:entity [2022/11/09 11:17] (현재)
kwon37xi [Entity 에 넣을 정보]
줄 1: 줄 1:
 ====== JPA Entity ====== ====== JPA Entity ======
 +
 +===== Entity 에 넣을 정보 =====
 +  *  개발자는 DB 테이블보다는 Entity 를 더 많이 참조하는 경향이 있는데 여기에 충분한 정보가 없으면 컨텍스트 스위칭이 심하게 발생한다. 따라서 Entity 에 애노테이션이나 주석으로 충분한 정보를 넣어줘야 한다. DB Comment 보다 중요하다.
 +  * Entity Class 에 ''@Table'', ''@Column'' 에 정확한 정보를 넣는다. 이름, length, nullable 여부 등 최대한 넣는다.
 +  * Index 정보도 최대한 넣어주는게 좋은데, 다 넣을 수 없다면 **unique** 인덱스 정보라도 넣어준다. unique 정보는 개발할 때 중요한 비즈니스 로직 지침 사항이 돼 준다.
 +
 +===== Serializable / 직렬화 =====
 +  * ''@Id''/Primary Key 는 항상 ''Serializable'' 해야한다.
 +  * detached entity 객체가 원격으로 전송되거나, ''HttpSession'' 등에 저장되려면 Entity 자체가 ''Serializable'' 해야한다. 하지만 그럴일이 없다면 Entity 자체가 꼭 ''Serializable''할 필요는 없다.
 +  * 클러스터링 2차 캐시 사용시에(이 클러스터가 Java 직렬화로 데이터를 주고 받아서?)도 Entity 가 ''Serializable'' 해야 한다.
 +  * [[https://www.baeldung.com/jpa-entities-serializable|JPA Entities and the Serializable Interface | Baeldung]]
 +  * https://stackoverflow.com/a/55434081/1051402
  
 ===== Entity Generate ===== ===== Entity Generate =====
줄 5: 줄 17:
   * [[https://github.com/smartnews/jpa-entity-generator|smartnews/jpa-entity-generator: Lombok-wired JPA entity source code generator, Gradle and Maven supported.]]   * [[https://github.com/smartnews/jpa-entity-generator|smartnews/jpa-entity-generator: Lombok-wired JPA entity source code generator, Gradle and Maven supported.]]
   * [[https://www.eclipse.org/webtools/dali/docs/3.2/user_guide/tasks006.htm|Generating entities from tables]] Ecilpse   * [[https://www.eclipse.org/webtools/dali/docs/3.2/user_guide/tasks006.htm|Generating entities from tables]] Ecilpse
-  * [[https://mogamoya.tistory.com/entry/%ED%8C%81-intellij-database-schema-%EA%B8%B0%EB%B0%98%EC%9C%BC%EB%A1%9C-%EC%9D%BC%EA%B4%84-%EC%97%94%ED%8B%B0%ED%8B%B0-%ED%81%B4%EB%9E%98%EC%8A%A4-%EC%83%9D%EC%84%B1%ED%95%98%EA%B8%B0|[팁] intellij database schema 기반으로 일괄 엔티티 클래스 생성하기 :: 모가 모야]] 
-  * [[:intellij_idea|IntelliJ IDEA]]는 ''persistence.xml''이 추가되면 자동 생성옵션이 활성화 되지만 자유도가 떨어진다. 
  
 ==== Intellij DB 스키마로부터 JPA Entity 생성하기 ==== ==== Intellij DB 스키마로부터 JPA Entity 생성하기 ====
-  * +  * [[https://mogamoya.tistory.com/entry/%ED%8C%81-intellij-database-schema-%EA%B8%B0%EB%B0%98%EC%9C%BC%EB%A1%9C-%EC%9D%BC%EA%B4%84-%EC%97%94%ED%8B%B0%ED%8B%B0-%ED%81%B4%EB%9E%98%EC%8A%A4-%EC%83%9D%EC%84%B1%ED%95%98%EA%B8%B0|[팁] intellij database schema 기반으로 일괄 엔티티 클래스 생성하기 :: 모가 모야]] 
 +  * [[:intellij_idea|IntelliJ IDEA]]는 ''persistence.xml''이 추가되면 자동 생성옵션이 활성화 되지만 자유도가 떨어진다. 
 +  * [[:intellij_idea|IntelliJ IDEA]]에서 **Database** 연결을 생성하고 Table 을 우클릭하여, **Scripted Extensions** 에서 **Go To Scripts Directory** 를 실행한다. 
 +  * 해당 디렉토리에 [[https://gist.github.com/kwon37xi/404b075c2258e1df3ccbb04fdd0be525|Generate JPA Entities.groovy]] gist 소스를 복사해 넣는다. 
 +    * [[https://gist.github.com/virtualadrian/519fe0dc6658fe60500067bee3134c97|IntelliJ Generators For Entity ( JPA Entity, View Model, Rest Controller ) - WIP plz comment with desires -]] 
 +  * 이제 다시 **Scripted Extensions -> Generate JPA Entities.groovy** 를 선택하면 Entity 소스가 생성된다. 
 +  * [[java:lombok|Lombok]] 기반이므로 lombok 이 필요하다.
  
  
  
java/jpa/entity.1593912546.txt.gz · 마지막으로 수정됨: 2020/07/05 10:29 저자 kwon37xi