我希望你不要把它标记为重复原因我检查了很多帖子答案而没有解决我的问题..我不能超越我的插入声明,这就像给我一个操作符的空对象,当我在defaut中将我的attributs设置为null,它将其成功插入数据库中的空对象
这是我的实体:
@Entity
@Table(name="operators")
public class Operator {
@Id
@GeneratedValue
private Integer id;
private String opName;
private String opCountry;
private Date opDate;
private Integer opMCC;
private Integer opCC;
private Integer opMNC;
private Integer opNC;
private String opPMN;
private String opDNS;
private String opAPN;
private String opMails;
private String opNums;
private String Comment;
public String getOpName() {
return opName;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public void setOpName(String opName) {
this.opName = opName;
}
public String getOpCountry() {
return opCountry;
}
public void setOpCountry(String opCountry) {
this.opCountry = opCountry;
}
public Date getOpDate() {
return opDate;
}
public void setOpDate(Date opDate) {
this.opDate = opDate;
}
public Integer getOpMCC() {
return opMCC;
}
public void setOpMCC(Integer opMCC) {
this.opMCC = opMCC;
}
public Integer getOpCC() {
return opCC;
}
public void setOpCC(Integer opCC) {
this.opCC = opCC;
}
public Integer getOpMNC() {
return opMNC;
}
public void setOpMNC(Integer opMNC) {
this.opMNC = opMNC;
}
public Integer getOpNC() {
return opNC;
}
public void setOpNC(Integer opNC) {
this.opNC = opNC;
}
public String getOpPMN() {
return opPMN;
}
public void setOpPMN(String opPMN) {
this.opPMN = opPMN;
}
public String getOpDNS() {
return opDNS;
}
public void setOpDNS(String opDNS) {
this.opDNS = opDNS;
}
public String getOpAPN() {
return opAPN;
}
public void setOpAPN(String opAPN) {
this.opAPN = opAPN;
}
public String getOpMails() {
return opMails;
}
public void setOpMails(String opMails) {
this.opMails = opMails;
}
public String getOpNums() {
return opNums;
}
public void setOpNums(String opNums) {
this.opNums = opNums;
}
public String getComment() {
return Comment;
}
public void setComment(String comment) {
Comment = comment;
}
}
这是我的添加视图:
<form method="POST" commandName="operator" id="form-banner" class="form-horizontal" action="${pageContext.request.contextPath}/operator/add.html">
<div class="form-group">
<label class="col-sm-2 control-label" for="input-banner-name">ID/Name Operator</label>
<div class="col-sm-10">
<input type="text" name="name" value="" placeholder="Name Operator" class="form-control" path="opName" required/>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label" for="input-banner-name">Country</label>
<div class="col-sm-10">
<input type="text" name="country" value="" placeholder="Country" class="form-control" path="opCountry" required/>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label" for="input-banner-name">Date of Database</label>
<div class="col-sm-10">
<input type="text" name="date" value="" placeholder="Date" class="form-control" path="opDate" required/>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label" for="input-banner-name">Operator MCC</label>
<div class="col-sm-10">
<input type="text" name="name" value="" placeholder="MCC" class="form-control" path="opMCC" required/>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label" for="input-banner-name">Operator CC</label>
<div class="col-sm-10">
<input type="text" name="cc" value="" placeholder="CC" class="form-control" path="opCC" required/>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label" for="input-banner-name">Operator MNC</label>
<div class="col-sm-10">
<input type="text" name="mnc" value="" placeholder="MNC" class="form-control" path="opMNC" required/>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label" for="input-banner-name">Operator NC</label>
<div class="col-sm-10">
<input type="text" name="cc" value="" placeholder="NC" class="form-control" path="opNC" required/>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label" for="input-banner-name">PMN</label>
<div class="col-sm-10" >
<textarea placeholder="PMN" class="form-control" rows="3" path="opPMN" required></textarea>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label" for="input-banner-name">DNS</label>
<div class="col-sm-10">
<textarea placeholder="DNS" class="form-control" rows="3" path="opDNS" required></textarea>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label" for="input-banner-name">APN</label>
<div class="col-sm-10">
<textarea placeholder="APN" class="form-control" rows="3" path="opAPN" required></textarea>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label" for="input-banner-name">Mails</label>
<div class="col-sm-10">
<textarea placeholder="Address Mails" class="form-control" rows="3" path="opMails" required></textarea>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label" for="input-banner-name">Phones</label>
<div class="col-sm-10">
<textarea placeholder="Phone Numbers" class="form-control" rows="3" path="opNums" required></textarea>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label" for="input-banner-name">Comments</label>
<div class="col-sm-10">
<textarea placeholder="Put your comment" class="form-control" rows="3" path="Comment" required></textarea>
</div>
</div>
<input class="button-primary" type="submit" value="Add">
</form>
这是我遇到的例外,无法解决。
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.hibernate.exception.ConstraintViolationException: could not execute statement
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:948)
org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:838)
javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
cause mère
org.hibernate.exception.ConstraintViolationException: could not execute statement
org.hibernate.exception.internal.SQLExceptionTypeDelegate.convert(SQLExceptionTypeDelegate.java:74)
org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49)
org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:125)
org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:110)
org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:136)
org.hibernate.id.IdentityGenerator$GetGeneratedKeysDelegate.executeAndExtract(IdentityGenerator.java:96)
org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:58)
org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2966)
org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3477)
org.hibernate.action.internal.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:81)
org.hibernate.engine.spi.ActionQueue.execute(ActionQueue.java:362)
org.hibernate.engine.spi.ActionQueue.addResolvedEntityInsertAction(ActionQueue.java:203)
org.hibernate.engine.spi.ActionQueue.addInsertAction(ActionQueue.java:183)
org.hibernate.engine.spi.ActionQueue.addAction(ActionQueue.java:167)
org.hibernate.event.internal.AbstractSaveEventListener.addInsertAction(AbstractSaveEventListener.java:321)
org.hibernate.event.internal.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:286)
org.hibernate.event.internal.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:192)
org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:125)
org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:204)
org.hibernate.event.internal.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:55)
org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:189)
org.hibernate.event.internal.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:49)
org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:90)
org.hibernate.internal.SessionImpl.fireSave(SessionImpl.java:763)
org.hibernate.internal.SessionImpl.save(SessionImpl.java:755)
org.hibernate.internal.SessionImpl.save(SessionImpl.java:751)
com.roaming.dao.OperatorDAOImpl.addOperator(OperatorDAOImpl.java:63)
com.roaming.service.OpServiceImpl.addOperator(OpServiceImpl.java:21)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:498)
org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:96)
org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:260)
org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:94)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
com.sun.proxy.$Proxy30.addOperator(Unknown Source)
com.roaming.controller.OperatorController.addingOperator(OperatorController.java:37)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:498)
org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:219)
org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:745)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:686)
org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:936)
org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:838)
javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
cause mère
com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Column 'opAPN' cannot be null
sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
java.lang.reflect.Constructor.newInstance(Constructor.java:423)
com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
com.mysql.jdbc.Util.getInstance(Util.java:386)
com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1040)
com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4074)
com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4006)
com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2468)
com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2629)
com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2719)
com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2155)
com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2450)
com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2371)
com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2355)
org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:133)
org.hibernate.id.IdentityGenerator$GetGeneratedKeysDelegate.executeAndExtract(IdentityGenerator.java:96)
org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:58)
org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2966)
org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3477)
org.hibernate.action.internal.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:81)
org.hibernate.engine.spi.ActionQueue.execute(ActionQueue.java:362)
org.hibernate.engine.spi.ActionQueue.addResolvedEntityInsertAction(ActionQueue.java:203)
org.hibernate.engine.spi.ActionQueue.addInsertAction(ActionQueue.java:183)
org.hibernate.engine.spi.ActionQueue.addAction(ActionQueue.java:167)
org.hibernate.event.internal.AbstractSaveEventListener.addInsertAction(AbstractSaveEventListener.java:321)
org.hibernate.event.internal.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:286)
org.hibernate.event.internal.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:192)
org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:125)
org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:204)
org.hibernate.event.internal.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:55)
org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:189)
org.hibernate.event.internal.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:49)
org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:90)
org.hibernate.internal.SessionImpl.fireSave(SessionImpl.java:763)
org.hibernate.internal.SessionImpl.save(SessionImpl.java:755)
org.hibernate.internal.SessionImpl.save(SessionImpl.java:751)
com.roaming.dao.OperatorDAOImpl.addOperator(OperatorDAOImpl.java:63)
com.roaming.service.OpServiceImpl.addOperator(OpServiceImpl.java:21)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:498)
org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:96)
org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:260)
org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:94)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
com.sun.proxy.$Proxy30.addOperator(Unknown Source)
com.roaming.controller.OperatorController.addingOperator(OperatorController.java:37)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:498)
org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:219)
org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:745)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:686)
org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:936)
org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:838)
javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
如果我认为列'opAPN'不能为null,但是当我在数据库中将其设置为null时,它会传递给另一列并向我注入相同的异常.etc