Skip to content

Commit 46e18c9

Browse files
flushChanges & delete throw SQLException
1 parent fb0c257 commit 46e18c9

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

ktorm-core/src/main/kotlin/org/ktorm/entity/Entity.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import java.io.ObjectInputStream
2323
import java.io.ObjectOutputStream
2424
import java.io.Serializable
2525
import java.lang.reflect.Proxy
26+
import java.sql.SQLException
2627
import kotlin.reflect.KClass
2728
import kotlin.reflect.full.isSubclassOf
2829
import 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
/**

ktorm-core/src/test/kotlin/org/ktorm/entity/EntityTest.kt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.ktorm.entity
22

3+
import org.h2.jdbc.JdbcSQLIntegrityConstraintViolationException
34
import org.junit.Test
45
import org.ktorm.BaseTest
56
import 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()

0 commit comments

Comments
 (0)