line / kotlin-jdsl

Kotlin library that makes it easy to build and execute queries without generated metamodel
https://kotlin-jdsl.gitbook.io/docs/
Apache License 2.0
686 stars 85 forks source link

Java Class Entity 호출 이슈 #64

Closed oen142 closed 2 years ago

oen142 commented 2 years ago

안녕하세요. 해당 라이브러리를 잘 쓰고 있습니다.

현재 제 프로젝트에서는 Java Entity를 사용하고 있고, Kotlin jdsl 에서 Java Entity를 호출해 사용하려고합니다.

기본적으로 kotlin은 private을 붙이지 않으면 외부 참조가 가능한걸로 돼있는데, Java Class 필드는 보통 private을 붙여서 사용하고 있습니다.

@Entity
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class RevealPosition extends BaseTimeEntity {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "position_id")
    private Long id;

image

해당 사진과 같이 호출을 하고 싶으나 할수 없는 상태입니다.

자바 Entity를 해당 KProperty로 바꾸려고 시도는 해봤는데, 잘 모르겠습니다. property: KProperty1<T, R>

자바 Entity도 호출할수 있는 아이디어 주시면 감사하겠습니다!

cj848 commented 2 years ago

-- korean 안녕하세요 말씀해주신 부분은 언어의 한계적인 부분으로 자바는 Kotlin처럼 컴파일타임에 KProperty를 생성을 하지 않습니다. 그러므로 별도의 방법은 없으며 public 으로 바꾸어도 처리가 불가능하니 엔티티를 Kotlin으로 전환하는 것을 추천드립니다.

-- english Hello, the part you mentioned is a limited part of the language, and Java does not create KProperty at compile time like Kotlin. Therefore, there is no other way, and it is impossible to process it even if it is changed to public , so it is recommended to convert the entity to Kotlin.

shouwn commented 2 years ago

@oen142 안녕하세요. README 부분을 확인하시면 KProperty는 아래와 같은 클래스를 만드는 것을 확인하실 수 있습니다.

image

그렇기 때문에 직접 위와 같은 클래스를 만드시면 사용하실 수 있습니다. QueryDSL에서 Q 클래스를 직접 만드는 작업과 동일하게 각 필드별로 하나씩 만들어주셔야 합니다.

그렇기 때문에 cj848 님이 말씀해주신 것처럼 Entity 만이라도 Kotlin으로 전환하는 것을 추천 드립니다.

oen142 commented 2 years ago

@cj848 @shouwn 두 분다 답변 감사합니다! 참고 많이 됐습니다!