You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
constructor(privatereadonlyentityManager: EntityManager){}asyncsaveMyPost(text){constpost=newPost();// Post is Entitypost.content=text;awaitthis.entityManager.persistAndFlush(post);}asyncmyMethod(){awaitthis.saveMyPost('THIS_WILL_BE_SAVE');awaitthis.entityManager.transactional(asyncem=>{constuser=newUser();user.name='myName';em.persist(user);awaitthis.saveMyPost('THIS_WILL_NOT_BE_SAVE');if(true){thrownewError('CUSTOM_ERROR');}awaitem.flush();});}
If I call myMethod(), then I expected 2 rows created on Post. (THIS_WILL_BE_SAVE, THIS_WILL_NOT_BE_SAVE)
because I think saveMyPost method have different database session(connection).
But just 1 row created on Post table. (THIS_WILL_BE_SAVE)
every database query in entityManager.transactional callback method is wrapped single transaction? likes @Transaction decorator of typeorm or @Transactinoal annotation of Spring.
How is this possible? Each http request keeps each database connection until response?
I want to understand about how it works.
So Is there a document that I can understand about this part? Or I want to know the location of the code about that.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi I have a question about transaction scope.
below is some part of my nestjs application code.
If I call
myMethod()
, then I expected 2 rows created on Post. (THIS_WILL_BE_SAVE, THIS_WILL_NOT_BE_SAVE)because I think
saveMyPost
method have different database session(connection).But just 1 row created on Post table. (THIS_WILL_BE_SAVE)
every database query in entityManager.transactional callback method is wrapped single transaction? likes
@Transaction
decorator of typeorm or@Transactinoal
annotation of Spring.How is this possible? Each http request keeps each database connection until response?
I want to understand about how it works.
So Is there a document that I can understand about this part? Or I want to know the location of the code about that.
Beta Was this translation helpful? Give feedback.
All reactions