Why @Transactional is not prolonged to repository method? The Next CEO of Stack OverflowWhat is reflection and why is it useful?What is a serialVersionUID and why should I use it?What's the difference between @Component, @Repository & @Service annotations in Spring?Why is subtracting these two times (in 1927) giving a strange result?Why don't Java's +=, -=, *=, /= compound assignment operators require casting?Why is char[] preferred over String for passwords?Why is it faster to process a sorted array than an unsorted array?Why is printing “B” dramatically slower than printing “#”?@Transactional take old values on not committed transactionChanging values with query Spring Data methods

How easy is it to start Magic from scratch?

Is a stroke of luck acceptable after a series of unfavorable events?

What does this shorthand mean?

How to get regions to plot as graphics

Should I tutor a student who I know has cheated on their homework?

Anatomically Correct Mesopelagic Aves

Is HostGator storing my password in plaintext?

WOW air has ceased operation, can I get my tickets refunded?

India just shot down a satellite from the ground. At what altitude range is the resulting debris field?

Where to find order of arguments for default functions

When airplanes disconnect from a tanker during air to air refueling, why do they bank so sharply to the right?

What is the purpose of the Evocation wizard's Potent Cantrip feature?

How to use tikz in fbox?

Does it take more energy to get to Venus or to Mars?

Horror movie/show or scene where a horse creature opens its mouth really wide and devours a man in a stables

% symbol leads to superlong (forever?) compilations

Implement the Thanos sorting algorithm

Opposite of a diet

If the heap is initialized for security, then why is the stack uninitialized?

Is it safe to use c_str() on a temporary string?

Why didn't Khan get resurrected in the Genesis Explosion?

Can a caster that cast Polymorph on themselves stop concentrating at any point even if their Int is low?

How to write the block matrix in LaTex?

Why were Madagascar and New Zealand discovered so late?



Why @Transactional is not prolonged to repository method?



The Next CEO of Stack OverflowWhat is reflection and why is it useful?What is a serialVersionUID and why should I use it?What's the difference between @Component, @Repository & @Service annotations in Spring?Why is subtracting these two times (in 1927) giving a strange result?Why don't Java's +=, -=, *=, /= compound assignment operators require casting?Why is char[] preferred over String for passwords?Why is it faster to process a sorted array than an unsorted array?Why is printing “B” dramatically slower than printing “#”?@Transactional take old values on not committed transactionChanging values with query Spring Data methods










0















I need to perform several operations in one transaction.



I use org.springframework.transaction.annotation.Transactional



One service (with @Transactional) calls another (without @Transactional) and this service calls repository



I have next service



 @Transactional
public void performBatchOperations( List<String> ids)
service1.doAction(ids);
service2.doAction(ids);



service2



@Component
public class Service2 {
@Autowired
private Repo repo;

public void doAction(List<String> ids)
repo.delete(ids);



Repository



@Component
public class Repo extends
JpaRepository<Entity, Long>, JpaSpecificationExecutor<Entity>


@Modifying
@Query("DELETE FROM Entity a WHERE a.jobId IN :ids")
void deleteByJobIdIn(@Param("ids") List<String> ids);



I got next error



Caused by: javax.persistence.TransactionRequiredException: Executing an update/delete query
liberty-debug | at org.hibernate.ejb.AbstractQueryImpl.executeUpdate(AbstractQueryImpl.java:99)


But i have @Transactional on my service method. Why it wasn't prolonged to Repository?



Is there way to use @Modifying as part of complex transaction?










share|improve this question
























  • Is the rest of spring properly set up?

    – XtremeBaumer
    Mar 7 at 14:29











  • which transactional are you using? (what are you importing)?

    – Andronicus
    Mar 7 at 14:29











  • Check that you're always using @org.springframework.transaction.annotation.Transactional and not mixing it with @javax.transaction.Transactional

    – noiaverbale
    Mar 7 at 14:44











  • This may not be documented clearly, but it is expected that @Modifying methods are also annotated with @Transactional. Doing so will propagate the running transaction to the repository method, as expected. In fact, the official documentation recommends annotating all repository interfaces as @Transactional(readOnly = true). The exception is seen because the proxy generated by Spring Data has no way of knowing if a repository method will always be invoked within a transaction, since the method can as well be called from a non-transactional context (after all, it is a public method).

