@Entity
public class Project extends AbstractAnnotatedAggregateRoot {
@Id
@GeneratedValue
private Long id;
private String name;
}
My entity looks like the above I am using the jpaRepository for persistence.
When i use the below code for persistence
Project project = new Project(initiateProjectCommand.name);
projectRepository.add(project);
It fails with the AggregateIdentifierNotInitializedException exception. It expects that id field should already be having a value … is this ok?
@Entity
public class Project extends AbstractAnnotatedAggregateRoot {
@Id
@GeneratedValue
private Long id;
@AggregateIdentifier
private String projectId = “1”;
}
I then updated my entity to look like the above. However it still fails, because the locateIdentifierField in AggregateAnnotationInspector locates the id field first which is not initialized.
@Entity
public class Project extends AbstractAnnotatedAggregateRoot {
@AggregateIdentifier
private String projectId = “1”;
// Note the change in order
@Id
@GeneratedValue
private Long id;
}
The above code works ! Some how i think there is a bug lurking around here. How do we publish event which using the JpaRepository for persistence of aggregates ?
"The AbstractAnnotatedAggregateRoot
also requires that the field containing the aggregate identifier is annotated with@AggregateIdentifier
. If you use JPA and have JPA annotations on the aggregate, Axon can also use the @Id
annotation provided by JPA.
"
Quoted from the reference manual, this is not quite followed in spirit and functionality, please let me know if there is something i have missed out … thanks