[Spring][Transaction] Multiple DAO
Bonjour à tous,
J'ai des petits soucis avec les transactions et spring... Je vous explique:
J'ai cette classe:
Code:
1 2 3 4 5 6 7 8 9 10 11 12
| @Service("calendrierBR")
public class CalendrierBRImpl implements ICalendrierBR {
/**
* Logger for this class
*/
private static final Logger logger = Logger
.getLogger(CalendrierBRImpl.class);
@Resource
private ITacheDAO tacheDAO;
@Resource
private IActiviteDAO activiteDAO; |
Et j'ai dans cette classe une méthode transactionnelle:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
@Transactional
public void insert(Activite activite, double jourAInserer, Date parse) {
[...]
activite = activiteDAO.save(activite);
while (jourAInserer > 0) {
for (short i = 1; i <= 4; i++) {
[...]
tacheDAO.findTache([...]);
[...]
tacheDAO.save([...]);
}
}
} |
Mes DAO sont comme ceci:
Code:
1 2 3 4 5 6
|
@Repository
public class ActiviteDAO implements IActiviteDAO{
@PersistenceContext(type = PersistenceContextType.EXTENDED)
private EntityManager entityManager; |
Je pensais que lorsqu'on déclarait une méthode transactionnelle, tous les dao que l'on utilise à l'intérieur de celle ci partage la même transaction, et donc la même session... Hors ce n'est pas le cas. Je le vois d'ailleurs au niveau des log:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
DEBUG - [CalendrierBRImpl] -> insertion des taches
DEBUG - [ActiviteDAO] -> saving Activite instance
DEBUG - [SessionImpl] -> opened session at timestamp: 12380808097
DEBUG - [JDBCTransaction] -> begin
DEBUG - [ConnectionManager] -> opening JDBC connection
DEBUG - [DriverManagerDataSource] -> Creating new JDBC DriverManager Connection to [jdbc:postgresql://localhost/suiviactivite]
DEBUG - [JDBCTransaction] -> current autocommit status: true
DEBUG - [JDBCTransaction] -> disabling autocommit
DEBUG - [ExtendedEntityManagerCreator$ExtendedEntityManagerInvocationHandler] -> Starting resource local transaction on application-managed EntityManager [org.hibernate.ejb.EntityManagerImpl@1f7dbd8]
DEBUG - [ExtendedEntityManagerCreator$ExtendedEntityManagerInvocationHandler] -> Joined local transaction
[...]
DEBUG - [BatchingBatcher] -> Executing batch size: 1
DEBUG - [AbstractBatcher] -> about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
DEBUG - [ActiviteDAO] -> persist successful
DEBUG - [TacheDAO] -> findTache
DEBUG - [SessionImpl] -> opened session at timestamp: 12380808100
DEBUG - [JDBCTransaction] -> begin
DEBUG - [ConnectionManager] -> opening JDBC connection
[...] |
On le voit bien... il fait deux fois un begin. Il ne devrait le faire qu'une seule fois, non ?!
Je pense que cela vient d'une mauvaise configuration de ma part... Pouvez-vous m'aider ?