Skip to content

Generated draft type dissallows null values #1023

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

Open
mipo256 opened this issue May 6, 2025 · 2 comments
Open

Generated draft type dissallows null values #1023

mipo256 opened this issue May 6, 2025 · 2 comments
Labels
bug Something isn't working

Comments

@mipo256
Copy link

mipo256 commented May 6, 2025

Jimmer Version

0.9.37

JDK Version

JDK 17

Database

H2

OS

Linux

Expected behavior

The scalar property can be set to null to INSERT/UPDATE null values.

Actual behavior

The exception is thrown:

java.lang.IllegalArgumentException: 'title' cannot be null, please specify non-null value or use nullable annotation to decorate this property

	at io.learnbydoing.models.BookDraft$Producer$DraftImpl.setTitle(BookDraft.java:628)
	at io.learnbydoing.repository.BookRepository.lambda$insertExplicitlySetTitleToNull$1(BookRepository.java:23)
	at org.babyfish.jimmer.runtime.Internal.modifyDraft(Internal.java:173)
	at org.babyfish.jimmer.runtime.Internal.lambda$produce$0(Internal.java:28)
	at org.babyfish.jimmer.runtime.Internal.usingDraftContext(Internal.java:102)
	at org.babyfish.jimmer.runtime.Internal.produce(Internal.java:26)
	at io.learnbydoing.models.BookDraft$Producer.produce(BookDraft.java:123)
	at io.learnbydoing.models.BookDraft$Producer.produce(BookDraft.java:119)
	at io.learnbydoing.repository.BookRepository.insertExplicitlySetTitleToNull(BookRepository.java:18)
	at io.learnbydoing.repository.BookRepositoryTest.insertExplicitlySetTitleToNull(BookRepositoryTest.java:38)
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)

Description

I've created the MRE, please check here: https://github.com/mipo256/jimmer-draft-scalar-to-null

In the Null Handling section of the documentation, there is an example with the Draft type of setting the property to null. This is the property of the relation, strictly speaking, and the generated BookDraft indeed would allow storing the null in the storeId. However, if I want to explicitly set the scalar property to null, the exception is thrown:

java.lang.IllegalArgumentException: 'title' cannot be null, please specify non-null value or use nullable annotation to decorate this property

The title property itself is both nullable in the H2 database, and in the POJO and is marked with @TNullable

Reproduction steps

Clone the project and execute the test BookRepositoryTest#insertExplicitlySetTitleToNull()

Generated SQL

N/A

Relation Model

The schema is set up in the init.sql in the test resources by the following SQL:

CREATE TABLE IF NOT EXISTS AUTHOR(
    ID BIGSERIAL PRIMARY KEY,
    FIRST_NAME TEXT NOT NULL,
    LAST_NAME TEXT NOT NULL
);

CREATE TABLE IF NOT EXISTS BOOK(
    ID BIGSERIAL PRIMARY KEY,
    TITLE TEXT,
    CREATED_AT TEXT,
    AUTHOR_ID BIGINT NOT NULL  REFERENCES AUTHOR(ID)
);

Screenshots

N/A

Logs

Already pasted above

@mipo256 mipo256 added the bug Something isn't working label May 6, 2025
@babyfish-ct
Copy link
Owner

The annotation is designed for jimmer-swagger, not the orm itself.

The annotation org.jetbrains.annotations.Nullabe (or any annotation whose name ends with Nullable or Null) id designed for the framework.

This org.jetbrains.annotations.Nullabe can be used like this

@Nullable
Type value;

but, unfortunately, it cannot be used like this

List<@Nullable ElementType> values;

So this annotation is designed like this

List<@TNullable ElementType> values;

If original design goal of this annotation is to support more nullity information which cannot be described by jetbrains annotation. let the nullity information can be as powerful as kotlin.

If the framework itself wants to support TNullable, its package org.babyfish.jimmer.clinet must be renamed to org.babyfish.jimmer.lang, is it acceptalbe?

@babyfish-ct
Copy link
Owner

babyfish-ct commented May 6, 2025

Now I changed the doc like this

Image

If it should be used to affect the behavior of the framework itself, its package org.babyfish.jimmer.clinet must be renamed to org.babyfish.jimmer.lang, is it acceptalbe?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants