0 Replies Latest reply on Sep 10, 2005 6:20 AM by Jordi Cabré Roca

    insert null into non-nullable column

    Jordi Cabré Roca Newbie

      Jboss dumps this message-->

      java.sql.SQLException: Try to insert null into a non-nullable column: column: RO
      LEID table: ROLE in statement [INSERT INTO ROLE (roleID, descripcio) VALUES (?,
      ?)]


      Mmm, I have an UserBean, an UserInfoBean, a RoleBean and a GroupBean EntityBeans. Moreover I've implemented a SessionBean.

      Mmm, SessionBean has AddRole method:

      /**
       * Business method
       * @ejb.interface-method view-type = "both"
       */
       public boolean AddRole(ejb.EntityInterfaces.RoleValue value) {
       // TODO Auto-generated method stub
       try {
       this.mRole.create(value);
       } catch (Exception e) {
       e.printStackTrace();
       return false;
       }
       return true;
       }


      My RoleBean is:

      package ejb.EntityBeans;
      
      import java.rmi.RemoteException;
      
      import javax.ejb.EJBException;
      import javax.ejb.EntityBean;
      import javax.ejb.EntityContext;
      import javax.ejb.RemoveException;
      
      import ejb.EntityInterfaces.RoleValue;
      
      /**
       * @ejb.bean name="Role"
       * display-name="Name for Role"
       * description="Description for Role"
       * jndi-name="ejb/Role"
       * type="CMP"
       * cmp-version="2.x"
       * view-type="local"
       *
       * @ejb.value-object match="*" name="Role"
       * @ejb.util generate="physical"
       * @ejb.persistence table-name="role"
       * @jboss.persistence create-table="true" remove_table="true"
       * @ejb.finder signature="java.util.Collection findAll()" result-type-mapping="Local"
       */
      public abstract class RoleBean implements EntityBean {
      
       public RoleBean() {
       super();
       // TODO Auto-generated constructor stub
       }
      
       public void ejbActivate() throws EJBException, RemoteException {
       // TODO Auto-generated method stub
      
       }
      
       public void ejbLoad() throws EJBException, RemoteException {
       // TODO Auto-generated method stub
      
       }
      
       public void ejbPassivate() throws EJBException, RemoteException {
       // TODO Auto-generated method stub
      
       }
      
       public void ejbRemove()
       throws RemoveException,
       EJBException,
       RemoteException {
       // TODO Auto-generated method stub
      
       }
      
       public void ejbStore() throws EJBException, RemoteException {
       // TODO Auto-generated method stub
      
       }
      
       public void setEntityContext(EntityContext ctx)
       throws EJBException,
       RemoteException {
       // TODO Auto-generated method stub
      
       }
      
       public void unsetEntityContext() throws EJBException, RemoteException {
       // TODO Auto-generated method stub
      
       }
      
       /**
       * Getter for CMP Field RoleID
       *
       * @ejb.pk-field
       * @ejb.persistent-field
       * @ejb.interface-method view-type="local"
       */
       public abstract java.lang.Integer getRoleID();
      
       /**
       * Setter for CMP Field RoleID
       *
       * @ejb.interface-method view-type="local"
       */
       public abstract void setRoleID(java.lang.Integer value);
      
       /**
       * Getter for CMP Field Descripcio
       *
       *
       * @ejb.persistent-field
       * @ejb.interface-method view-type="local"
       */
       public abstract java.lang.String getDescripcio();
      
       /**
       * Setter for CMP Field Descripcio
       *
       * @ejb.interface-method view-type="local"
       */
       public abstract void setDescripcio(java.lang.String value);
      
       /**
       * Create method
       * @ejb.create-method view-type = "local"
       */
       public ejb.EntityInterfaces.RolePK ejbCreate(
       ejb.EntityInterfaces.RoleValue value) throws javax.ejb.CreateException {
       this.setRoleID(value.getRoleID());
       this.setDescripcio(value.getDescripcio());
       // TODO Auto-generated method stub
       return null;
       }
       /**
       * Post Create method
       */
       public void ejbPostCreate(ejb.EntityInterfaces.RoleValue value)
       throws javax.ejb.CreateException {
       // TODO Auto-generated method stub
       }
       /**
       * Getter for CMR Relationship
       *
       * @ejb.interface-method view-type="local"
       * @ejb.relation name = "RolesUsers"
       * role-name = "RoleHasUsersRoleName"
       * target-multiple = "yes"
       * @jboss.relation-mapping
       * style="relation-table"
       *
       * @jboss.relation-table
       * table-name="RolesUsers"
       * create-table="true"
       * remove-table="false"
       *
       * @jboss.relation
       * related-pk-field="login"
       * fk-column="login_fk"
       * fk-constraint="true"
       */
       public abstract java.util.Collection getUsers();
      
       /**
       * Setter for CMR Relationship
       *
       * @ejb.interface-method view-type="local"
       */
       public abstract void setUsers(java.util.Collection value);
      
       /**
       * Business method
       * @ejb.interface-method view-type = "local"
       */
       public ejb.EntityInterfaces.RoleValue getValue() {
       // TODO Auto-generated method stub
       RoleValue value = new RoleValue();
       value.setRoleID(this.getRoleID());
       value.setDescripcio(this.getDescripcio());
       return value;
       }
       /**
       * Business method
       * @ejb.interface-method view-type = "local"
       */
       public void setValues(ejb.EntityInterfaces.RoleValue value) {
       // TODO Auto-generated method stub
       this.setRoleID(value.getRoleID());
       this.setDescripcio(value.getDescripcio());
       }
      }


      Mmm, one UserBean can have more RoleBeans, and one RoleBean can have more UserBeans.

      UserBean:

      package ejb.EntityBeans;
      
      import java.rmi.RemoteException;
      
      import javax.ejb.EJBException;
      import javax.ejb.EntityBean;
      import javax.ejb.EntityContext;
      import javax.ejb.RemoveException;
      
      /**
       * @ejb.bean name="User"
       * display-name="Name for User"
       * description="Description for User"
       * jndi-name="ejb/User"
       * type="CMP"
       * cmp-version="2.x"
       * view-type="local"
       *
       * @ejb.value-object match="*" name="User"
       * @ejb.util generate="physical"
       * @ejb.persistence table-name="user"
       * @jboss.persistence create-table="true" remove_table="true"
       * @ejb.finder signature="java.util.Collection findAll()" result-type-mapping="Local"
       */
      
      public abstract class UserBean implements EntityBean {
      
       public UserBean() {
       super();
       // TODO Auto-generated constructor stub
       }
      
       public void ejbActivate() throws EJBException, RemoteException {
       // TODO Auto-generated method stub
      
       }
      
       public void ejbLoad() throws EJBException, RemoteException {
       // TODO Auto-generated method stub
      
       }
      
       public void ejbPassivate() throws EJBException, RemoteException {
       // TODO Auto-generated method stub
      
       }
      
       public void ejbRemove()
       throws RemoveException,
       EJBException,
       RemoteException {
       // TODO Auto-generated method stub
      
       }
      
       public void ejbStore() throws EJBException, RemoteException {
       // TODO Auto-generated method stub
      
       }
      
       public void setEntityContext(EntityContext ctx)
       throws EJBException,
       RemoteException {
       // TODO Auto-generated method stub
      
       }
      
       public void unsetEntityContext() throws EJBException, RemoteException {
       // TODO Auto-generated method stub
      
       }
      
       /**
       * Getter for CMP Field Login
       *
       * @ejb.pk-field
       * @ejb.persistent-field
       * @ejb.interface-method view-type="local"
       */
       public abstract java.lang.String getLogin();
      
       /**
       * Setter for CMP Field Login
       *
       * @ejb.interface-method view-type="local"
       */
       public abstract void setLogin(java.lang.String value);
      
       /**
       * Getter for CMP Field Password
       *
       *
       * @ejb.persistent-field
       * @ejb.interface-method view-type="local"
       */
       public abstract java.lang.String getPassword();
      
       /**
       * Setter for CMP Field Password
       *
       * @ejb.interface-method view-type="local"
       */
       public abstract void setPassword(java.lang.String value);
      
       /**
       * Create method
       * @ejb.create-method view-type = "local"
       */
       public ejb.EntityInterfaces.UserPK ejbCreate(
       ejb.EntityInterfaces.UserValue value) throws javax.ejb.CreateException {
       // TODO Auto-generated method stub
       this.setLogin(value.getLogin());
       this.setPassword(value.getPassword());
       return null;
       }
       /**
       * Post Create method
       */
       public void ejbPostCreate(ejb.EntityInterfaces.UserValue value)
       throws javax.ejb.CreateException {
       // TODO Auto-generated method stub
       }
      
       /**
       * Getter for CMR Relationship
       *
       * @ejb.interface-method view-type="local"
       * @ejb.relation name = "UserHasUserInfo"
       * role-name = "UserHasUserInfoRoleName"
       * @jboss.relation related-pk-field="loginID"
       * fk-column="loginID_fk"
       */
       public abstract ejb.EntityInterfaces.UserInfoLocal getUserInfo();
       /**
       * Setter for CMR Relationship
       *
       * @ejb.interface-method view-type="local"
       */
       public abstract void setUserInfo(ejb.EntityInterfaces.UserInfoLocal value);
      
       /**
       * Getter for CMR Relationship
       *
       * @ejb.interface-method view-type="local"
       * @ejb.relation name = "RolesUsers"
       * role-name = "UserHasRolesRoleName"
       * target-multiple = "yes"
       * @jboss.relation-mapping
       * style="relation-table"
       *
       * @jboss.relation-table
       * table-name="RolesUsers"
       * create-table="true"
       * remove-table="false"
       *
       * @jboss.relation
       * related-pk-field="RoleID"
       * fk-column="role_fk"
       * fk-constraint="false"
       */
       public abstract java.util.Collection getRoles();
      
       /**
       * Setter for CMR Relationship
       *
       * @ejb.interface-method view-type="local"
       */
       public abstract void setRoles(java.util.Collection value);
      
       /**
       * Getter for CMR Relationship
       *
       * @ejb.interface-method view-type="local"
       * @ejb.relation name = "GroupUser"
       * role-name = "UserHasGroupRoleName"
       * @jboss.relation related-pk-field="ID"
       * fk-column="groupID_fk"
       */
       public abstract ejb.EntityInterfaces.GroupLocal getGroup();
      
       /**
       * Setter for CMR Relationship
       *
       * @ejb.interface-method view-type="local"
       */
       public abstract void setGroup(ejb.EntityInterfaces.GroupLocal value);
      
       /**
       * Business method
       * @ejb.interface-method view-type = "local"
       */
       public ejb.EntityInterfaces.UserValue getUserValue() {
       // TODO Auto-generated method stub
       ejb.EntityInterfaces.UserValue ret = new ejb.EntityInterfaces.UserValue();
       ret.setLogin(this.getLogin());
       ret.setPassword(this.getPassword());
       return null;
       }
       /**
       * Business method
       * @ejb.interface-method view-type = "local"
       */
       public void setUserValue(ejb.EntityInterfaces.UserValue value) {
       // TODO Auto-generated method stub
       this.setLogin(value.getLogin());
       this.setPassword(value.getPassword());
       }
      }
      


      How you can see, I use XDoclet to generate jboss info.
      When I perform my client application, I perform-->

      session.addRole(roleValue);
      


      Can you say me why shows me it?
      I'm very worried because I must finish it on Monday.

      Thanks beforehand.