首页 > 解决方案 > net.corda.nodeapi.internal.persistence.CouldNotCreateDataSourceException:无法创建数据源

问题描述

我正在尝试使用此处的示例开发 CorDapp 。我在我的项目中添加了两个模块,一个用于合同,另一个用于流。我已经为我的合同添加了测试用例,它工作正常,但是流的测试用例在设置阶段失败。这是我的测试类的代码

@TestInstance(TestInstance.Lifecycle.PER_CLASS)
 class SharedInformationFlowTests {
   private lateinit var network: MockNetwork
   private lateinit var a: StartedMockNode
   private val proposal = LedgerUpdateProposal.testProposal()

@BeforeAll
fun setup() {
    val params = MockNetworkParameters(cordappsForAllNodes = listOf(
            TestCordapp.findCordapp("com.something.contract")
    ))

    network = MockNetwork(params) //fails here
    a = network.createPartyNode()
    network.runNetwork()
}

@AfterAll
fun tearDown() {
    network.stopNodes()
}

这是我收到的错误消息:

[WARN] 13:42:52,620 [main] spi.SqlExceptionHelper. - SQL Error: 0, SQLState: null {changeSet=migration/vault-schema.changelog-v9.xml::update-vault-states::R3.Corda, databaseChangeLog=master.changelog.json}
[ERROR] 13:42:52,620 [main] spi.SqlExceptionHelper. - Connection is closed {changeSet=migration/vault-schema.changelog-v9.xml::update-vault-states::R3.Corda, databaseChangeLog=master.changelog.json}


net.corda.nodeapi.internal.persistence.CouldNotCreateDataSourceException: Could not create the 
DataSource: Migration failed for change set migration/vault-schema.changelog-v9.xml::update-vault-states::R3.Corda:
 Reason: net.corda.nodeapi.internal.persistence.HibernateConfigException: Could not create Hibernate configuration: Unable to open JDBC Connection for DDL execution

我认为 liquibase 有问题。我已尝试按照此处的建议resources/migration将更改日志文件添加到我的目录中,但似乎没有任何效果。请帮忙。

更新添加架构

/**
 * The family of com.sentinel.schemas for SharingInformationState.
 */
object SharingInformationSchema

/**
 * An SharingInformationState schema.
 */
object SharingInformationSchemaV1 : MappedSchema(
    schemaFamily = SharingInformationSchema.javaClass,
    version = 1,
    mappedTypes = listOf(PersistentSharingInformation::class.java)) {
override val migrationResource: String? = "sharing-information-schema-v1.changelog-master.xml"

@Entity
@Table(name = "persistent_sharing_information")
class PersistentSharingInformation(
        @Column(name = "owner_id")
        var dataOwnerId: Long,

        @Column(name = "buyer_id")
        var dataBuyerId: Long,

        @Column(name = "start_date")
        val startDate: String,

        @Column(name = "end_date")
        val endDate: String,

        @Column(name = "shared_fields")
        val sharedFieldsIds: String,

        @Column(name = "agreement_status")
        val agreementStatus: String,

        @Column(name = "contract_type")
        val contractType: String,

        @Column(name = "linear_id")
        var linearId: UUID
) : PersistentState() {

    // Default constructor required by hibernate.
    constructor() : this(0L,  0L,
            "", "", "[]", "", "", UUID.randomUUID())
}

}

 @BelongsToContract(com.package.contract.SharingInformationContract::class)
 class SharingInformationState(val ourParty: Party,
                          val proposal: LedgerUpdateProposal,
                          override val linearId: UniqueIdentifier = UniqueIdentifier()) : LinearState, QueryableState {

override val participants: List<AbstractParty> = listOf(ourParty)

override fun generateMappedObject(schema: MappedSchema): PersistentState {
    return when (schema) {
        SharingInformationSchemaV1 -> SharingInformationSchemaV1.PersistentSharingInformation(
                proposal.ownerId,
                proposal.buyerId,
                proposal.startDate,
                proposal.endDate,
                proposal.sharedFieldsIds.toString(),
                proposal.agreementStatus.name,
                proposal.contractType.name,
                linearId.id
        )
        else -> throw IllegalArgumentException("Unrecognised schema $schema")
    }
}

override fun supportedSchemas(): Iterable<MappedSchema> = listOf(SharingInformationSchemaV1)

}

  @CordaSerializable
  enum class AgreementStatus { APPROVED, REJECTED }
  @CordaSerializable
  enum class ContractType { CORPORATE, CONSUMER, MARKETING, BINDING }

标签: kotlinliquibasecordadiscord

解决方案


推荐阅读