package com.oguerreiro.resilient.repository;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import jakarta.persistence.EntityManager;

@Repository
public class ResilientNewTransactionRepositoryExtendedImpl<T> implements ResilientNewTransactionRepositoryExtended<T> {
  @Autowired
  private EntityManager entityManager;

  @Override
  @Transactional(propagation = Propagation.REQUIRES_NEW)
  public void saveInNewTransaction(T domain) {
    // Persist the entity in a new transaction
    entityManager.persist(domain);
  }

}