    – manish
    Mar 8 at 5:13












  • Can I use @Modifying as part of complex transaction?

    – Artyom Karnov
    Mar 8 at 11:00















0















I need to perform several operations in one transaction.



I use org.springframework.transaction.annotation.Transactional



One service (with @Transactional) calls another (without @Transactional) and this service calls repository



I have next service



 @Transactional
public void performBatchOperations( List<String> ids)
service1.doAction(ids);
service2.doAction(ids);



service2



@Component
public class Service2 {
@Autowired
private Repo repo;

public void doAction(List<String> ids)
repo.delete(ids);



Repository



@Component
public class Repo extends
JpaRepository<Entity, Long>, JpaSpecificationExecutor<Entity>


@Modifying
@Query("DELETE FROM Entity a WHERE a.jobId IN :ids")
void deleteByJobIdIn(@Param("ids") List<String> ids);



I got next error



Caused by: javax.persistence.TransactionRequiredException: Executing an update/delete query
liberty-debug | at org.hibernate.ejb.AbstractQueryImpl.executeUpdate(AbstractQueryImpl.java:99)


But i have @Transactional on my service method. Why it wasn't prolonged to Repository?



Is there way to use @Modifying as part of complex transaction?










share|improve this question
























  • Is the rest of spring properly set up?

    – XtremeBaumer
    Mar 7 at 14:29











  • which transactional are you using? (what are you importing)?

    – Andronicus
    Mar 7 at 14:29











  • Check that you're always using @org.springframework.transaction.annotation.Transactional and not mixing it with @javax.transaction.Transactional

    – noiaverbale
    Mar 7 at 14:44











  • This may not be documented clearly, but it is expected that @Modifying methods are also annotated with @Transactional. Doing so will propagate the running transaction to the repository method, as expected. In fact, the official documentation recommends annotating all repository interfaces as @Transactional(readOnly = true). The exception is seen because the proxy generated by Spring Data has no way of knowing if a repository method will always be invoked within a transaction, since the method can as well be called from a non-transactional context (after all, it is a public method).

    – manish
    Mar 8 at 5:13












  • Can I use @Modifying as part of complex transaction?

    – Artyom Karnov
    Mar 8 at 11:00













0












0








0








I need to perform several operations in one transaction.



I use org.springframework.transaction.annotation.Transactional



One service (with @Transactional) calls another (without @Transactional) and this service calls repository



I have next service



 @Transactional
public void performBatchOperations( List<String> ids)
service1.doAction(ids);
service2.doAction(ids);



service2



@Component
public class Service2 {
@Autowired
private Repo repo;

public void doAction(List<String> ids)
repo.delete(ids);



Repository



@Component
public class Repo extends
JpaRepository<Entity, Long>, JpaSpecificationExecutor<Entity>


@Modifying
@Query("DELETE FROM Entity a WHERE a.jobId IN :ids")
void deleteByJobIdIn(@Param("ids") List<String> ids);



I got next error



Caused by: javax.persistence.TransactionRequiredException: Executing an update/delete query
liberty-debug | at org.hibernate.ejb.AbstractQueryImpl.executeUpdate(AbstractQueryImpl.java:99)


But i have @Transactional on my service method. Why it wasn't prolonged to Repository?



Is there way to use @Modifying as part of complex transaction?










share|improve this question
















I need to perform several operations in one transaction.



I use org.springframework.transaction.annotation.Transactional



One service (with @Transactional) calls another (without @Transactional) and this service calls repository



I have next service



 @Transactional
public void performBatchOperations( List<String> ids)
service1.doAction(ids);
service2.doAction(ids);



service2



@Component
public class Service2 {
@Autowired
private Repo repo;

public void doAction(List<String> ids)
repo.delete(ids);



Repository



@Component
public class Repo extends
JpaRepository<Entity, Long>, JpaSpecificationExecutor<Entity>


@Modifying
@Query("DELETE FROM Entity a WHERE a.jobId IN :ids")
void deleteByJobIdIn(@Param("ids") List<String> ids);



I got next error



Caused by: javax.persistence.TransactionRequiredException: Executing an update/delete query
liberty-debug | at org.hibernate.ejb.AbstractQueryImpl.executeUpdate(AbstractQueryImpl.java:99)


But i have @Transactional on my service method. Why it wasn't prolonged to Repository?



Is there way to use @Modifying as part of complex transaction?







java spring hibernate spring-data-jpa spring-data






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 8 at 11:01







Artyom Karnov

















asked Mar 7 at 14:25









Artyom KarnovArtyom Karnov

10011




10011












