4 Replies Latest reply on Jul 12, 2010 8:59 PM by Allan De Leon

    Exception @In attribute requires non-null

    Allan De Leon Newbie
      Can't figure out what's going on... been pounding on the following issue for the last day and a half. I've done a seam project before and have never ran into this issue. But now, the following which seems so basic will not work...

      I have the following sample entity:

      @Entity
      @Name("sampleentity")
      @Table(name = "sampleentity")
      public class SampleEntity {

              private static final long serialVersionUID = 1L;
             
              private Long id;

              private String name;

              @Id
              @GeneratedValue(strategy = GenerationType.AUTO)
              public Long getId() {
                      return id;
              }

              public void setId(Long id) {
                      this.id = id;
              }

              public String getName() {
                      return name;
              }

              public void setName(String name) {
                      this.name = name;
              }

      }



      All I'm trying to do is inject the above 'sampleentity' component into a session bean:

      @Stateful
      @Scope(CONVERSATION)
      @Name(AccountServiceLocal.NAME)
      public class AccountServiceBean implements AccountServiceLocal {

      ...
              @In(create = true)
              private SampleEntity sampleentity;
      ...

      }


      Now, @In(create = true) is supposed to create a new instance of 'sampleentity' if there isn't already an instance of it. But all I get is:

      javax.faces.FacesException: ${accountService.someMethod}: javax.ejb.EJBTransactionRolledbackException: @In attribute requires non-null value: accountService.sampleentity
              at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:118)
              at javax.faces.component.UICommand.broadcast(UICommand.java:387)
              at org.ajax4jsf.component.AjaxActionComponent.broadcast(AjaxActionComponent.java:55)
              at org.ajax4jsf.component.AjaxViewRoot.processEvents(AjaxViewRoot.java:321)
              at org.ajax4jsf.component.AjaxViewRoot.broadcastEvents(AjaxViewRoot.java:296)
              at org.ajax4jsf.component.AjaxViewRoot.processPhase(AjaxViewRoot.java:253)
              at org.ajax4jsf.component.AjaxViewRoot.processApplication(AjaxViewRoot.java:466)
              at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:82)


      Adding @AutoCreate to the entity doesn't work either.

      The big difference with this project is that I used maven to setup the project using the seam maven archetype from http://seam-archetype.sourceforge.net/jbosscc-seam-archetype/1.2/project-info.html.   In my previous project, I used seam-gen to setup the project.

      Anyone run into this issue before? Any advice would be much appreciated.

        • 1. Re: Exception @In attribute requires non-null
          bb bb Master
          Try to use @In(required=false) and initialize the entity if the value of the entity is null.
          • 2. Re: Exception @In attribute requires non-null
            Allan De Leon Newbie
            Thanks for replying... unfortunately, your suggestion wasn't what I was hoping for. @In(create = true) is supposed to create a new instance of the injected component if one doesn't already exist, but it just doesn't. @AutoCreate also doesn't seem to be auto-creating instances of components... The problem seems to be caused by the seam maven archetype I used to setup the project. I tested the same components using a seam-gen configured project and they work just fine.

            thanks
            • 3. Re: Exception @In attribute requires non-null
              Kevin Sapper Newbie

              Hi Allen,


              @In(create=true) attempts to initialize the annotated object if missing or null. In your case seam cannot initialize a new instance, because it doesn't know how. Probably it's because you don't got a default constructor but that's just a guess. What will solve your problem is a @Factory method which initializes your object or the factory method returns a SampleEntity and got the name sampleEntity. Then seam would outject the SampleEntity with the context name sampleEntity into the context and your AccountServiceBean could inject the initialized instance as a result.


              regards kevin

              • 4. Re: Exception @In attribute requires non-null
                Allan De Leon Newbie
                Thanks, Kevin. I've actually tested my code using a project that was generated using seam-gen and @In(create=true) works fine in that environment. So, it looks like the problem is caused by the seam maven archetype I used to setup my initial project.

                Here's more info on the maven setup if you haven't seen it:
                http://seam-archetype.sourceforge.net/jbosscc-seam-archetype/1.2/quickstart.html