-
Notifications
You must be signed in to change notification settings - Fork 115
Add a way to differentiate between nullability on the client side vs nullability on the database side #904
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
Comments
I have a large program written with jimmer and I have encountered various situations, but jimmer does not need what you wrote. Everything works there with inserting nested elements. Check the ID generation on the database side. |
You need to understand how databases work, jimmer is a wrapper that syncs with your database settings and allows you to easily interact with them. If you can't design the database correctly, then no ORM will help you here. |
You are saving incorrectly. It is done through Draft.$ ... https://babyfish-ct.github.io/jimmer-doc/docs/mutation/save-command/input-dto/null-handling/#null-related-issues-in-data-input Filling in the ID is optional even if it is "long" |
Jimmer's Input DTOs can help you. Input DTOs provide a solution to your problem by allowing properties to be nullable on the client side (Input DTO) while ensuring they are non-null on the database side (Entity). With Input DTOs, you can handle the
Key Points:
This behavior allows you to have nullable properties on the client side while ensuring they are non-null on the database side. For more details, please see DTO Language / 7.Nullability and DTO Language / 3.2 input-specific functionalities. |
Hi, sorry for late reply because of 8-days Chinese new year. Yes, @storympro and @runnableAir are right, the InputDTO can help you.
|
Reason
From the docs:
This is leads to the problem. Let's say I have Java an entity like this:
As you see, It has ID as an identity column in the database. The problem is that this property has the
NOT NULL
constraint on the database side, which makes total sense, I guess, for everybody. That means, that if we would usejimmer.database-validation-mode: ERROR
(which by the way is a great feature), we're forced to use a primitive type likelong
.The problem is, that we cannot just leave it as it is, because if we would try to save an entity of the type
Book
where we do not provide the ID in the DTO from which theBook
is constructed (because we have an identity column), we would get an error:The actual saving code that executes
save()
is this (simplified):And we really cannot do much. We cannot use
Long
as a wrapper class, because the column is indeedNOT NULL
, and Jimmer would complain. Adding carious annotations like@TNullable
etc. does not really help at all. So we hit a conundrum.Description
Already explained above.
Existing solutions
So, my proposal is to do the following: We need to distinguish between 2 things:
For primitives/wrappers case, we can use a wrapper class and also apply an annotation (a newly created one perhaps) that says that this column is possible to be nullable on the client side, but on the database side it is never null. So that the jimmer schema checker can understand that the use of the wrapper here is appropriate.
The text was updated successfully, but these errors were encountered: