2 Replies Latest reply on Oct 29, 2010 5:39 AM by Leo van den berg

    Trying to use EntityHome

    Ira Klein Newbie
      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)