Giter VIP home page Giter VIP logo

Comments (5)

jdubois avatar jdubois commented on May 12, 2024

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.

jdubois avatar jdubois commented on May 12, 2024

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.

jmiddleton avatar jmiddleton commented on May 12, 2024

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.

jdubois avatar jdubois commented on May 12, 2024

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.

phstudy avatar phstudy commented on May 12, 2024

In fact, this is a pitfall with Hibernate, not JPA.

from generator-jhipster.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.