Multiple entity Aggregate

Hi,

I’m trying to figure out the best/correct way to handle the following problem in a JPA aggregate scenario:

AggregateA has an aggregate member EntityA. AggregateA contains a method that changes some state and also needs to create an EntityA if it doesn’t exist already. How should this be handled with Axon? I have tried to create a new EntityA (thinking it would be automatically handled) but get the following error:

“java.lang.IllegalStateException, org.hibernate.TransientPropertyValueException: object references an unsaved transient instance - save the transient instance before flushing”.

Previously, before adding EntityA as an aggregate member, I was creating EntityA using a command constructor but I believe EntityA is really an aggregate member so would like to control it from AggregateA.

Apologies if I am missing something really obvious here.

Thanks

Adding Cascade(CascadeType.PERSIST) to EntityA fixed the issue below so now creating the new EntityA from within the AggregateA works nicely.

Hi Ralph,

Happy to hear you figured out the issue yourself, and thanks for providing your process on the usergroup!

Typically, when using the JPA repository to store your Aggregates instead of Event Sourcing, and you have Aggregate Members in your Aggregate, you need to think about the required JPA annotations to store them in the form you want them to be stored.

If you encounter any future problems, do not hesitate to post a question!

Cheers,
Steven

Cheers Steven, I was too focused on Axon, rookie error I suppose