It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

@NotNull annotation doesn't work as expected Edited

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

Hi @Hy Nguyen ,

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

Hi @Pascal Robert ,

 

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

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

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

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted in Jira

Calling all Jira Cloud users! Give us feedback on our exploration of a new navigation.

Hi everyone! My name’s Matt and I’m a product manager at Atlassian. I work in the navigation & findability space for all our Jira Cloud products. We’ve been working on trying to improve the exp...

1,045 views 16 12
Join discussion

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you