mirror of
https://github.com/corda/corda.git
synced 2025-06-16 22:28:15 +00:00
[CORDA-1596] Improve error message when CorDapp schema changes (#4506)
* Raise schema exceptions with better error * Add test and use new exceptions
This commit is contained in:
@ -4,6 +4,7 @@ import co.paralleluniverse.strands.Strand
|
||||
import net.corda.core.internal.NamedCacheFactory
|
||||
import net.corda.core.schemas.MappedSchema
|
||||
import net.corda.core.utilities.contextLogger
|
||||
import org.hibernate.tool.schema.spi.SchemaManagementException
|
||||
import rx.Observable
|
||||
import rx.Subscriber
|
||||
import rx.subjects.UnicastSubject
|
||||
@ -101,7 +102,14 @@ class CordaPersistence(
|
||||
private val defaultIsolationLevel = databaseConfig.transactionIsolationLevel
|
||||
val hibernateConfig: HibernateConfiguration by lazy {
|
||||
transaction {
|
||||
HibernateConfiguration(schemas, databaseConfig, attributeConverters, jdbcUrl, cacheFactory, customClassLoader)
|
||||
try {
|
||||
HibernateConfiguration(schemas, databaseConfig, attributeConverters, jdbcUrl, cacheFactory, customClassLoader)
|
||||
} catch (e: Exception) {
|
||||
when (e) {
|
||||
is SchemaManagementException -> throw HibernateSchemaChangeException("Incompatible schema change detected. Please run the node with database.initialiseSchema=true. Reason: ${e.message}", e)
|
||||
else -> throw HibernateConfigException("Could not create Hibernate configuration: ${e.message}", e)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -339,3 +347,7 @@ private fun Throwable.hasSQLExceptionCause(): Boolean =
|
||||
}
|
||||
|
||||
class CouldNotCreateDataSourceException(override val message: String?, override val cause: Throwable? = null) : Exception()
|
||||
|
||||
class HibernateSchemaChangeException(override val message: String?, override val cause: Throwable? = null): Exception()
|
||||
|
||||
class HibernateConfigException(override val message: String?, override val cause: Throwable? = null): Exception()
|
||||
|
Reference in New Issue
Block a user