  • Is the rest of spring properly set up?

    – XtremeBaumer
    Mar 7 at 14:29











  • which transactional are you using? (what are you importing)?

    – Andronicus
    Mar 7 at 14:29











  • Check that you're always using @org.springframework.transaction.annotation.Transactional and not mixing it with @javax.transaction.Transactional

    – noiaverbale
    Mar 7 at 14:44











  • This may not be documented clearly, but it is expected that @Modifying methods are also annotated with @Transactional. Doing so will propagate the running transaction to the repository method, as expected. In fact, the official documentation recommends annotating all repository interfaces as @Transactional(readOnly = true). The exception is seen because the proxy generated by Spring Data has no way of knowing if a repository method will always be invoked within a transaction, since the method can as well be called from a non-transactional context (after all, it is a public method).

    – manish
    Mar 8 at 5:13












  • Can I use @Modifying as part of complex transaction?

    – Artyom Karnov
    Mar 8 at 11:00

















  • Is the rest of spring properly set up?

    – XtremeBaumer
    Mar 7 at 14:29











  • which transactional are you using? (what are you importing)?

    – Andronicus
    Mar 7 at 14:29











  • Check that you're always using @org.springframework.transaction.annotation.Transactional and not mixing it with @javax.transaction.Transactional

    – noiaverbale
    Mar 7 at 14:44











  • This may not be documented clearly, but it is expected that @Modifying methods are also annotated with @Transactional. Doing so will propagate the running transaction to the repository method, as expected. In fact, the official documentation recommends annotating all repository interfaces as @Transactional(readOnly = true). The exception is seen because the proxy generated by Spring Data has no way of knowing if a repository method will always be invoked within a transaction, since the method can as well be called from a non-transactional context (after all, it is a public method).

    – manish
    Mar 8 at 5:13












  • Can I use @Modifying as part of complex transaction?

    – Artyom Karnov
    Mar 8 at 11:00
















Is the rest of spring properly set up?

– XtremeBaumer
Mar 7 at 14:29





Is the rest of spring properly set up?

– XtremeBaumer
Mar 7 at 14:29













which transactional are you using? (what are you importing)?

– Andronicus
Mar 7 at 14:29





which transactional are you using? (what are you importing)?

– Andronicus
Mar 7 at 14:29













Check that you're always using @org.springframework.transaction.annotation.Transactional and not mixing it with @javax.transaction.Transactional

– noiaverbale
Mar 7 at 14:44





Check that you're always using @org.springframework.transaction.annotation.Transactional and not mixing it with @javax.transaction.Transactional

– noiaverbale
Mar 7 at 14:44













This may not be documented clearly, but it is expected that @Modifying methods are also annotated with @Transactional. Doing so will propagate the running transaction to the repository method, as expected. In fact, the official documentation recommends annotating all repository interfaces as @Transactional(readOnly = true). The exception is seen because the proxy generated by Spring Data has no way of knowing if a repository method will always be invoked within a transaction, since the method can as well be called from a non-transactional context (after all, it is a public method).

– manish
Mar 8 at 5:13






This may not be documented clearly, but it is expected that @Modifying methods are also annotated with @Transactional. Doing so will propagate the running transaction to the repository method, as expected. In fact, the official documentation recommends annotating all repository interfaces as @Transactional(readOnly = true). The exception is seen because the proxy generated by Spring Data has no way of knowing if a repository method will always be invoked within a transaction, since the method can as well be called from a non-transactional context (after all, it is a public method).

– manish
Mar 8 at 5:13














Can I use @Modifying as part of complex transaction?

– Artyom Karnov
Mar 8 at 11:00





Can I use @Modifying as part of complex transaction?

– Artyom Karnov
Mar 8 at 11:00












0






active

oldest

votes












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%2f55046130%2fwhy-transactional-is-not-prolonged-to-repository-method%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















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.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55046130%2fwhy-transactional-is-not-prolonged-to-repository-method%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

1928 у кіно

Захаров Федір Захарович

Ель Греко