-
Notifications
You must be signed in to change notification settings - Fork 81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is it possible to support rendering query that contains entities with value class
fields?
#559
Comments
Hi, leviathan-n. I'll look into it in detail this weekend, but supporting a value class doesn't seem easy for two reasons. The first is that Kotlin automatically wraps the value class when it is passed to an external library. Because of this, Kotlin JDSL has to use reflection every time to check if the passed value is the value class and to extract the value of the value class. The second reason is the most problematic: Kotlin unboxes the value class field when it compiles to Java. It seems difficult to make them compatible without creating a new expression function. |
I reviewed value classes and my conclusion was to support them informally with guides. I think it's too early to formally support value classes, because there are many risks.
For these reasons, I don't think value classes are ready for library support yet. However, I think it would be a waste not to use value classes, so I thought I'd provide some informal guidance. The current problem is that the Kotlin JDSL needs to unbox value classes that are passed as parameters. To make this possible, we can implement a JpqlSerializer for JpqlValue. There are several ways to implement a JpqlSerializer. You can either list the value classes in advance and implement your own logic to unbox the value passed as a parameter if it matches, or you can use Kotlin reflection to get the value using the first property if the type is a value class. I'll leave it up to the user to decide which one to choose. If you are comfortable with this approach, I will create a document for value class. |
Sorry I saw your reaction too late. I'll leave how to use value class in the documentation. Thanks for your cooperation! |
@shouwn 안녕하세요! 어사인 요청드립니다. :) |
작업 예정이신가요? 어사인 드렸습니다 :) 정신없어서 계속 못하고 있었는데 감사합니다. |
@erie0210 감사합니다! |
spring data add support for kotlin value class at version 3.2 , so we can define an entity like this to avoid primitive obsession:
and saying that there is a simple query
and got an exception when executing it
The text was updated successfully, but these errors were encountered: