Results 1 to 2 of 2

Thread: Hibernate Lazy Loading Problem

  1. #1
    Join Date
    Nov 2005
    Posts
    1

    Default Hibernate Lazy Loading Problem

    Perhaps I'm being stupid here, but I've read the docs and I can't see a way to achieve what I need. I have a hibernate application (not web app), which has been written using "traditional" hibernate - ie concrete classes, rather than interfaces. As an example, say we have a Customer who has a number of Order objects. I want to be able to intercept Customer.getOrders() to open/close a session/transaction. Having to write a load of *Manager or *DAO classes seems a little bit clumbsy, when I already have perfectly clean, simple concrete classes. The whole point of hibernate is to be (relatively) transparent.

    IIUC, the Customer and Order object will NOT be beans, and I can't see a way to proxy these objects. How to I intercept the call to Customer.getOrders() and of course get*** methods on the returned Order objects too?

    The documentation only refers to proxying manager objects, not the entities themselves.

    Am I missing something?

  2. #2
    Join Date
    Jan 2005
    Location
    Bucharest, Romania
    Posts
    5,403

    Default

    The documentation only refers to proxying manager objects, not the entities themselves.
    What documentations are you talking about - HB or Spring?
    HB itself does some proxy as you already know to make lazy-loading happen. Opening a session for every call to get will be overkill - it's best to open a session and do as much work in it as possible (openSessionInView pattern).
    To intercept getXXX methods you can use an AOP interceptor to take care of it. Moreover, HB 3.x (at least) supports working with proxies not just concrete objects.
    Costin Leau
    SpringSource - http://www.SpringSource.com- Spring Training, Consulting, and Support - "From the Source"
    http://twitter.com/costinl
    Please use [ c o d e ] [ / c o d e ] tags

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •