4 Replies Latest reply: Apr 5, 2013 2:20 AM by gimbal2 RSS

    lazy loading in a ejb, jpa

    REDO LOG
      Hi all,
      I am about developing an JEE web application and I needed to implement what is do called lazy loading or pagination, I did some search and I found that JPA contains annotation to mark the fields of an entity as Lazy in fetchType and in the ejb you have to load entity object by page. I couldn't understand clearly and get confused when I have to pass the page size I want to load to the ejb session from my managed bean and also, with mocks in the project and interfaces to implements, it is really a jungle I got really CONFUSED and miss understanding of the hole thing.

      Please if anybody has a tutorial, a book, a web page that gives anything about my subject, I will be so thankful.


      thanks for any help,

      Rashid, best Regards
        • 1. Re: lazy loading in a ejb, jpa
          Kayaman
          REDO LOG wrote:
          I am about developing an JEE web application and I needed to implement what is do called lazy loading or pagination
          Those are two different things.
          The first one means that a part of an object graph won't be loaded unless it's needed (avoiding loading data that won't be used), the second means that only parts of a resultset are loaded.
          I did some search and I found that JPA contains annotation to mark the fields of an entity as Lazy in fetchType
          That's lazy loading of entities.
          Please if anybody has a tutorial, a book, a web page that gives anything about my subject, I will be so thankful.
          Well, I have a web page for you: http://google.com
          • 2. Re: lazy loading in a ejb, jpa
            gimbal2
            'Pro JPA 2.0' - buy it, love it. Additionally you may want to get the book 'Enterprise Javabeans 3.1' (O'Reilly) which is the best book I have read on EJB tech and may help to understand how JPA fits into the EJB landscape exactly.

            Note that lazy loading and pagination have absolutely -nothing- to do with each other.
            it is really a jungle I got really CONFUSED and miss understanding of the hole thing
            That is because it is difficult material and not for the novice. It took me two years of hard daily practice before I was confident enough to state "I understand JEE"; and I already had a good 6 years of Java/web programming experience at that point.
            • 3. Re: lazy loading in a ejb, jpa
              REDO LOG
              thanks I have solver the problem, I had to initialize the list in a PostConstruct annotated method instead of the getter
              • 4. Re: lazy loading in a ejb, jpa
                gimbal2
                REDO LOG wrote:
                thanks I have solver the problem, I had to initialize the list in a PostConstruct annotated method instead of the getter
                Both techniques work actually (as long as you really make it a lazy initialization, which is something different than lazy loading), I just find PostConstruct a littler cleaner.