User:

public class User implements Serializable {
/**
* User
* Default Constructor
*/
public User ()
{
logger.debug("User is created");

}

private String username;
private Long centerId;
private Long userId;
private String phone;
private String project;
private boolean userContractor;
private String contractNumber;
private Category logger = Category.getInstance(this.getClass());
private Long contractorId;


public Long getCenterId ()
{
return centerId;
}

public void setCenterId ( Long centerId )
{
this.centerId = centerId;
}

... other getters/setters

}


UserBean: (managed bean)

package gov.nasa.msfc.repository.submittal.view.bean;

import gov.nasa.msfc.repository.submittal.model.businessobject.User;
import gov.nasa.msfc.repository.submittal.model.exception.UserException;
import gov.nasa.msfc.repository.submittal.view.builder.UserBuilder;
import gov.nasa.msfc.repository.submittal.view.util.FacesUtils;

public class UserBean extends BaseBean {

private Long centerId;
private String username;
private Long userId;
private String phone;
private String project;
private boolean userContractor;
private Long contractorId;
private String contractNumber;

/**
* UserBean
*/
public UserBean ()
{
logger.debug("UserBean is created");
}

public Long getCenterId ()
{
return centerId;
}

public void setCenterId ( Long centerId )
{
this.centerId = centerId;
}

... other gettters/setters

/**
* save
*/
public String saveAction ()
{
String result = "fail";
try
{
User user = UserBuilder.createUser ( this );

this.serviceLocator.getUserService ().save ( user );
result = "success";
}
catch ( UserException ex )
{
String msg = "Could not save/udpate user";
FacesUtils.addErrorMessage ( msg + ":Internal Error" );
}
return result;
}

}


I'm setting a bean property with the value from a select one list box like this:

<h:selectOneMenu id="centermenu" value="#{userBean.centerId}">
<f:selectItems value="#{applicationBean.centerSelectItems}"/>
</h:selectOneMenu>

applicationBean.centerSelectItems is an ArrayList of selectItem objects each
containing a name/value pair.

In the mapping file the centerId is set to not-null="true" because a user
should always have a centerId.

User.hbm.xml:

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD
2.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd";>
<hibernate-mapping
package="gov.nasa.msfc.repository.submittal.model.businessobject">
<class name="User" table="SUBMITTAL_USER" >
<cache usage="read-write"/>
<id name="userId" column="USER_ID" unsaved-value="null">
<generator class="sequence">
<param name="sequence">submittal_user_seq</param>
</generator>
</id>
<many-to-one name="centerId" class="Center" column="CENTER_ID"
cascade="none" not-null="true" />
<property name="username" column="USERNAME"/>
<property name="phone" column="PHONE"/>
<property name="project" column="PROJECT"/>
<property name="userContractor" column="IS_CONTRACTOR"/>
<many-to-one name="contractorId" class="Contractor"
column="CONTRACTOR_ID" cascade="none" />
<property name="contractNumber" column="CONTRACT_NUMBER"/>
</class>
</hibernate-mapping>


When the user visits the userdata.jsp page the form gives them the option to
set the centerId using the above selectOneMenu tag. The problem is that
when the saveAction is executed by a user the following message is displayed:
net.sf.hibernate.PropertyValueException: not-null property references a null
or transient value:
gov.nasa.msfc.repository.submittal.model.businessobject.User.centerId

The question is why is User.centerId null? and what can I do to ensure it is
not null?

Thanks,
Mark









Reply via email to