@NotNull annotation doesn't work as expected

Hy Nguyen October 23, 2018

Hi,

I'm trying to create an Entity class named SchemeEntity with not-null name, so I put @NotNull annotation above of getName() method.





public interface GraphicLanguageSchemeEntity extends Entity {

    @NotNull
    String getName();

    void setName(String name);

    String getDescription();

    void setDescription(String description);

    @OneToMany(reverse = "getGraphicLanguageScheme")
    WorkflowEntity[] getWorkflowGraphicEntries();

    @OneToMany(reverse = "getGraphicLanguageScheme")
    GraphicLanguageEntryEntity[] getGraphicLanguageEntries();
}



This is the code that I used to insert new object to database:


 @Override
    public GraphicLanguageSchemeEntity createGraphicLanguageScheme(String name, String description) {
        writeLock.lock();
        try {
            GraphicLanguageSchemeEntity graphicLanguageScheme = ao.create(
                GraphicLanguageSchemeEntity.class);
            graphicLanguageScheme.setName(name);
            graphicLanguageScheme.setDescription(description);
            graphicLanguageScheme.save();
            return graphicLanguageScheme;
        } finally {
            writeLock.unlock();
        }
 }



As I expected, when I insert a new SchemeEntity into database, as long as it has some "name", the creating should be success.

 

But some how when I executed the code, with not-null value for name, I got the error message:


Exception: class java.lang.IllegalArgumentException The follow required fields were not set when trying to create entity '<hidden-package>.GraphicLanguageSchemeEntity', those fields are: ImmutableFieldInfo{fieldName='NAME', polymorphicName='null', accessor=public abstract java.lang.String <hidden-package>.GraphicLanguageSchemeEntity.getName(), mutator=public abstract void <hidden-package>.GraphicLanguageSchemeEntity.setName(java.lang.String), primary=false, nullable=false, autoIncrement=false, defaultValue=false, fieldType=class java.lang.String, typeInfo=String:VARCHAR, generatorType=null}

 

The error occurred in this line:

    GraphicLanguageSchemeEntity graphicLanguageScheme = ao.create(
        GraphicLanguageSchemeEntity.class);


Did I do some thing wrong in my code, or this is a SDK's bug?

1 answer

1 vote
Pascal Robert July 3, 2019

Hi @Hy Nguyen ,

I have the same problem as you. Did you find a solution?

Hy Nguyen July 3, 2019

Hi @Pascal Robert ,

 

I still have not found a solution, seems to be a tough topic.

Pascal Robert July 4, 2019

I found the solution here: https://developer.atlassian.com/server/framework/atlassian-sdk/creating-entities/#creating-an-entity-with--not-null--constraints

To create a Application entity, I use this constructor:

final Application application = ao.create(
Application.class,
new DBParam("NOM",nomApplication),
new DBParam("NO_APPLICATION",noApplication),
new DBParam("UUID",uuid),
new DBParam("NOM_ABREGE",nomAbrege)
);

 

Like Nhac Tat Nguyen likes this
Hy Nguyen July 4, 2019

@Pascal Robert  Thank you. That's is the correct answer.

Suggest an answer

Log in or Sign up to answer