Transactional Propagation.REQUIRES_NEW not work












0














I try save list of entities to Oracle Db.



@Transactional
public void save() {
//logick
for (QuittanceType quittanceType : quittance) {
quittancesService.parseQuittance(quittanceType);
}
//logick
}


On each step I call this method:



@Transactional
@Override
public void parseQuittance(QuittanceType quittance) {
try {

//logick create payToChargeDb
paymentToChargeService.saveAndFlush(payToChargeDb);

} catch (Exception e) {
log.warn("Ignore.", e);
}
}


and method



        @Override
public PaymentsToCharge saveAndFlushIn(PaymentsToCharge paymentsToCharge) {
return paymentToChargeRepository.saveAndFlush(paymentsToCharge);
}


When I try save entity with constraint My main transaction rollback and I get stacktrace:



Caused by: java.sql.BatchUpdateException: ORA-02290: CHECK integrity constraint violated(MYDB.PAYMENTS_TO_CHARGE_CHK1)


But I want skip not success entities and save success. I marck my method



@Transactional(propagation = Propagation.REQUIRES_NEW)


and it look like this:



@Transactional
@Override
public void parseQuittance(QuittanceType quittance) {
try {

//logick create payToChargeDb
paymentToChargeService.saveAndFlushInNewTransaction(payToChargeDb);

} catch (Exception e) {
log.warn("Ignore.", e);
}
}


and



@Transactional(propagation = Propagation.REQUIRES_NEW)
@Override
public PaymentsToCharge saveAndFlushInNewTransaction(PaymentsToCharge paymentsToCharge) {
return paymentToChargeRepository.saveAndFlush(paymentsToCharge);
}


But when I try save entity with constraint I not get exception and not enter to catcj block. just stop working debugging and the application continues to work. I do not get any errors. and as if rollback is happening










share|improve this question
























  • Is your saveAndFlushInNewTransaction part of the same class as parseQuittance?
    – AlexB
    Nov 23 '18 at 14:27










  • Have you tried removing the @Transactional annotation from save() and parseQuittance() methods and leave it only on saveAndFlushInNewTransaction()?
    – pleft
    Nov 23 '18 at 14:30


















0














I try save list of entities to Oracle Db.



@Transactional
public void save() {
//logick
for (QuittanceType quittanceType : quittance) {
quittancesService.parseQuittance(quittanceType);
}
//logick
}


On each step I call this method:



@Transactional
@Override
public void parseQuittance(QuittanceType quittance) {
try {

//logick create payToChargeDb
paymentToChargeService.saveAndFlush(payToChargeDb);

} catch (Exception e) {
log.warn("Ignore.", e);
}
}


and method



        @Override
public PaymentsToCharge saveAndFlushIn(PaymentsToCharge paymentsToCharge) {
return paymentToChargeRepository.saveAndFlush(paymentsToCharge);
}


When I try save entity with constraint My main transaction rollback and I get stacktrace:



Caused by: java.sql.BatchUpdateException: ORA-02290: CHECK integrity constraint violated(MYDB.PAYMENTS_TO_CHARGE_CHK1)


But I want skip not success entities and save success. I marck my method



@Transactional(propagation = Propagation.REQUIRES_NEW)


and it look like this:



@Transactional
@Override
public void parseQuittance(QuittanceType quittance) {
try {

//logick create payToChargeDb
paymentToChargeService.saveAndFlushInNewTransaction(payToChargeDb);

} catch (Exception e) {
log.warn("Ignore.", e);
}
}


and



@Transactional(propagation = Propagation.REQUIRES_NEW)
@Override
public PaymentsToCharge saveAndFlushInNewTransaction(PaymentsToCharge paymentsToCharge) {
return paymentToChargeRepository.saveAndFlush(paymentsToCharge);
}


But when I try save entity with constraint I not get exception and not enter to catcj block. just stop working debugging and the application continues to work. I do not get any errors. and as if rollback is happening










share|improve this question
























  • Is your saveAndFlushInNewTransaction part of the same class as parseQuittance?
    – AlexB
    Nov 23 '18 at 14:27










  • Have you tried removing the @Transactional annotation from save() and parseQuittance() methods and leave it only on saveAndFlushInNewTransaction()?
    – pleft
    Nov 23 '18 at 14:30
















