Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Hibernate not null属性引用null或瞬态值异常_Hibernate_Hibernate Mapping - Fatal编程技术网

Hibernate not null属性引用null或瞬态值异常

Hibernate not null属性引用null或瞬态值异常,hibernate,hibernate-mapping,Hibernate,Hibernate Mapping,我不熟悉hibernate,正在尝试为此表创建hibernate文件: brand_id | brand_name | status int,PK,AI varchar(100) | bool 我的hibernate文件是: <hibernate-mapping> <class name="Brand" table="brand" catalog="aCatalog"> <id name="brandId" type="java.lang.Integ

我不熟悉hibernate,正在尝试为此表创建hibernate文件:

brand_id | brand_name | status
int,PK,AI  varchar(100) | bool
我的hibernate文件是:

<hibernate-mapping>
  <class name="Brand" table="brand" catalog="aCatalog">
    <id name="brandId" type="java.lang.Integer">
        <column name="brand_id" />
        <generator class="identity" />
    </id>
    <property name="brandName" type="string">
        <column name="brand_name" length="100" not-null="true"/>
    </property>
    <property name="status" type="boolean">
            <column name="status"/>
    </property>
  </class>
</hibernate-mapping>
当我将其设置为false或未在那里写入任何内容时,我将使用null值保存数据。我做错了什么

编辑:

支持Bean:

@ManagedBean(name="brandSettingsBean")
@ViewScoped
public class BrandSettingsBean extends EBSBean implements Serializable {

    BrandSettingsService bsService = new BrandSettingsService();

    private Brand brand=new Brand();
    private String brandName;
    private Brand selectedBrand;
    private List<Brand> BrandList;

    public Brand getSelectedBrand() {
        return selectedBrand;
    }

public void setSelectedBrand(Brand selectedBrand) {
        this.selectedBrand = selectedBrand;
    }
public BrandSettingsBean() throws Exception {

        brandList=bsService.getBrands(null);
    }


 public void brandKaydet() {
        EBSResponse er = kiService.brandKaydet(brand, sessionUser, ipAdresi);

        if (er.getExceptionValue() == null) {
            this.brandList = (List<Brand>)er.getObjectValue();
            FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, localeBean.lang.getString(er.getStringValue()), "");
            FacesContext.getCurrentInstance().addMessage("sysMsg", message);
        } else {
            FacesMessage message = new FacesMessage(EBSUtils.getHataTipi(er.getExceptionValue().getHataTipi()), localeBean.lang.getString(er.getExceptionValue().getHataMesaji()), "");
            FacesContext.getCurrentInstance().addMessage("sysMsg", message);
        }

        brand=new Brand();
    }
@ManagedBean(name=“brandSettingsBean”)
@视域
公共类BrandSettingsBean扩展EBSBean实现可序列化{
BrandSettingsService bsService=新的BrandSettingsService();
自有品牌=新品牌();
私有字符串品牌名称;
自有品牌选择品牌;
私人名单;
公共品牌getSelectedBrand(){
返回所选品牌;
}
公共选择品牌(品牌选择品牌){
this.selectedBrand=selectedBrand;
}
public BrandSettingsBean()引发异常{
brandList=bsService.getBrands(空);
}
公共无效brandKaydet(){
EBSResponse er=kiService.brandKaydet(品牌、会话用户、ipAdresi);
if(er.getExceptionValue()==null){
this.brandList=(List)er.getObjectValue();
FacesMessage=新的FacesMessage(FacesMessage.SEVERITY_信息,localeBean.lang.getString(er.getStringValue()),“”);
FacesContext.getCurrentInstance().addMessage(“sysMsg”,message);
}否则{
FacesMessage message=newFacesMessage(EBSUtils.getHataTipi(er.getExceptionValue().getHataTipi()),localeBean.lang.getString(er.getExceptionValue().getHataMesaji()),“”);
FacesContext.getCurrentInstance().addMessage(“sysMsg”,message);
}
品牌=新品牌();
}
xhtml:

<p:inputText size="30" maxlength="50" required="true" requiredMessage="#{lang.brand_req_txt}" value="#{BrandSettingsBean.selectedBrand.brandName}"/> 


听起来你在告诉Hibernate品牌名称不能为空,然后在保存之前不进行设置。我们可以看看生成附加堆栈跟踪的代码来确认这一点吗?

嗯,我不确定那里发生了什么。Hibernate引用了status字段。你有一个名为status on Brand的属性吗?Alex,谢谢你的回答。我发现我正在把商标名发送给支持bean,而我应该发送brand。
<p:inputText size="30" maxlength="50" required="true" requiredMessage="#{lang.brand_req_txt}" value="#{BrandSettingsBean.selectedBrand.brandName}"/>