Announcement Announcement Module
Collapse
No announcement yet.
Calling Hibernate.initialize() using AOP Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Calling Hibernate.initialize() using AOP

    In my service layer components, I'm wanting to ensure that any domain object(s) I return, have lazy associations initialized properly - I'm not using OSIV in the web tier and my service layer runs remotely from the web tier.

    I believe a call to
    Code:
    Hibernate.initialize()
    is the way to perform initialization. However, I don't want to call this directly from the service layer because it rather exposes Hibernate as the DAO implementation technology.

    Instead, what I've done is to create an annotation
    Code:
    @InitializeResult
    that I can annotate a method with where I want the return value for that method to be initialized. I've created an aspect for invoking
    Code:
    Hibernate.initialize()
    and associated it with the new annotation. I've defined an
    Code:
    @AfterReturning
    advice that invokes the initialization code on the returned object.

    I'm not getting the lazy initialization exceptions in the web tier like I was before.

    My question is - does this approach seem dodgy? Am I missing something that will break this approach?

    I'd be grateful for any advice that anyone can pass on to me regarding this.

    Thanks,

    Andrew
Working...
X