0












0








0







I try save list of entities to Oracle Db.



@Transactional
public void save() {
//logick
for (QuittanceType quittanceType : quittance) {
quittancesService.parseQuittance(quittanceType);
}
//logick
}


On each step I call this method:



@Transactional
@Override
public void parseQuittance(QuittanceType quittance) {
try {

//logick create payToChargeDb
paymentToChargeService.saveAndFlush(payToChargeDb);

} catch (Exception e) {
log.warn("Ignore.", e);
}
}


and method



        @Override
public PaymentsToCharge saveAndFlushIn(PaymentsToCharge paymentsToCharge) {
return paymentToChargeRepository.saveAndFlush(paymentsToCharge);
}


When I try save entity with constraint My main transaction rollback and I get stacktrace:



Caused by: java.sql.BatchUpdateException: ORA-02290: CHECK integrity constraint violated(MYDB.PAYMENTS_TO_CHARGE_CHK1)


But I want skip not success entities and save success. I marck my method



@Transactional(propagation = Propagation.REQUIRES_NEW)


and it look like this:



@Transactional
@Override
public void parseQuittance(QuittanceType quittance) {
try {

//logick create payToChargeDb
paymentToChargeService.saveAndFlushInNewTransaction(payToChargeDb);

} catch (Exception e) {
log.warn("Ignore.", e);
}
}


and



@Transactional(propagation = Propagation.REQUIRES_NEW)
@Override
public PaymentsToCharge saveAndFlushInNewTransaction(PaymentsToCharge paymentsToCharge) {
return paymentToChargeRepository.saveAndFlush(paymentsToCharge);
}


But when I try save entity with constraint I not get exception and not enter to catcj block. just stop working debugging and the application continues to work. I do not get any errors. and as if rollback is happening










share|improve this question















I try save list of entities to Oracle Db.



@Transactional
public void save() {
//logick
for (QuittanceType quittanceType : quittance) {
quittancesService.parseQuittance(quittanceType);
}
//logick
}


On each step I call this method:



@Transactional
@Override
public void parseQuittance(QuittanceType quittance) {
try {

//logick create payToChargeDb
paymentToChargeService.saveAndFlush(payToChargeDb);

} catch (Exception e) {
log.warn("Ignore.", e);
}
}


and method



        @Override
public PaymentsToCharge saveAndFlushIn(PaymentsToCharge paymentsToCharge) {
return paymentToChargeRepository.saveAndFlush(paymentsToCharge);
}


When I try save entity with constraint My main transaction rollback and I get stacktrace:



Caused by: java.sql.BatchUpdateException: ORA-02290: CHECK integrity constraint violated(MYDB.PAYMENTS_TO_CHARGE_CHK1)


But I want skip not success entities and save success. I marck my method



@Transactional(propagation = Propagation.REQUIRES_NEW)


and it look like this:



@Transactional
@Override
public void parseQuittance(QuittanceType quittance) {
try {

//logick create payToChargeDb
paymentToChargeService.saveAndFlushInNewTransaction(payToChargeDb);

} catch (Exception e) {
log.warn("Ignore.", e);
}
}


and



@Transactional(propagation = Propagation.REQUIRES_NEW)
@Override
public PaymentsToCharge saveAndFlushInNewTransaction(PaymentsToCharge paymentsToCharge) {
return paymentToChargeRepository.saveAndFlush(paymentsToCharge);
}


But when I try save entity with constraint I not get exception and not enter to catcj block. just stop working debugging and the application continues to work. I do not get any errors. and as if rollback is happening







spring spring-boot transactions spring-data-jpa spring-transactions






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 23 '18 at 14:43









Billy Frost

1,74698




1,74698










asked Nov 23 '18 at 13:33









ip696

1,15811135




1,15811135












  • Is your saveAndFlushInNewTransaction part of the same class as parseQuittance?
    – AlexB
    Nov 23 '18 at 14:27










  • Have you tried removing the @Transactional annotation from save() and parseQuittance() methods and leave it only on saveAndFlushInNewTransaction()?
    – pleft
    Nov 23 '18 at 14:30




















  • Is your saveAndFlushInNewTransaction part of the same class as parseQuittance?
    – AlexB
    Nov 23 '18 at 14:27










  • Have you tried removing the @Transactional annotation from save() and parseQuittance() methods and leave it only on saveAndFlushInNewTransaction()?
    – pleft
    Nov 23 '18 at 14:30


















