mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
More detailed exception on persist errors
This commit is contained in:
@@ -4,6 +4,7 @@ import io.ebean.config.dbplatform.DatabasePlatform;
|
||||
import io.ebean.util.StringHelper;
|
||||
import io.ebeaninternal.server.core.PersistRequestBean;
|
||||
import io.ebeaninternal.server.persist.BeanPersister;
|
||||
import io.ebeaninternal.server.type.DataBindCapture;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
||||
@@ -70,7 +71,7 @@ final class DmlBeanPersister implements BeanPersister {
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
// log the error to the transaction log
|
||||
String msg = "Error[" + StringHelper.removeNewLines(e.getMessage()) + "]";
|
||||
String msg = "Error[" + StringHelper.removeNewLines(e.getMessage()) + "] " + handler;
|
||||
if (request.transaction().isLogSummary()) {
|
||||
request.transaction().logSummary(msg);
|
||||
}
|
||||
|
||||
@@ -259,4 +259,14 @@ public abstract class DmlHandler implements PersistHandler, BindableRequest {
|
||||
return stmt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
if (sql == null) {
|
||||
return "not yet initialized";
|
||||
} else if (bindLog == null || bindLog.length() == 0) {
|
||||
return sql;
|
||||
} else {
|
||||
return Str.add(sql, " -- bind(", bindLog.toString(), ")");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,11 +5,13 @@ import io.ebean.DB;
|
||||
import io.ebean.DataIntegrityException;
|
||||
import io.ebean.xtest.IgnorePlatform;
|
||||
import io.ebean.annotation.Platform;
|
||||
import org.assertj.core.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.tests.model.basic.Customer;
|
||||
import org.tests.model.basic.Order;
|
||||
import org.tests.model.basic.ResetBasicData;
|
||||
|
||||
import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
public class TestInsertDataIntegrityException extends BaseTestCase {
|
||||
@@ -26,7 +28,10 @@ public class TestInsertDataIntegrityException extends BaseTestCase {
|
||||
Order order = new Order();
|
||||
order.setStatus(Order.Status.NEW);
|
||||
order.setCustomer(invalidCustomer);
|
||||
assertThatThrownBy(() -> DB.save(order))
|
||||
.isInstanceOf(DataIntegrityException.class)
|
||||
.hasMessageContaining("insert into o_order")
|
||||
.hasMessageContaining(",900000");
|
||||
|
||||
assertThrows(DataIntegrityException.class, () -> DB.save(order));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user