1

I have 2 entities that needed to be persisted in two different DB's:

1) MyClassMetaData - persisted on mysql via jpa+hibernate in spring (entityManager)

2) MyClassRawData - persisted on mongoDB via spring data (mongoTemplate)

There is a one To one Relation between the two entities: There is no meaning for only one entitiesto be persisted without the other. there will always be a metadata AND rawdata for each save.

My service for saving these 2 entities looks like this

@Transactional
public void saveMyClass(metadata, rawdata){

 // Do Something here
 this.entityManager.persist(metadata);
 this.mongoTemplate.save(rawData);

}

My question is: how do i make sure that if an error occurs on this save method - a rollback will take place and for both classes?

thanks

Urbanleg
  • 6,252
  • 16
  • 76
  • 139

1 Answers1

0

This might be what you want to achieve: http://static.springsource.org/spring-data/mongodb/docs/current/reference/html/mongo.cross.store.html However it ties the two entities strictly together.

Juraj Misur
  • 1,338
  • 1
  • 11
  • 7
  • This has been removed in Spring data 2.0. I have the same problem, and don't know how to handle it. – Teocali Oct 29 '22 at 20:24