Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PanacheRepository injected methods cannot be made transactional #7188

Closed
zeljkot opened this issue Feb 13, 2020 · 12 comments · Fixed by #9472
Closed

PanacheRepository injected methods cannot be made transactional #7188

zeljkot opened this issue Feb 13, 2020 · 12 comments · Fixed by #9472
Labels
area/panache kind/bug Something isn't working
Milestone

Comments

@zeljkot
Copy link

zeljkot commented Feb 13, 2020

Describe the bug
If a class implementing the PanacheRepository is marked as @Transactional, methods injected by Quarkus are not transactional.

Expected behavior
All public methods should be transactional. When calling e.g. persist, a transaction should be created and operation should succeed.

Actual behavior
App throws javax.persistence.TransactionRequiredException: Transaction is not active, consider adding @Transactional to your method to automatically activate one.

To Reproduce
Steps to reproduce the behavior:

  1. Create a class implementing PanacheRepository and mark it as @Transactional
  2. Create test class, with non-transactional test method and injected repository
  3. Call persist from a non-transactional method.

Configuration

# Add your application.properties here, if applicable.

Screenshots
(If applicable, add screenshots to help explain your problem.)

Environment (please complete the following information):

  • Output of uname -a or ver: Windows 10
  • Output of java -version: 1.8
  • GraalVM version (if different from Java):
  • Quarkus version or git rev: 1.3.0.Alpha1

Additional context
(Add any other context about the problem here.)

@zeljkot zeljkot added the kind/bug Something isn't working label Feb 13, 2020
@gsmet
Copy link
Member

gsmet commented Feb 17, 2020

Yeah, I think it's probably the same issue of the methods being injected too late and not being taken into account by the interception layer.

/cc @mkouba

@agoncal
Copy link
Contributor

agoncal commented Apr 5, 2020

Any update on this one ? I'm using 1.3.1.Final and I have the same issue (impossible to persist an entity with the repository because of transaction not being activated)

@mkouba
Copy link
Contributor

mkouba commented Apr 6, 2020

@gsmet Yes, as described here the repository class is transformed and the methods are generated and so the CDI container does not see the methods at all.

@agoncal
Copy link
Contributor

agoncal commented May 19, 2020

(cc @FroMage that's the issue I was mentioning during the podcast)

@FroMage
Copy link
Member

FroMage commented May 19, 2020

@mkouba so, why do we run ArC before the Panache enhancers? How does ArC load the bytecode to see which methods need interceptors? ClassLoader, Jandex, or using an ASM transformer?

@mkouba
Copy link
Contributor

mkouba commented May 19, 2020

so, why do we run ArC before the Panache enhancers?

@FroMage I have no idea when Panache enhancers are executed. By "run" you mean the analysis of the bean classes?

How does ArC load the bytecode to see which methods need interceptors?

We only consider methods from the Jandex.

@FroMage
Copy link
Member

FroMage commented May 19, 2020

We only consider methods from the Jandex.

OK, so even if we ran ArC after we're done transforming, it would not see the new methods unless we reindexed them.

Is that the best thing to do, do you think @stuartwdouglas ?

stuartwdouglas added a commit to stuartwdouglas/quarkus that referenced this issue May 20, 2020
@stuartwdouglas
Copy link
Member

Isn't the underlying issue here just that ArC is not intercepting default methods? #9472

@mkouba
Copy link
Contributor

mkouba commented May 20, 2020

@stuartwdouglas Nope, it's not about the default methods but about "synthetic" methods added during transformation... or at least that was my assumption ;-).

@FroMage
Copy link
Member

FroMage commented May 20, 2020

OK, that's a very good point, because in this case all methods are defined on the superinterface. We're not introducing new methods, we're just overriding them.

But perhaps what @mkouba is saying is that even if the class itself is marked as @Transactional it does not apply to interface methods it inherits IFF the user hasn't overriden them? The fact that we override them later via a transformer makes it too late for ArC to consider them overridden.

@mkouba
Copy link
Contributor

mkouba commented May 20, 2020

We're not introducing new methods, we're just overriding them.

Aha, that's a completely different situation then. I'm sorry for confusion. In that case, Stuart's PR should work fine.

@FroMage
Copy link
Member

FroMage commented May 20, 2020

OK great. Note that I've filed #9487 for interception of static methods.

stuartwdouglas added a commit to stuartwdouglas/quarkus that referenced this issue May 21, 2020
stuartwdouglas added a commit to stuartwdouglas/quarkus that referenced this issue May 21, 2020
@FroMage FroMage added this to the 1.6.0 milestone May 25, 2020
@gsmet gsmet modified the milestones: 1.6.0 - master, 1.5.0.Final May 26, 2020
gsmet pushed a commit to gsmet/quarkus that referenced this issue May 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/panache kind/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants