SSH做添加的过程中出现了异常javax.servlet.ServletException: not-null property references a nu
错误信息如下:
严重: Servlet.service() for servlet action threw exception
javax.servlet.ServletException: not-null property references a null or transient value: com.jyx.pojo.Merchant.codeTableByGroupP; nested exception is org.hibernate.PropertyValueException: not-null property references a null or transient value: com.jyx.pojo.Merchant.codeTableByGroupP
at org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:286)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:78)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:77)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.opensymphony.module.sitemesh.filter.PageFilter.parsePage(PageFilter.java:118)
at com.opensymphony.module.sitemesh.filter.PageFilter.doFilter(PageFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:619)
Merchant类如下:
public class Merchant implements java.io.Serializable {
private String merchantId;
private CodeTable codeTableByGroupP;
private CodeTable codeTableByCodeC;
private MerchantMain merchantMain;
private CodeTable codeTableByGroupC;
private String merchantName;
private String logoPath;
private String address;
private String discription;
private String phone;
private Integer consumption;
private Integer sale;
private String saleExplain;
private Date saleStartDate;
private Date saleEndDate;
private String characteristic;
private String busRoutes;
public Merchant() {
}
public Merchant(CodeTable codeTableByGroupP, CodeTable codeTableByCodeC,
MerchantMain merchantMain, CodeTable codeTableByGroupC) {
this.codeTableByGroupP = codeTableByGroupP;
this.codeTableByCodeC = codeTableByCodeC;
this.merchantMain = merchantMain;
this.codeTableByGroupC = codeTableByGroupC;
}
public Merchant(CodeTable codeTableByGroupP, CodeTable codeTableByCodeC,
MerchantMain merchantMain, CodeTable codeTableByGroupC,
String merchantName, String logoPath, String address,
String discription, String phone, Integer consumption,
Integer sale, String saleExplain, Date saleStartDate,
Date saleEndDate, String characteristic, String busRoutes) {
this.codeTableByGroupP = codeTableByGroupP;
this.codeTableByCodeC = codeTableByCodeC;
this.merchantMain = merchantMain;
this.codeTableByGroupC = codeTableByGroupC;
this.merchantName = merchantName;
this.logoPath = logoPath;
this.address = address;
this.discription = discription;
this.phone = phone;
this.consumption = consumption;
this.sale = sale;
this.saleExplain = saleExplain;
this.saleStartDate = saleStartDate;
this.saleEndDate = saleEndDate;
this.characteristic = characteristic;
this.busRoutes = busRoutes;
}
public String getMerchantId() {
return this.merchantId;
}
public void setMerchantId(String merchantId) {
this.merchantId = merchantId;
}
public CodeTable getCodeTableByGroupP() {
return this.codeTableByGroupP;
}
public void setCodeTableByGroupP(CodeTable codeTableByGroupP) {
this.codeTableByGroupP = codeTableByGroupP;
}
public CodeTable getCodeTableByCodeC() {
return this.codeTableByCodeC;
}
public void setCodeTableByCodeC(CodeTable codeTableByCodeC) {
this.codeTableByCodeC = codeTableByCodeC;
}
public MerchantMain getMerchantMain() {
return this.merchantMain;
}
public void setMerchantMain(MerchantMain merchantMain) {
this.merchantMain = merchantMain;
}
public CodeTable getCodeTableByGroupC() {
return this.codeTableByGroupC;
}
public void setCodeTableByGroupC(CodeTable codeTableByGroupC) {
this.codeTableByGroupC = codeTableByGroupC;
}
public String getMerchantName() {
return this.merchantName;
}
public void setMerchantName(String merchantName) {
this.merchantName = merchantName;
}
public String getLogoPath() {
return this.logoPath;
}
public void setLogoPath(String logoPath) {
this.logoPath = logoPath;
}
}
CodeTable类如下:
public class CodeTable implements java.io.Serializable {
private String codeId;
private String codeC;
private String codeV;
private String parentCodeC;
private Set merchantsForCodeC = new HashSet(0);
private Set merchantsForGroupC = new HashSet(0);
private Set merchantsForGroupP = new HashSet(0);
public CodeTable() {
}
public CodeTable(String codeC, String codeV, String parentCodeC) {
this.codeC = codeC;
this.codeV = codeV;
this.parentCodeC = parentCodeC;
}
public CodeTable(String codeC, String codeV, String parentCodeC,
Set merchantsForCodeC, Set merchantsForGroupC,
Set merchantsForGroupP) {
this.codeC = codeC;
this.codeV = codeV;
this.parentCodeC = parentCodeC;
this.merchantsForCodeC = merchantsForCodeC;
this.merchantsForGroupC = merchantsForGroupC;
this.merchantsForGroupP = merchantsForGroupP;
}
public String getCodeId() {
return this.codeId;
}
public void setCodeId(String codeId) {
this.codeId = codeId;
}
public String getCodeC() {
return this.codeC;
}
public void setCodeC(String codeC) {
this.codeC = codeC;
}
public String getCodeV() {
return this.codeV;
}
public void setCodeV(String codeV) {
this.codeV = codeV;
}
public String getParentCodeC() {
return this.parentCodeC;
}
public void setParentCodeC(String parentCodeC) {
this.parentCodeC = parentCodeC;
}
public Set getMerchantsForCodeC() {
return this.merchantsForCodeC;
}
public void setMerchantsForCodeC(Set merchantsForCodeC) {
this.merchantsForCodeC = merchantsForCodeC;
}
public Set getMerchantsForGroupC() {
return this.merchantsForGroupC;
}
public void setMerchantsForGroupC(Set merchantsForGroupC) {
this.merchantsForGroupC = merchantsForGroupC;
}
public Set getMerchantsForGroupP() {
return this.merchantsForGroupP;
}
public void setMerchantsForGroupP(Set merchantsForGroupP) {
this.merchantsForGroupP = merchantsForGroupP;
}
}
action代码如下:
public ActionForward addMerchantInfo(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response){
MerchantInfoForm merchantInfoForm = (MerchantInfoForm) form;
String path = "myj";
IMerchantInfoService iMerchantInfoService = erchantInfoService)getBean("merchantInfoService");
Merchant merchant = new Merchant();
CodeTable codeTable = new CodeTable();
MerchantMain merchantMain = new MerchantMain();
merchant.setMerchantId(merchantInfoForm.getMid());
merchant.setMerchantName(merchantInfoForm.getMerchant_name());
merchant.setLogoPath(merchantInfoForm.getLogo_path());
codeTable.setCodeC("2");
codeTable.setCodeV("3");
codeTable.setParentCodeC("1");
merchantMain.setMid(1);
merchant.setMerchantMain(merchantMain);
merchant.setCodeTableByCodeC(codeTable);
merchant.setCodeTableByCodeC(codeTable);
merchant.setCodeTableByCodeC(codeTable);
merchant.setMerchantId("11");
merchant.setAddress(merchantInfoForm.getAddress());
merchant.setDiscription(merchantInfoForm.getDiscription());
merchant.setPhone(merchantInfoForm.getPhone());
merchant.setSale(Integer.parseInt(merchantInfoForm.getSale()));
merchant.setConsumption(1);
merchant.setSaleExplain(merchantInfoForm.getSale_explain());
merchant.setSaleStartDate(merchantInfoForm.getSale_startDate());
merchant.setSaleEndDate(merchantInfoForm.getSale_endDate());
merchant.setCharacteristic(merchantInfoForm.getCharacteristic());
merchant.setLogoPath(filepath+"/"+formFile.getFileName());
merchant.setBusRoutes(merchantInfoForm.getBus_routes());
iMerchantInfoService.addMerchant(merchant);
由于发帖字数有限,所以将merchant类部分gei、set方法删了,实际类中merchant的所有属性都有相应的get、set方法。
System.out.println("merchant group P = " + merchant.getCodeTableByGroupP());
System.out.println("merchant group c = " + merchant.getCodeTableByGroupC());
System.out.println("merchant code c = " + merchant.getCodeTableByCodeC());
打印信息如下:
merchant group P = null
merchant group c = null
merchant code c = com.jyx.pojo.CodeTable@114c37d
[解决办法]
lz用的hibernate配置文件有个实体关系映射配置 叫xxx.hbm.xml里的属性配了not-null="true" 但是实际给程序里的值是null值; 你看看吧。
