IllegalArgumentException: entityId is null

I have this case: in entity I set a sequence with @GeneratedValue and @SequenceGenerator.
I use a Db where it is set for each ID(primary key) to have auto increment with special sequense. This is the reason to use this annotation to connect corrently the sequense.

When I try to insert a new record, the jmix displays this error (entityId is null) but the data is inserted in db.

I try to fix it with your @JmixGeneratedValue(sequenceName = “sequence_name”),
but it genarates a new Id always when I open the screen for inserting, no matter if I save the data in db or not.

I want to generate a new ID only when i have a record in db.

thank you an advance :slight_smile:
I have this case: in entity I set a sequence with @GeneratedValue and @SequenceGenerator.
I use a Db where it is set for each ID(primary key) to have auto increment with special sequense. This is the reason to use this annotation to connect corrently the sequense.

When I try to insert a new record, the jmix displays this error (entityId is null) but the data is inserted in db.

I try to fix it with your @JmixGeneratedValue(sequenceName = “sequence_name”),
but it genarates a new Id always when I open the screen for inserting, no matter if I save the data in db or not.

I want to generate a new ID only when i have a record in db.

thank you an advance :smile:

Hello,
Thank you for highlighting the issue.

Unfortunately, we cannot reproduce the problem. We will be able to help you if you send us a small sample project along with step by step scenario of actions taken prior to getting an error.
Also,in case you will encounter any other problems in the future - it would help us a lot if you could share with us the following data:

  • your environment specifications (OS/IDEA versions and any additional libraries used)
  • jmix / jmix.plugin versions

Hi @georgi.minchev
Use the following parameters when creating entity (with or without “Has UUID” trait):

image

You will get entity code like this, and it should work:

@JmixEntity
@Table(name = "FOO")
@Entity
public class Foo {
    @Column(name = "ID", nullable = false)
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "foo_seq")
    @SequenceGenerator(name = "foo_seq", sequenceName = "foo_seq", allocationSize = 1)
    private Long id;

// ...

Hi,

Here is my test project https://github.com/gminchev1982/documents-jmix/tree/master

  1. in Document Entity i set the sequence with
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = “DOCUMENTS_ID_SEQ”)
    @SequenceGenerator(name = “DOCUMENTS_ID_SEQ”, sequenceName = “DOCUMENTS_ID_SEQ”, allocationSize = 1)

When I save a new record I received: EntityId is null

  1. In CorrespondenceType Entity : I set the sequence with @JmixGeneratedValue(sequenceName = “CORRESPONDENCE_TYPE_ID_SEQ”)

Always when I open the screen for inserting, the Id field has a new value(+1) no matter if I save the data in db or not.

I want to generate a new ID only when i have a record in db.

Hi Georgi,
Thanks for the project.

Remove all Lombok annotations from the Document entity, and it will work as expected.

Lombok enhancements prevent from correct generation of ID required for displaying entities in UI.

Regards,
Konstantin

Good day. I have a similar problem
There are two entities: Contractor and license. license is a composite attribute (one2many) of the Contractor entity. Entities have an id of type long with filling using sequence. I tried auto-increment, same thing).
I add a license on the Contractor entry form and an error occurs. openMode=“DIALOG”.

It works normally only when the field IDs have the @JmixGeneratedValut annotation; in all other entities an error occurs.
Lombok is not used.

     @Column(name = "ID", nullable = false)
     @Id
     @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "re2_license_seq")
     @SequenceGenerator(name = "re2_license_seq", sequenceName = "re2_license_seq", allocationSize = 1)
     private Long id;

image

Hi Anton,
Could you provide a test project with these entities and views?

Hi, Konstantin.

example:

Thank you for the test project.
The issue is fixed, the fix will be available in the next 2.1 patch.