1 Reply Latest reply on Jun 15, 2007 9:12 PM by icordoba

    Which approach to fully access EJB3 Entities from within JSP

    icordoba

      Hi there,
      after reading lots of posts trying to find a solution to access EJB3 Entity beans from JSTL I haven't been able to get a valid approach.
      I can't use Lazy loading as that would make my JSP need a scriptlet to make a UserTransaction surround all data access.
      When using Eager loading, I have to make all data be returned as Set's, and not Lists or Collections (solutions for this involve Hibernate specific annotations, outside EJB 3 standard; I want to stick to EJB3 I've also found very "ugly" using @IndexColumn or @ColumnId Hibernate annotations).
      As I just said, and because I am using Struts, the only solution I've found is attaching EJBs in the request/session with there relations as Set types. This works but I have a big small problem. I can't access data using Expression Language. For example, I am getting a:
      Unable to find a value for "0" in object of class "org.hibernate.collection.PersistentSet" using operator "[]"
      When trying to do:
      ${newsArticle.textBlocks[0]}

      Can anybody thing of an approach to be able to access EJBs in JSP pages without any limitations, conforming to EJB3 standard and without using scriptlets in my page? (Of course working with JBoss).

      I can't believe that such a simple goal is not actually possible with JBoss (and maybe other AS's) implementation of EJB3.

      Thanks for any help,
      Ignacio

        • 1. Re: Which approach to fully access EJB3 Entities from within
          icordoba

          Just one comment. The only solution I've found is adding @transient properties to the EJBs with the following structure:

          @Transient
           public List<CMTextblock> getTextblocksList()
           {
           ArrayList<CMTextblock> list = new ArrayList<CMTextblock>();
           list.addAll(getTextblocks());
           return list;
           }
          


          This way I can get multiple Eager getters for onetomany relations, but makes JSTL writer need to think if he must use, in this case, ${article.textblocks} or ${article.textblocksList} depending on if he'll use EL or just regular JSTL iteration (c:forEach, ...)