Announcement Announcement Module
Collapse
No announcement yet.
Hibernate Lazy Loading Problem Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

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

    Comment

    Working...
    X