我一直在尝试使用https://docs.corda.net/releases/release-V4.0/api-persistence.html?highlight=generatemappedobject#persisting-hierarchical-data作为指导来创建持久的分层状态结构。
我的结构如下。我有一个ServiceState,可以有0 .. * ServiceDataStates。将来,ServiceDataState也可以具有0 .. * usePurposeStates,但目前可以忽略。
您可以看到我当前的架构和状态。我的Corda版本是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]
答案 0 :(得分:0)
这肯定看起来像是一个休眠的问题,特别是其中您必须添加一些注释以清除问题的问题。
在列出您的特定问题时,可能是这样的?
@Column
@ElementCollection(targetClass=Integer.class)
private List<Integer> countries;
也请查看这些帖子,他们可能会为您提供帮助。
org.hibernate.MappingException: Could not determine type for: java.util.Set