-
Notifications
You must be signed in to change notification settings - Fork 31
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
Comments
@antoinesd, interested in your opinion as well :) |
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. Ideally, we would have this as separate module, but you will need to somehow access the If you can cobble together a PR, we can go from there. |
Yes, that was my very thinking, too. By adding this module, a user would get support for JPA/JTA.
That'd be fantastic! |
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. |
to be honest, I am wondering why weld just doesn't provide an supposedly optional feature to have a default TransactionServices implementation that looks up transaction related objects via jndi, for example. There are transaction managers that are used in java se apps, and none of them including narayana has provided it's own implementation of this. That would leave only entity manager factory and such like to be done. |
Were any further actions done here? I'm heavily struggeling with the transaction context, while trying to adopt @gunnarmorling example to my test project (here executing a very simple CDI Test which looks exactly like in @gunnarmorling project but in my it fails )
I found #80 that this error comes from a older If you want to have a look at my testing project it would be the |
Oh thanks. Sorry if I pollute this thread. In my demo project I'll have JavaEE 7 (so CDI 1.2) application as I'm trying to set up this testing environment for our work situation (yeah Java EE 7 ...). Will try to go back to an older version of |
No problem. |
[...a few years later] Hi everyone! 👋 ...I came across this thread while trying to integrate a declarative transactional approach in a simple application that uses I wanted to ask if there has been any consideration for introducing support for this in the testing library 🤔 |
Hello there has been no work done in this regard and this issue has mostly been buried and forgotten I am afraid :) |
I'm on the other side of the fence for this one because I wouldn't know where to start 😅 I'll leave this one up for a more qualified soul. Thanks foe the update! 🙌 |
In one of the earlier comments there is a link to a sample code that has some of the internals we'd use. Then there's a question of how to include this. If it should be:
I'd say it's better to keep it optional but OFC we could start by adding it directly and then taking a look at how much luggage does that amount to. |
Thinking about it some more, we might be able to re-use (or repurpose) |
I tried playing with this a little but my knowledge in the JPA area is pretty much nonexistent so that's making it hard to know what kind of wiring do we need/want. It also does bring in a lot of dependencies - hibernate core parts for JPA bits and Narayana core for JTA. @x80486 do you have a sample (or more) of tests that you would expect to work? |
Thank you for looking into this 🥇 I'll create a small repository so you can test this — give me a couple of hours to put everything together. It will be everything working in |
Thank you. |
This is the repository: jakarta-persistence-weld-testing.zip On $ git status
On branch main
Your branch is up to date with 'origin/main'.
nothing to commit, working tree clean
$ ./gradlew clean check
To honour the JVM settings for this build a single-use Daemon process will be forked. For more on this, please refer to https://docs.gradle.org/8.10.2/userguide/gradle_daemon.html#sec:disabling_the_daemon in the Gradle documentation.
Daemon will be stopped at the end of the build
> Task :clean
> Task :processResources
> Task :processTestResources
> Task :generateEffectiveLombokConfig
> Task :compileJava
> Task :classes
> Task :generateTestEffectiveLombokConfig
> Task :compileTestJava
> Task :testClasses
> Task :test
> Task :check
BUILD SUCCESSFUL in 7s
8 actionable tasks: 8 executed If you change to the branch $ git checkout weld-jta-test
Switched to branch 'weld-jta-test'
Your branch is up to date with 'origin/weld-jta-test'.
$ ./gradlew clean check
To honour the JVM settings for this build a single-use Daemon process will be forked. For more on this, please refer to https://docs.gradle.org/8.10.2/userguide/gradle_daemon.html#sec:disabling_the_daemon in the Gradle documentation.
Daemon will be stopped at the end of the build
> Task :clean
> Task :processResources
> Task :processTestResources
> Task :generateEffectiveLombokConfig
> Task :compileJava
> Task :classes
> Task :generateTestEffectiveLombokConfig
> Task :compileTestJava
> Task :testClasses
> Task :test FAILED
MyEntityRepositoryTest > saveFindAndUpdate() FAILED
java.lang.AssertionError at MyEntityRepositoryTest.java:72
MyEntityRepositoryTest > save() FAILED
java.lang.AssertionError at MyEntityRepositoryTest.java:42
6 tests completed, 2 failed
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':test'.
> There were failing tests. See the report at: file:///.../jakarta-persistence-weld-testing/build/reports/tests/test/index.html
* Try:
> Run with --scan to get full insights.
BUILD FAILED in 6s
8 actionable tasks: 8 executed @gunnarmorling could validate this example as well. |
I see, thanks @x80486 I can see you are handling JPA and actually only need JTA bits.
For which you need a dependency on narayana, so in gradle speech that should be something like But that seems to leave two tests failing and in both cases it seems that saved entity then cannot be found. |
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:
@Transactional
TransactionServices
so that Weld can make use of JTA and support transactional observers and injection of theUserTransaction
WDYT?
The text was updated successfully, but these errors were encountered: