Comments (5)
This is "normal" with JPA, if you access a lazy relationship outside of a transaction.
Normally, you should use a service layer, with a transaction. For instance, the UserService class is perfect for doing this job.
Now, I understand this is a pitfall with JPA, so we should work on two possible solutions (outside of documenting the issue):
- Using the Open Session In View pattern. This is not my favorite solution, as it is mostly a hack, and it's bad for scalability
- Have a look at the extended persistence context pattern. I'm not sure we can make it work correctly with JHipster, but this would be my favorite solution. See the "PersistentContext.EXTENDED" attribute on the persistence context.
from generator-jhipster.
As I feared we can't use an extended persistence context with our stack.
So the only two options we have left is:
- Using the open session in view pattern. I don't like it, as it hides the problem from the developer: he should use JPA correctly.
- Letting people use JPA correctly: that's why I won't correct this issue. You have many ways to go around this problem, either by using eager relations or by using a transaction and a Spring service. That's how JPA is supposed to be used, and Spring controllers, in my opinion.
from generator-jhipster.
Agree with you, I don't like open session view pattern coz some exceptions (db exceptions) are only detected when the transaction is committed which happens outside of the controller.
What about to provide an option during the generation of the app where the developer can automatically include or not a open session in view filter?
Thanks,
Jorge
from generator-jhipster.
This could be a solution: I don't want to have too many options when generating the app, but some options come and go depending on how we evolve. For me this is not a very high priority option, but I'll see that in a couple of versions (I think we will lose some options soon)
from generator-jhipster.
In fact, this is a pitfall with Hibernate, not JPA.
from generator-jhipster.
Related Issues (20)
- Increase modularization and improve organization by providing nested generators.
- Entity table name generated by jdl conflicts with the generated by the generator.
- @MapstructExpression: Usage of quote char (") in expression not possible HOT 1
- Integration test failing on a newly created project HOT 4
- Angular: Using Entity "Refresh list" button makes pagination links multiply requests HOT 1
- Application bootstrapping issue after upgrading ng-jhipster generated application(with angular) to angular 17 and generator-jhipster HOT 1
- build error: Missing "./dist/types/cli" specifier in "generator-jhipster" package
- German Administration for Metrics wonky due to locale error HOT 6
- German i18n missing translation keys
- Upgrade method is missing parameters HOT 1
- Support for the Multitenancy HOT 9
- API First Development Page Guide makes assumptions to work HOT 10
- Upgrade from 7.9.4 to 8.1.0 fail with Error: Command failed: "Unknown command: "bin" HOT 5
- Change the `upgrade` command to print migrate blueprint instructions HOT 1
- Jhipster 8.1.0 Vue 3 fails with the darkly bootswatch theme
- Misspelling in generated JwtAuthenticationTestUtils.java HOT 2
- Remove the Eclipse and IDEA plugins from the Server Generator
- Allow to define default value in JDL for a field
- Sonar: Unnecessary use of conditional expression for default assignment HOT 4
- How To Enhance JWT Payload Add Some Customer Value In Jwt Token
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from generator-jhipster.