chapinsky
(Serg Pinsky)
July 13, 2021, 9:05am
1
create jmix 1.0.0 project (jdk 11.0.8)
add new JPA Entity with Id type UUID (annotated @JmixGeneratedValue by default)
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;
....
}
Create Master-detail screen
Start application and create entity - all works
Generate onAfterInit event handler
@Subscribe
public void onAfterInit(AfterInitEvent event) {
Test test = new Test();
test.setName("test name");
dataManager.save(test);
}
Open Master-detail screen: IllegalStateException: Generated ID is null in com.company.test3.entity.Test-null [new]
chapinsky
(Serg Pinsky)
July 14, 2021, 1:55am
2
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.
2 Likes