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

Provide support for declarative TX and transactional observers #65

Open
gunnarmorling opened this Issue Jan 14, 2019 · 4 comments

Comments

Projects
None yet
2 participants
@gunnarmorling
Copy link

gunnarmorling commented Jan 14, 2019

Hey, first of all, thanks a lot for this project, it's very helpful!

One thing I was missing is support for declarative TX control (via @Transactional) and transactional observers. This needs JTA to be hooked up.

I figured out the steps needed and added an example to our demos repo in Hibernate: hibernate/hibernate-demos#39

Also planning to write a blog post about this, but actually it'd be great if this was working out-of-the-box in Weld JUnit. I.e. there could be a new module, "persistence" or so, which does all the things I had to do manually:

  • Provide producers for EM and EMF
  • Inject the BM into Hibernate so that DI works in JPA entity listeners
  • Set up JTA via Narayana, bringing support for @Transactional
  • Hooking up TransactionServices so that Weld can make use of JTA and support transactional observers and injection of the UserTransaction

WDYT?

@gunnarmorling

This comment has been minimized.

Copy link
Author

gunnarmorling commented Jan 14, 2019

@antoinesd, interested in your opinion as well :)

@manovotn

This comment has been minimized.

Copy link
Collaborator

manovotn commented Jan 14, 2019

I think this would be an interesting yet very specific addition and that it should be an independent feature that you can but don't need to run in your tests.
This gets somewhat trickier in combination with the fact that we need a solution for junit4 and junit5 both of which operate differently.

Ideally, we would have this as separate module, but you will need to somehow access the Weld object we create so that you can register you beans (producers) and transactional service with it (some static method allowing that perhaps?).

If you can cobble together a PR, we can go from there.

@gunnarmorling

This comment has been minimized.

Copy link
Author

gunnarmorling commented Jan 14, 2019

Ideally, we would have this as separate module

Yes, that was my very thinking, too. By adding this module, a user would get support for JPA/JTA.

If you can cobble together a PR, we can go from there.

That'd be fantastic!

@gunnarmorling

This comment has been minimized.

Copy link
Author

gunnarmorling commented Jan 24, 2019

Here's my blog post on the topic which also contains an example implementation:

http://in.relation.to/2019/01/23/testing-cdi-beans-and-persistence-layer-under-java-se/

The code is in the hibernate-demos repo and I've rewritten it slightly now, so everything is easily usable via a JUnit rule. I think you could essentially pull over this rule into a new weld-junit-persistence module and this would already be of great help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment