Я пытался создать постоянную иерархическую структуру состояний, используя https://docs.corda.net/releases/release-V4.0/api-persistence.html?highlight=generatemappedobject#persisting-hierarchical-data в качестве руководства.
Моя структура следующая. У меня есть ServiceState, который может иметь 0 .. * ServiceDataStates. В будущем ServiceDataState также может иметь 0 .. * usePurposeStates, но пока это можно игнорировать.
Вы можете видеть мои текущие схемы и состояния. Моя версия корда 3.3
object ServiceSchema
@CordaSerializable
object ServiceSchemaV1 : MappedSchema(
schemaFamily = ServiceSchema.javaClass,
version = 1,
mappedTypes = listOf(ServiceSchemaV1.PersistentServiceState::class.java,
ServiceDataSchemaV1.PersistentServiceDataState::class.java)) {
@Entity
@Table(name = "service_state")
class PersistentServiceState (
@Column(name = "linear_id", unique = true, nullable = false)
var linearId: UUID,
@Column(name = "account_operator", nullable = false)
var accountOoperator: String,
@Column(name = "service_provider", nullable = false)
var serviceProvider: String,
@Column(name = "service_name", nullable = false)
var serviceName: String,
@Column(name = "service_description", nullable = false)
var serviceDescription: String,
@Column(name = "date_created", nullable = false)
var dateCreated: LocalDate,
@JoinColumns(
JoinColumn(name = "transaction_id", referencedColumnName = "transaction_id"),
JoinColumn(name = "output_index", referencedColumnName = "output_index"))
var serviceDataStates: MutableList<ServiceDataState>?,
@Column(name = "service_partner_name", nullable = true)
var servicePartners: String?
) : PersistentState() {
constructor() : this(
UUID.randomUUID(),
"",
"",
"",
"",
LocalDate.now(),
mutableListOf(),
""
)
}
}
object ServiceDataSchema
@CordaSerializable
object ServiceDataSchemaV1: MappedSchema(
schemaFamily = ServiceDataSchema.javaClass,
version = 1,
mappedTypes = listOf(ServiceDataSchemaV1.PersistentServiceDataState::class.java,
ServiceSchemaV1.PersistentServiceState::class.java,
UsePurposeSchemaV1.PersistentUsePurposeState::class.java)) {
@Entity
@Table(name = "servicedata_state")
class PersistentServiceDataState(
@Column(name = "linearid", unique = true, nullable = false)
var linearId: UUID,
@Column(name = "name", nullable = false)
var name: String,
@Column(name = "type", nullable = false)
var type: String,
@Column(name = "usepurposes")
var usePurposes: UUID,
@Column(name = "api_schema", nullable = false)
var apiSchema: String,
@Column(name = "api_transfer_terms", nullable = false)
var apiTransferTerms: String,
@Column(name = "servicedata_party_name", nullable = true)
var parties: String?,
@ManyToOne(targetEntity = ServiceSchemaV1.PersistentServiceState::class)
var persistentServiceState: ServiceState?
) : PersistentState() {
constructor() : this(
UUID.randomUUID(),
"",
"",
UUID.randomUUID(),
"",
"",
"",
null
)
}
}
data class ServiceState(
val accountOperator: Party,
val serviceProvider: Party,
val serviceName: String,
val serviceDescription: String,
val dateCreated: LocalDate,
val serviceDataStates: MutableList<ServiceDataState>,
val servicePartners: MutableList<Party>,
override val linearId: UniqueIdentifier = UniqueIdentifier()
) : LinearState, QueryableState {
override fun supportedSchemas(): Iterable<MappedSchema> = listOf(ServiceSchemaV1)
override val participants get() =
listOf(accountOperator, serviceProvider)
override fun generateMappedObject(schema: MappedSchema): PersistentState {
return when (schema) {
is ServiceSchemaV1 -> ServiceSchemaV1.PersistentServiceState(
this.linearId.id,
this.accountOperator.name.toString(),
this.serviceProvider.name.toString(),
this.serviceName,
this.serviceDescription,
this.dateCreated,
this.serviceDataStates,
this.servicePartners[0]?.name.toString()
)
else -> throw IllegalArgumentException("Unrecognised schema $schema")
}
}
fun serviceCopyWithTodaysDate() = copy(dateCreated = LocalDate.now())
fun addServiceData(
serviceDataList: MutableList<ServiceDataState>,
id: UniqueIdentifier
) = copy(
serviceDataStates = serviceDataList,
linearId = id
)
fun addPartners(servicePartners: MutableList<Party>, id: UniqueIdentifier) = copy(
servicePartners = servicePartners,
linearId = id
)
}
data class ServiceDataState(
override val linearId: UniqueIdentifier = UniqueIdentifier(),
val name: String,
val type: String,
val usePurposes: MutableList<UniqueIdentifier>,
val service: ServiceState,
val apiSchema: String,
val apiTransferTerms: String,
val parties: MutableList<Party>
) : LinearState, QueryableState {
override val participants: List<Party> get() =
parties
override fun generateMappedObject(schema: MappedSchema): PersistentState {
return when (schema) {
is ServiceDataSchemaV1 -> ServiceDataSchemaV1.PersistentServiceDataState(
this.linearId.id,
this.name,
this.type,
this.usePurposes[0]?.id,
this.apiSchema,
this.apiTransferTerms,
this.parties[0]?.name.toString(),
this.service
)
else -> throw IllegalArgumentException("Unrecognised schema $schema")
}
}
override fun supportedSchemas(): Iterable<MappedSchema> = listOf(ServiceDataSchemaV1)
Я не знаю, что мне не хватает. Когда я запускаю свои узлы, я получаю следующую трассировку стека
org.hibernate.MappingException: Could not determine type for: java.util.List, at table: service_state, for columns: [org.hibernate.mapping.Column(serviceDataStates)]
at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:455) ~[hibernate-core-5.2.6.Final.jar:5.2.6.Final]
at org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:422) ~[hibernate-core-5.2.6.Final.jar:5.2.6.Final]
at org.hibernate.mapping.Property.isValid(Property.java:226) ~[hibernate-core-5.2.6.Final.jar:5.2.6.Final]
at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:597) ~[hibernate-core-5.2.6.Final.jar:5.2.6.Final]