File tree Expand file tree Collapse file tree 2 files changed +17
-0
lines changed
main/kotlin/org/ktorm/entity
test/kotlin/org/ktorm/entity Expand file tree Collapse file tree 2 files changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -23,6 +23,7 @@ import java.io.ObjectInputStream
2323import java.io.ObjectOutputStream
2424import java.io.Serializable
2525import java.lang.reflect.Proxy
26+ import java.sql.SQLException
2627import kotlin.reflect.KClass
2728import kotlin.reflect.full.isSubclassOf
2829import kotlin.reflect.jvm.jvmErasure
@@ -168,6 +169,7 @@ public interface Entity<E : Entity<E>> : Serializable {
168169 * @see add
169170 * @see update
170171 */
172+ @Throws(SQLException ::class )
171173 public fun flushChanges (): Int
172174
173175 /* *
@@ -191,6 +193,7 @@ public interface Entity<E : Entity<E>> : Serializable {
191193 * @see update
192194 * @see flushChanges
193195 */
196+ @Throws(SQLException ::class )
194197 public fun delete (): Int
195198
196199 /* *
Original file line number Diff line number Diff line change 11package org.ktorm.entity
22
3+ import org.h2.jdbc.JdbcSQLIntegrityConstraintViolationException
34import org.junit.Test
45import org.ktorm.BaseTest
56import org.ktorm.database.Database
@@ -397,6 +398,19 @@ class EntityTest : BaseTest() {
397398 assert (e.flushChanges() == 1 )
398399 }
399400
401+ @Test
402+ fun testExceptionThrowsByProxy () {
403+ try {
404+ val e = database.employees.find { it.id eq 1 } ? : throw AssertionError ()
405+ e.department = Department ()
406+ e.flushChanges()
407+
408+ throw AssertionError (" failed" )
409+ } catch (e: JdbcSQLIntegrityConstraintViolationException ) {
410+ assert (e.message!! .contains(" NULL not allowed for column \" department_id\" " ))
411+ }
412+ }
413+
400414 @Test
401415 fun testHasColumnValue () {
402416 val p1 = Parent ()
You can’t perform that action at this time.
0 commit comments