Я новичок в спящем режиме и пытаюсь создать файл спящего режима для этой таблицы:
brand_id | brand_name | status
int,PK,AI varchar(100) | bool
Мой файл гибернации:
<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>
при установке свойства not-null для brandName в true, я получал исключение после исключения:
org.hibernate.PropertyValueException: not-null property references a null or transient value: com.bla.pojos.Brand.status
at org.hibernate.engine.Nullability.checkNullability(Nullability.java:72)
at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:290)
at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:181)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:107)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:187)
at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:33)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:172)
at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:27)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:535)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:523)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:519)
Когда я устанавливаю значение false или ничего не записываю, я сохраняю свои данные с нулевым значением. Что я делаю не так?
EDIT:
Фасоль:
@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();
}
XHTML:
<p:inputText size="30" maxlength="50" required="true" requiredMessage="#{lang.brand_req_txt}" value="#{BrandSettingsBean.selectedBrand.brandName}"/>