'IllegalStateException: Generated ID is null' when saving entity with id annoteted by @JmixGeneratedValue

  1. create jmix 1.0.0 project (jdk 11.0.8)
  2. add new JPA Entity with Id type UUID (annotated @JmixGeneratedValue by default)
  3. Add mandatory String attribute
@JmixEntity
@Table(name = "TEST")
@Entity
public class Test {
    @JmixGeneratedValue
    @Column(name = "ID", nullable = false)
    @Id
    private UUID id;

    @Column(name = "NAME", nullable = false)
    @NotNull
    private String name;
    ....
}
  1. Create Master-detail screen
  2. Start application and create entity - all works
  3. Generate onAfterInit event handler
    @Subscribe
    public void onAfterInit(AfterInitEvent event) {
        Test test = new Test();
        test.setName("test name");
        dataManager.save(test);
    }
  1. Open Master-detail screen: IllegalStateException: Generated ID is null in com.company.test3.entity.Test-null [new]

Caution of @JmixGeneratedValue documentation says: Note that the @JmixGeneratedValue annotation doesn’t take any effect if you create an entity instance using the new operator. See instantiating entities for proper methods of creating new instances.

1 Like