7 Replies Latest reply on Feb 11, 2006 12:03 AM by Peter Voringer

    Application Design with EJB3.0

    Peter Voringer Newbie

      Hi out there,

      i´m currently working on a new portal system with ejb3.0 for persistence and logic implementation.

      Writing and designing some "prototypes" i may realised some structural weakness of the EJB3.0 Spec, partly discussed (also in this forum):

      The "lazy loading".

      The problems:

      Defining relations as EAGER is in most cases very inefficient, for example if the entity is very complex with lot of relations, so in default case nearly all relations would be marked as LAZY. But this makes navigation through the database (entity bean relations) mostly impossible.

      Marking Relations as EAGER is a "nice to have feature" but not really helpfull, if i (want to) write very generic interfaces in the session facade or having more compley entities with lots of relations.
      Also if writing for each Business Case some additional methods with extra "value-model" classes (lot of more work) i don't want EAGER. In this case i would create a Query with "(left) join fetch entity.relation" which is more efficient.
      So the logic consequence would be to tell each sessionbean method what it should load. In forum 2 options were mentioned:
      LoadLevels with
      1) enum Class for each Entity with an element for each relation (very dynamic and scallable) or
      2) a single int which value represents a set of relations to load (not so dynamic)
      In both cases i have to create the query dynamically, so it is not possible
      to create generic classes (for example like EJB3DAOGeneric in Caveaemptor). The altenative to write entity.relation.size() is terrible and very unpretty in my eyes.

      Strongly bounded with this problem is the transaction management.
      If you think of a standard (but nohow complex) web application it has to fetch entites from database for the menutree, elements to show or the application needs (groups, permissions, ...) for processing the request. Furthermore some requests cause the logic to do changes to the database.
      If one of this processes fails i want to tell the user of my webapp. If all is in one transaction which lifecycle is managed in for example a HttpFilter i get the exceptions in my filter and cannot make any notfies to the user.
      If i make transaction-per-facade-method i have the problem i cannot lazy fetch entities. This is a big problem if someone uses something like Struts with MVC 2+1 (Actions create context/content for jsp/template which only renders given content), to keep away too much logic from jsps.

      It is nice to have all this tutorials, but most of them are very basic and do not satisfy requirements for productive use of ejb3.0. So is there any fully implemented application (no tutorials, test, howtos, .. )
      which is productive in use or some "extended" tutorials?


      Perhaps i am completly wrong, but what i conceived until now doesn't satisfy or makes me happy. So perhaps someone has a position/statement to all this?

      Regards

      Peter