2 Replies Latest reply on Sep 17, 2007 9:24 PM by Terry

    EntityHome.persist() return NullPointerException

    Terry Apprentice

      When trying to persist record to database using EntityHome object from within Java code (not jsf), following error is thrown.

      Caused by: java.lang.NullPointerException
      at org.jboss.seam.framework.Home.createdMessage(Home.java:52)
      at org.jboss.seam.framework.EntityHome.persist(EntityHome.java:51)
      at au.edu.tisc.session.ActivityLogger.log(ActivityLogger.java:60)
      at au.edu.tisc.session.Authenticator.authenticate(Authenticator.java:68)


      Home.java:52 line is:
      debug("created entity #0 #1", entityClass.getName(), id);

      I believe error is due to 'id' being null, as debug from my code below show.

      My Code:

      public void log(OrgUser orgUser, String action, String actionDesc) {

      OrgUserActivityLogHome orgUserActivityLogHome = new OrgUserActivityLogHome();

      orgUserActivityLogHome.getInstance().setId("000001");
      orgUserActivityLogHome.getInstance().setAction(action);
      orgUserActivityLogHome.getInstance().setDescription(actionDesc);
      orgUserActivityLogHome.getInstance().setOrgUser(orgUser);
      orgUserActivityLogHome.getInstance().setLastUpateDate((new CurrentDatetime()).getCurrentDatetime());

      System.out.println("orgUserActivityLogHome.getId(): " + (orgUserActivityLogHome.getId()==null ? "null" : (String) orgUserActivityLogHome.getId()));

      orgUserActivityLogHome.persist();
      }

      System.out.println ==> message: orgUserActivityLogHome.getId(): null

      I am not sure why Id is being null, since I am setting it in my code????

      I am new to Seam. Please feel free to make other suggestions.

      Thanks