Is your saveAndFlushInNewTransaction part of the same class as parseQuittance?
– AlexB
Nov 23 '18 at 14:27




Is your saveAndFlushInNewTransaction part of the same class as parseQuittance?
– AlexB
Nov 23 '18 at 14:27












Have you tried removing the @Transactional annotation from save() and parseQuittance() methods and leave it only on saveAndFlushInNewTransaction()?
– pleft
Nov 23 '18 at 14:30






Have you tried removing the @Transactional annotation from save() and parseQuittance() methods and leave it only on saveAndFlushInNewTransaction()?
– pleft
Nov 23 '18 at 14:30














1 Answer
1






active

oldest

votes


















0














The proxy created by @Transactional does not intercept calls within the object.




In proxy mode (which is the default), only external method calls
coming in through the proxy are intercepted. This means that
self-invocation (in effect, a method within the target object calling
another method of the target object) does not lead to an actual
transaction at runtime even if the invoked method is marked with
@Transactional. Also, the proxy must be fully initialized to provide
the expected behavior, so you should not rely on this feature in your
initialization code (that is, @PostConstruct).




https://docs.spring.io/spring/docs/current/spring-framework-reference/data-access.html#transaction-declarative



The same documentation recommends use of AspectJ if you want this behaviour.






share|improve this answer

















  • 1




    quittancesService.parseQuittance and paymentToChargeService.saveAndFlush apparently they are in different service classes so the @Transactional annotation should work.
    – pleft
    Nov 23 '18 at 14:43










  • The OP has not posted any class structure. I think downvotes are unwarranted, as this behaviour can be a "gotcha", and given the lack of information, could be the answer.
    – AlexB
    Nov 29 '18 at 14:39












  • The downvote is not mine. Although not very clear, the methods in question belong to different classes (see my comment above) so this answer is based on a false assumption.
    – pleft
    Nov 29 '18 at 14:46











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53447687%2ftransactional-propagation-requires-new-not-work%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














The proxy created by @Transactional does not intercept calls within the object.




In proxy mode (which is the default), only external method calls
coming in through the proxy are intercepted. This means that
self-invocation (in effect, a method within the target object calling
another method of the target object) does not lead to an actual
transaction at runtime even if the invoked method is marked with
@Transactional. Also, the proxy must be fully initialized to provide
the expected behavior, so you should not rely on this feature in your
initialization code (that is, @PostConstruct).




https://docs.spring.io/spring/docs/current/spring-framework-reference/data-access.html#transaction-declarative



The same documentation recommends use of AspectJ if you want this behaviour.






share|improve this answer

















  • 1




    quittancesService.parseQuittance and paymentToChargeService.saveAndFlush apparently they are in different service classes so the @Transactional annotation should work.
    – pleft
    Nov 23 '18 at 14:43










  • The OP has not posted any class structure. I think downvotes are unwarranted, as this behaviour can be a "gotcha", and given the lack of information, could be the answer.
    – AlexB
    Nov 29 '18 at 14:39












  • The downvote is not mine. Although not very clear, the methods in question belong to different classes (see my comment above) so this answer is based on a false assumption.
    – pleft
    Nov 29 '18 at 14:46
















0














The proxy created by @Transactional does not intercept calls within the object.




In proxy mode (which is the default), only external method calls
coming in through the proxy are intercepted. This means that
self-invocation (in effect, a method within the target object calling
another method of the target object) does not lead to an actual
transaction at runtime even if the invoked method is marked with
@Transactional. Also, the proxy must be fully initialized to provide
the expected behavior, so you should not rely on this feature in your
initialization code (that is, @PostConstruct).




https://docs.spring.io/spring/docs/current/spring-framework-reference/data-access.html#transaction-declarative



The same documentation recommends use of AspectJ if you want this behaviour.






