diff --git a/sqli-repo/src/main/java/io/xream/sqli/repository/dao/DaoImpl.java b/sqli-repo/src/main/java/io/xream/sqli/repository/dao/DaoImpl.java index dc632953..9b50d794 100644 --- a/sqli-repo/src/main/java/io/xream/sqli/repository/dao/DaoImpl.java +++ b/sqli-repo/src/main/java/io/xream/sqli/repository/dao/DaoImpl.java @@ -29,6 +29,7 @@ import io.xream.sqli.parser.BeanElement; import io.xream.sqli.parser.Parsed; import io.xream.sqli.parser.Parser; +import io.xream.sqli.repository.exception.SqliRumtimeException; import io.xream.sqli.repository.exception.TooManyResultsException; import io.xream.sqli.repository.init.SqlInit; import io.xream.sqli.repository.init.SqlTemplate; @@ -39,6 +40,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.sql.SQLIntegrityConstraintViolationException; import java.util.*; /** @@ -142,6 +144,14 @@ public boolean create(Object obj) { return this.jdbcHelper.create(isAutoIncreaseId,sql,valueList); } catch (Exception e) { + Throwable t = e.getCause(); + if ( t != null && + t instanceof SQLIntegrityConstraintViolationException){ + String msg = t.getMessage(); + if (msg.contains("cannot be null")) { + throw new SqliRumtimeException("Table of "+ Parser.get(clz).getTableName()+", " + msg); + } + } throw ExceptionTranslator.onRollback(obj, e, logger); } diff --git a/sqli-repo/src/main/java/io/xream/sqli/repository/exception/SqliRumtimeException.java b/sqli-repo/src/main/java/io/xream/sqli/repository/exception/SqliRumtimeException.java new file mode 100644 index 00000000..b5753730 --- /dev/null +++ b/sqli-repo/src/main/java/io/xream/sqli/repository/exception/SqliRumtimeException.java @@ -0,0 +1,29 @@ +/* + * Copyright 2020 io.xream.sqli + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.xream.sqli.repository.exception; + +/** + * @author Sim + */ +public class SqliRumtimeException extends RuntimeException{ + + public SqliRumtimeException(String message) { + super(message); + } +}