Announcement Announcement Module
Collapse
No announcement yet.
A way to handle Hibernate's LazyLoading with remoting Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • #16
    I have also come accross a similar problem. My server has to have a very generic interface, since it has many clients (currently a webapp and a rich client), both of which can be extended by thirdparties through plugins. The requirements for these applications (in terms of the data they need) is not known to me, since it will depend on the client/plugin. So for example exposing a getUser() method that returns the User object and all associated related objects may make sense for the rich-client app but not for the webclient.

    In the end what I decided to do was to expose a QueryManager service, which allowed the client to specifically get just what information it requires. In essense the QueryManager provides a number methods that take in a query and associated parameters and returns a List of the results. The QueryManager is
    a bit smarter than I mention here, for example it can support multiple query
    language flavors (currently HQL and SQL), provides names queries for often
    used queries etc...

    This design also meant I could get rid of all the methods I used to have in
    my other service interfaces that were strictly related to data retrieval,
    cutting down on the code drastically.

    But for this to work you need to design your persistent objects with this in
    mind. No lazy loading, for one. You also need to know who is executing the
    queries if you have priviliged data and then use hibernate's filters to prevent
    un authorised access to data. Since I was already using acegi, this was trivial.

    Not using lazy loading may seem like a big compromise, but I have found it is
    not since clients always load precisely what they need and nothing more.

    Comment


    • #17
      There is something similar on the Hibernate forums: http://hibernate.org/377.html .

      Comment


      • #18
        Originally posted by baptiste
        Hi,

        I work on a 3-tiered app with Java clients and a Spring/Hibernate server acessed over RMI, so your approach is of great interest to me. However, I can't figure it out with so few code. Would you mind giving us a more detailed exemple, with a sample domain object and a bit of client code?

        I'd be grateful for that. Regards,
        Baptiste
        Sure, I have run out of time today, but Iíll post something tomorrow.
        Federico.

        Comment


        • #19
          Some code and example

          Ok, here is the code and a little example.
          Not precisely a polished document , but it should get readable once you format de code. The JDK 1.5 parts should be easy to extract if you canít use them.
          Hope this helps figuring things out, and if it doesnít donít hesitate to ask.

          Regards,
          Federico.

          Comment


          • #20
            Originally posted by fschroder
            Ok, here is the code and a little example.
            Not precisely a polished document , but it should get readable once you format de code. The JDK 1.5 parts should be easy to extract if you canít use them.
            Hope this helps figuring things out, and if it doesnít donít hesitate to ask.

            Regards,
            Federico.
            Thanks a lot. It's getting clearer but I still have difficulty getting the whole picture. I haven't worked with Java 1.5 and these kinds of aspects before, so this explains that.

            Regards,
            Baptiste

            Comment


            • #21
              Hibernate 4.x - @FetchProfile

              Hi, since this thread pops up in various searches, just wanted to note that Hibernate 4 allows to solve this problem using:

              Code:
              @FetchProfile(name = "customer-with-orders", fetchOverrides = {
                 @FetchProfile.FetchOverride(entity = Customer.class, association = "orders", mode = FetchMode.JOIN)
              })
              See http://docs.jboss.org/hibernate/core...ching-profiles

              Comment

              Working...
              X