share|improve this answer

















  • 1




    quittancesService.parseQuittance and paymentToChargeService.saveAndFlush apparently they are in different service classes so the @Transactional annotation should work.
    – pleft
    Nov 23 '18 at 14:43










  • The OP has not posted any class structure. I think downvotes are unwarranted, as this behaviour can be a "gotcha", and given the lack of information, could be the answer.
    – AlexB
    Nov 29 '18 at 14:39












  • The downvote is not mine. Although not very clear, the methods in question belong to different classes (see my comment above) so this answer is based on a false assumption.
    – pleft
    Nov 29 '18 at 14:46














0












0








0






The proxy created by @Transactional does not intercept calls within the object.




In proxy mode (which is the default), only external method calls
coming in through the proxy are intercepted. This means that
self-invocation (in effect, a method within the target object calling
another method of the target object) does not lead to an actual
transaction at runtime even if the invoked method is marked with
@Transactional. Also, the proxy must be fully initialized to provide
the expected behavior, so you should not rely on this feature in your
initialization code (that is, @PostConstruct).




https://docs.spring.io/spring/docs/current/spring-framework-reference/data-access.html#transaction-declarative



The same documentation recommends use of AspectJ if you want this behaviour.






share|improve this answer












The proxy created by @Transactional does not intercept calls within the object.




In proxy mode (which is the default), only external method calls
coming in through the proxy are intercepted. This means that
self-invocation (in effect, a method within the target object calling
another method of the target object) does not lead to an actual
transaction at runtime even if the invoked method is marked with
@Transactional. Also, the proxy must be fully initialized to provide
the expected behavior, so you should not rely on this feature in your
initialization code (that is, @PostConstruct).




https://docs.spring.io/spring/docs/current/spring-framework-reference/data-access.html#transaction-declarative



The same documentation recommends use of AspectJ if you want this behaviour.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 23 '18 at 14:34









AlexB

1043




1043








  • 1




    quittancesService.parseQuittance and paymentToChargeService.saveAndFlush apparently they are in different service classes so the @Transactional annotation should work.
    – pleft
    Nov 23 '18 at 14:43










  • The OP has not posted any class structure. I think downvotes are unwarranted, as this behaviour can be a "gotcha", and given the lack of information, could be the answer.
    – AlexB
    Nov 29 '18 at 14:39












  • The downvote is not mine. Although not very clear, the methods in question belong to different classes (see my comment above) so this answer is based on a false assumption.
    – pleft
    Nov 29 '18 at 14:46














  • 1




    quittancesService.parseQuittance and paymentToChargeService.saveAndFlush apparently they are in different service classes so the @Transactional annotation should work.
    – pleft
    Nov 23 '18 at 14:43










  • The OP has not posted any class structure. I think downvotes are unwarranted, as this behaviour can be a "gotcha", and given the lack of information, could be the answer.
    – AlexB
    Nov 29 '18 at 14:39












  • The downvote is not mine. Although not very clear, the methods in question belong to different classes (see my comment above) so this answer is based on a false assumption.
    – pleft
    Nov 29 '18 at 14:46








1




1




quittancesService.parseQuittance and paymentToChargeService.saveAndFlush apparently they are in different service classes so the @Transactional annotation should work.
– pleft
Nov 23 '18 at 14:43




quittancesService.parseQuittance and paymentToChargeService.saveAndFlush apparently they are in different service classes so the @Transactional annotation should work.
– pleft
Nov 23 '18 at 14:43












The OP has not posted any class structure. I think downvotes are unwarranted, as this behaviour can be a "gotcha", and given the lack of information, could be the answer.
– AlexB
Nov 29 '18 at 14:39






The OP has not posted any class structure. I think downvotes are unwarranted, as this behaviour can be a "gotcha", and given the lack of information, could be the answer.
– AlexB
Nov 29 '18 at 14:39














The downvote is not mine. Although not very clear, the methods in question belong to different classes (see my comment above) so this answer is based on a false assumption.
– pleft
Nov 29 '18 at 14:46




The downvote is not mine. Although not very clear, the methods in question belong to different classes (see my comment above) so this answer is based on a false assumption.
– pleft
Nov 29 '18 at 14:46


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53447687%2ftransactional-propagation-requires-new-not-work%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks

Calculate evaluation metrics using cross_val_predict sklearn

Insert data from modal to MySQL (multiple modal on website)