2 Replies Latest reply on Oct 29, 2010 5:39 AM by lvdberg

    Trying to use EntityHome

    iklein99
      I'm trying to do a very simple "hello world" where I'm using an extended version EntityHome (which is created by the Eclipse plugin.

      I have an EJB that instantiates this extended Entity, gets the instance, sets a field, and calls persist().  The result is that the entity is persisted, but it also crashes with a Null Pointer along the way.

      Here is the extended EntityHome:


      @Entity
      @Name("person")
      public class Person implements Serializable
      {
          /**
               *
               */
              private static final long serialVersionUID = 1L;
              // seam-gen attributes (you should probably edit these)
          private Long id;
          private String name;

          // add additional entity attributes

          // seam-gen attribute getters/setters with annotations (you probably should edit)

          @Id @GeneratedValue
          public Long getId() {
              return id;
          }

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

          @Length(max = 20)
          public String getName() {
              return name;
          }

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

      }


      Here is the bean that uses it...


           public void sayHello(String name)
          {
               PersonHome personHome = new PersonHome();
              
              
              // implement your business logic here
              log.info("Hello.sayHello() action called with: #{person.name}");
              statusMessages.add("sayHello #{person.name}");
             
               Person p = (Person) personHome.getInstance();
               p.setName(name);
               personHome.persist();
               ...

      Here is the stack trace...

      Caused by: java.lang.NullPointerException
              at org.jboss.seam.framework.Controller.debug(Controller.java:197)
              at org.jboss.seam.framework.Home.updatedMessage(Home.java:54)
              at org.jboss.seam.framework.EntityHome.update(EntityHome.java:65)
              at org.domain.helloworld2.session.HelloBean.sayHello(HelloBean.java:47)
              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
              at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

        • 1. Re: Trying to use EntityHome
          vata2999

          as i know while you're using @Name annotation in your entity class you don't need to use EntityHome if you want to use entityHome put @Name annotation in your EntityHome
          in addition to get component instance use this



          Person p = (Person) Component.getInstance("person");



          • 2. Re: Trying to use EntityHome
            lvdberg

            Hi,


            This happens because you're not using the bean correctly (because you're constructing it yourself). When you try to print (log.info) it will find a not-injected log-instance, which results in your NPE.


            Leo