0 Replies Latest reply on Mar 9, 2007 4:38 PM by J.R. Ector

    persist passing null object

    J.R. Ector Newbie

      I'm getting the following error when using the CRUD EntityHome object:

      15:34:34,569 WARN [JDBCExceptionReporter] SQL Error: 1400, SQLState: 23000
      15:34:34,569 ERROR [JDBCExceptionReporter] ORA-01400: cannot insert NULL into ("CPPMS"."CPPMS_USER"."NAME")
      
      15:34:34,569 WARN [JDBCExceptionReporter] SQL Error: 1400, SQLState: 23000
      15:34:34,569 ERROR [JDBCExceptionReporter] ORA-01400: cannot insert NULL into ("CPPMS"."CPPMS_USER"."NAME")
      
      15:34:34,569 ERROR [AbstractFlushingEventListener] Could not synchronize database state with session
      org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
       at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:71)
       at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
       at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:249)
       at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:235)
       at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:139)
       at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:29
      8)
       at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
       at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
       at org.hibernate.ejb.AbstractEntityManagerImpl.flush(AbstractEntityManagerImpl.java:296)
       at org.jboss.seam.persistence.EntityManagerProxy.flush(EntityManagerProxy.java:81)
       at org.jboss.seam.framework.EntityHome.persist(EntityHome.java:49)
       at gov.dot.marad.persistence.ejb.model.CppmsUserHome.persist(CppmsUserHome.java:104)
       at gov.dot.marad.persistence.ejb.model.CppmsUserHome$$FastClassByCGLIB$$be17843c.invoke(<generated>)


      Here's the bean:

      package gov.dot.marad.persistence.ejb.model;
      
      // Generated Mar 2, 2007 10:00:38 AM by Hibernate Tools 3.2.0.b9
      
      import java.util.HashSet;
      import java.util.Set;
      
      import javax.persistence.CascadeType;
      import javax.persistence.Column;
      import javax.persistence.Entity;
      import javax.persistence.FetchType;
      import javax.persistence.GeneratedValue;
      import javax.persistence.GenerationType;
      import javax.persistence.Id;
      import javax.persistence.ManyToMany;
      import javax.persistence.OneToMany;
      import javax.persistence.SequenceGenerator;
      import javax.persistence.Table;
      
      import org.hibernate.validator.Length;
      import org.hibernate.validator.NotNull;
      import org.jboss.seam.ScopeType;
      import org.jboss.seam.annotations.Name;
      import org.jboss.seam.annotations.Scope;
      
      /**
       * CppmsUser generated by hbm2java
       */
      @SuppressWarnings("serial")
      @Entity
      @Name("cppmsUser")
      @Scope(ScopeType.SESSION)
      @Table(name = "CPPMS_USER")
      public class CppmsUser implements java.io.Serializable
      {
      
       private int userId;
      
       private String name;
      
       private String emailAddress;
      
       private String userName;
      
       private String password;
      
       private Set<TitleXiTaskReminder> titleXiTaskReminders = new HashSet<TitleXiTaskReminder>(
       0);
      
       private Set<Report> reports = new HashSet<Report>(0);
      
       private Set<TitleXiTask> titleXiTasksForCreatorId = new HashSet<TitleXiTask>(
       0);
      
       private Set<Profile> profiles = new HashSet<Profile>(0);
      
       private Set<TitleXiTask> titleXiTasksForUserId = new HashSet<TitleXiTask>(0);
      
       private Set<UserProgRoleRef> userProgRoleRefs = new HashSet<UserProgRoleRef>(
       0);
      
       private Set<CommunicationLog> communicationLogs = new HashSet<CommunicationLog>(
       0);
      
       public CppmsUser()
       {
       }
      
       public CppmsUser(int userId)
       {
       this.userId = userId;
       }
      
       public CppmsUser(int userId, String name, String emailAddress,
       String userName, String password,
       Set<TitleXiTaskReminder> titleXiTaskReminders, Set<Report> reports,
       Set<TitleXiTask> titleXiTasksForCreatorId, Set<Profile> profiles,
       Set<TitleXiTask> titleXiTasksForUserId,
       Set<UserProgRoleRef> userProgRoleRefs,
       Set<CommunicationLog> communicationLogs)
       {
       this.userId = userId;
       this.name = name;
       this.emailAddress = emailAddress;
       this.userName = userName;
       this.password = password;
       this.titleXiTaskReminders = titleXiTaskReminders;
       this.reports = reports;
       this.titleXiTasksForCreatorId = titleXiTasksForCreatorId;
       this.profiles = profiles;
       this.titleXiTasksForUserId = titleXiTasksForUserId;
       this.userProgRoleRefs = userProgRoleRefs;
       this.communicationLogs = communicationLogs;
       }
      
       @Id
       @SequenceGenerator(name = "USER_SEQ", sequenceName = "CPPMS_USER_SEQUENCE")
       @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "USER_SEQ")
       @Column(name = "USER_ID", unique = true, nullable = false, precision = 22, scale = 0)
       @NotNull
       public int getUserId()
       {
       return this.userId;
       }
      
       public void setUserId(int userId)
       {
       this.userId = userId;
       }
      
       @Column(name = "NAME", length = 50)
       @Length(max = 50)
       public String getName()
       {
       return this.name;
       }
      
       public void setName(String name)
       {
       this.name = name;
       }
      
       @Column(name = "EMAIL_ADDRESS", length = 60)
       @Length(max = 60)
       public String getEmailAddress()
       {
       return this.emailAddress;
       }
      
       public void setEmailAddress(String emailAddress)
       {
       this.emailAddress = emailAddress;
       }
      
       @Column(name = "USER_NAME", length = 40)
       @Length(max = 40)
       public String getUserName()
       {
       return this.userName;
       }
      
       public void setUserName(String userName)
       {
       this.userName = userName;
       }
      
       @Column(name = "PASSWORD", length = 20)
       @Length(max = 20)
       public String getPassword()
       {
       return this.password;
       }
      
       public void setPassword(String password)
       {
       this.password = password;
       }
      
       @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "cppmsUser")
       public Set<TitleXiTaskReminder> getTitleXiTaskReminders()
       {
       return this.titleXiTaskReminders;
       }
      
       public void setTitleXiTaskReminders(
       Set<TitleXiTaskReminder> titleXiTaskReminders)
       {
       this.titleXiTaskReminders = titleXiTaskReminders;
       }
      
       @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "cppmsUser")
       public Set<Report> getReports()
       {
       return this.reports;
       }
      
       public void setReports(Set<Report> reports)
       {
       this.reports = reports;
       }
      
       @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "cppmsUserByCreatorId")
       public Set<TitleXiTask> getTitleXiTasksForCreatorId()
       {
       return this.titleXiTasksForCreatorId;
       }
      
       public void setTitleXiTasksForCreatorId(
       Set<TitleXiTask> titleXiTasksForCreatorId)
       {
       this.titleXiTasksForCreatorId = titleXiTasksForCreatorId;
       }
      
       @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
       public Set<Profile> getProfiles()
       {
       return this.profiles;
       }
      
       public void setProfiles(Set<Profile> profiles)
       {
       this.profiles = profiles;
       }
      
       @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "cppmsUserByUserId")
       public Set<TitleXiTask> getTitleXiTasksForUserId()
       {
       return this.titleXiTasksForUserId;
       }
      
       public void setTitleXiTasksForUserId(Set<TitleXiTask> titleXiTasksForUserId)
       {
       this.titleXiTasksForUserId = titleXiTasksForUserId;
       }
      
       @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "cppmsUser")
       public Set<UserProgRoleRef> getUserProgRoleRefs()
       {
       return this.userProgRoleRefs;
       }
      
       public void setUserProgRoleRefs(Set<UserProgRoleRef> userProgRoleRefs)
       {
       this.userProgRoleRefs = userProgRoleRefs;
       }
      
       @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "cppmsUser")
       public Set<CommunicationLog> getCommunicationLogs()
       {
       return this.communicationLogs;
       }
      
       public void setCommunicationLogs(Set<CommunicationLog> communicationLogs)
       {
       this.communicationLogs = communicationLogs;
       }
      
      
      }
      


      The home:
      package gov.dot.marad.persistence.ejb.model;
      
      import java.util.ArrayList;
      import java.util.List;
      
      import javax.persistence.EntityManager;
      
      import org.jboss.seam.annotations.Factory;
      import org.jboss.seam.annotations.In;
      import org.jboss.seam.annotations.Name;
      import org.jboss.seam.framework.EntityHome;
      
      @SuppressWarnings("serial")
      @Name("cppmsUserHome")
      public class CppmsUserHome extends EntityHome<CppmsUser>
      {
      
       @In(create = true)
       EntityManager em;
      
       public EntityManager getEntityManager()
       {
       return em;
       }
      
       @Factory("cppmsUser")
       public CppmsUser initCppmsUser()
       {
       return getInstance();
       }
      
       public void setCppmsUserUserId(Integer id)
       {
       setId(id);
       }
      
       public Integer getCppmsUserUserId()
       {
       return (Integer) getId();
       }
      
       @Override
       protected CppmsUser createInstance()
       {
       CppmsUser cppmsUser = new CppmsUser();
       return cppmsUser;
       }
      
       public void wire()
       {
       }
      
       public boolean isWired()
       {
       return true;
       }
      
       public CppmsUser getDefinedInstance()
       {
       return isIdDefined() ? getInstance() : null;
       }
      
       public List<TitleXiTaskReminder> getTitleXiTaskReminders()
       {
       return getInstance() == null ? null
       : new ArrayList<TitleXiTaskReminder>(getInstance()
       .getTitleXiTaskReminders());
       }
      
       public List<Report> getReports()
       {
       return getInstance() == null ? null : new ArrayList<Report>(
       getInstance().getReports());
       }
      
       public List<TitleXiTask> getTitleXiTasksForCreatorId()
       {
       return getInstance() == null ? null : new ArrayList<TitleXiTask>(
       getInstance().getTitleXiTasksForCreatorId());
       }
      
       public List<TitleXiTask> getTitleXiTasksForUserId()
       {
       return getInstance() == null ? null : new ArrayList<TitleXiTask>(
       getInstance().getTitleXiTasksForUserId());
       }
      
       public List<UserProgRoleRef> getUserProgRoleRefs()
       {
       return getInstance() == null ? null : new ArrayList<UserProgRoleRef>(
       getInstance().getUserProgRoleRefs());
       }
      
       public List<CommunicationLog> getCommunicationLogs()
       {
       return getInstance() == null ? null : new ArrayList<CommunicationLog>(
       getInstance().getCommunicationLogs());
       }
      
      }
      



      The page:

      <f:view xmlns:h="http://java.sun.com/jsf/html"
       xmlns:f="http://java.sun.com/jsf/core"
       xmlns:ice="http://www.icesoft.com/icefaces/component">
      
       <ice:outputDeclaration doctypeRoot="HTML"
       doctypePublic="-//W3C//DTD HTML 4.01 Transitional//EN"
       doctypeSystem="http://www.w3.org/TR/html4/loose.dtd" />
      
       <html>
       <head>
      
       <title>CPPMS</title>
       <link href="./xmlhttp/css/xp/xp.css" rel="stylesheet" type="text/css" />
       </head>
       <body>
       <h2>Create User</h2>
       <ice:form>
       <f:loadBundle basename="gov.dot.marad.web.MessageBundle" var="bundle" />
       <ice:outputLabel for="name">
       <ice:outputText value="#{bundle.name_label}">
       </ice:outputText>
       </ice:outputLabel>
       <ice:inputText id="name" value="#{cppmsUser.name}" />
       <br />
       <ice:outputLabel for="emailAddress">
       <ice:outputText value="#{bundle.user_email_label}">
       </ice:outputText>
       </ice:outputLabel>
       <ice:inputText id="emailAddress" value="#{cppmsUser.emailAddress}" />
       <br />
       <ice:outputLabel for="userName">
       <ice:outputText value="#{bundle.user_name_label}">
       </ice:outputText>
       </ice:outputLabel>
       <ice:inputText id="userName" value="#{cppmsUser.userName}" />
       <br />
      
       <ice:outputLabel for="password">
       <ice:outputText value="#{bundle.user_password_label}"></ice:outputText>
       </ice:outputLabel>
       <ice:inputSecret id="password" redisplay="false"
       value="#{cppmsUser.password}"></ice:inputSecret>
       <br />
       <ice:messages showDetail="true" />
       <ice:commandButton action="#{cppmsUserHome.persist}"
       value="Create User"></ice:commandButton>
       </ice:form>
       </body>
       </html>
      </f:view>
      


      Is it necessary to supply all of parameters in the constructor?
      Is this caused by the use of a sequence generator?

      Thanks,

      JR