0 Replies Latest reply: Mar 18, 2012 7:02 AM by matiger RSS

    Entity-Bean in a Entity-Bean is not working

    matiger Newbie



      I just started developing with JBoss AS 7 and EJB and I wasn't sure if I should put this question in the beginners corner. If that would be better, maybe somebody can move it there.


      I created an Entity-Bean 'Auction' which contains some String-fields and two fields that contain entities too.


      public class Auction {
          private Long id;
          private User creator;
          private Town town;
          private String mandatory;
          private String optional;

      // getters and setters...


      Now I want to create a new Auction-Bean and persist it, but I always get a NullPointerException.


      Here the Frontendcode:


           <h:selectOneListbox id="name" value="#{newAuction.creator.id}" size="1">
                <f:selectItems var="item" itemLabel="#{item.name}" itemValue="#{item.id}" value="#{userManager.users}" />
           <h:selectOneListbox id="town" value="#{newAuction.town.id}" size="1">
                <f:selectItems var="item" itemLabel="#{item.name}" itemValue="#{item.id}" value="#{townManager.towns}" />
                value="#{newAuction.mandatory}" />
                value="#{newAuction.optional}" />
                value="Register" />     


      But now I get an Exception like this:


      value="#{newAuction.creator.id}": Target Unreachable, 'creator' returned null


      I do understand that the field 'creator' is not initialized when I try to set the id, but how do I do it then? I just want to put the Bean that's already initialised (for showing the combo-box) in there.


      It's kinda hard to google this stuff, I tried


      any help is really appreciated.


      Thanks, Mati