英文:
Type mismatch: inferred type is () -> JoinColumn but JoinColumn was expected
问题
我们正在使用Corda 4、Springboot Web服务器和Postgresql 11。
以下是Corda平台、Springboot服务器和其他必要依赖项的版本-
cordaReleaseGroup=net.corda
cordaVersion=4.0
gradlePluginsVersion=4.0.45
kotlinVersion=1.2.71
junitVersion=4.12
quasarVersion=0.7.10
spring_version = '4.3.11.RELEASE'
spring_boot_version = '2.0.2.RELEASE'
spring_boot_gradle_plugin_version = '2.1.1.RELEASE'
jvmTarget = "1.8"
log4jVersion =2.11.2
platformVersion=4
slf4jVersion=1.7.25
nettyVersion=4.1.22.Final
我们成功地实现了从一个节点向目标存储表发送单个事务记录。
我们遇到了一个需求,这个事务是一对多类型的,因此需要在存储中创建父子表。
以下是用于创建父子表模式的代码,但在编译时抛出错误 - "Type mismatch: inferred type is () -> JoinColumn but JoinColumn was expected".
import net.corda.core.schemas.MappedSchema
import net.corda.core.schemas.PersistentState
import javax.persistence.*;
import java.io.Serializable;
import java.util.List;
import java.util.UUID
object Schema1
object SchemaV1 : MappedSchema(
schemaFamily = Schema1.javaClass,
version = 1,
mappedTypes = listOf(PersistentEmployees::class.java,PersistentEmployeeVehicles::class.java))
{
@Entity
@Table(name = "TBL_EMPLOYEES")
class PersistentEmployees(
@Column(name = "EmployeeId")
var Pid: Long,
@Column(name = "EmployeeName")
var EmployeeName: String,
@Column(name = "EmployeeAddress")
var EmployeeAddress: String,
@OneToMany(cascade = [CascadeType.PERSIST])
@JoinColumns({
JoinColumn(name = "output_index", referencedColumnName = "output_index"),
JoinColumn(name = "transaction_id", referencedColumnName = "transaction_id") })
private val EmpVehicles:List<PersistentEmployeeVehicles>
) : PersistentState(), Serializable
@Entity
@Table(name = "TBL_EMPLOYEE_VEHICLES")
class PersistentEmployeeVehicles(
@Column(name = "ID")
var ID: UUID,
@Column(name = "VEHICLETYPE")
var VEHICLETYPE: String,
@Column(name = "VEHICLEMODEL")
var VEHICLEMODEL: String,
@Column(name = "VEHICLENUMBER")
var VEHICLENUMBER: String
)
}
问题1:错误的原因是什么,是否可能提供解决方案?
我们使用了Corda Git Hub上的“Car insurance”和“一对多”映射示例。以下是链接-
"https://github.com/corda/samples/blob/release-V4/carinsurance-QueryableState/contracts/src/main/java/net/corda/examples/carinsurance/schema/PersistentInsurance.java"
"https://github.com/corda/samples/blob/release-V4/carinsurance-QueryableState/contracts/src/main/java/net/corda/examples/carinsurance/schema/PersistentClaim.java"
英文:
We are using Corda 4, Springboot web server and Postgresql 11.
Following are the versions of Corda platform, Springboot server, and other essential dependencies used-
cordaReleaseGroup=net.corda
cordaVersion=4.0
gradlePluginsVersion=4.0.45
kotlinVersion=1.2.71
junitVersion=4.12
quasarVersion=0.7.10
spring_version = '4.3.11.RELEASE'
spring_boot_version = '2.0.2.RELEASE'
spring_boot_gradle_plugin_version = '2.1.1.RELEASE'
jvmTarget = "1.8"
log4jVersion =2.11.2
platformVersion=4
slf4jVersion=1.7.25
nettyVersion=4.1.22.Final
We were able to achieve the sending of single transaction record to a target vault table, from a node to another.
We have come across a requirement in which the transaction is of One-to-many type, for which parent-child tables need to be created in the vault.
Following is the code to create the schema for the parent-child tables but it throws error on compilation -
"Type mismatch: inferred type is () -> JoinColumn but JoinColumn was expected".
import net.corda.core.schemas.MappedSchema
import net.corda.core.schemas.PersistentState
import javax.persistence.*;
import java.io.Serializable;
import java.util.List;
import java.util.UUID
object Schema1
object SchemaV1 : MappedSchema(
schemaFamily = Schema1.javaClass,
version = 1,
mappedTypes = listOf(PersistentEmployees::class.java,PersistentEmployeeVehicles::class.java))
{
@Entity
@Table(name = "TBL_EMPLOYEES")
class PersistentEmployees(
@Column(name = "EmployeeId")
var Pid: Long,
@Column(name = "EmployeeName")
var EmployeeName: String,
@Column(name = "EmployeeAddress")
var EmployeeAddress: String,
@OneToMany(cascade = [(CascadeType.PERSIST)])
@JoinColumns({
JoinColumn(name = "output_index", referencedColumnName = "output_index");
JoinColumn(name = "transaction_id", referencedColumnName = "transaction_id") })
private val EmpVehicles:List<PersistentEmployeeVehicles>
) : PersistentState(), Serializable
@Entity
@Table(name = "TBL_EMPLOYEE_VEHICLES")
class PersistentEmployeeVehicles(
@Column(name = "ID")
var ID: UUID,
@Column(name = "VEHICLETYPE")
var VEHICLETYPE: String,
@Column(name = "VEHICLEMODEL")
var VEHICLEMODEL: String,
@Column(name = "VEHICLENUMBER")
var VEHICLENUMBER: String
)
}
Question 1: What would be the cause of the error and also the solution (if possible)?
We used "Car insurance" "One-to-many" mapping sample from Corda Git Hub. Following are the links-
"https://github.com/corda/samples/blob/release-V4/carinsurance-QueryableState/contracts/src/main/java/net/corda/examples/carinsurance/schema/PersistentInsurance.java"
"https://github.com/corda/samples/blob/release-V4/carinsurance-QueryableState/contracts/src/main/java/net/corda/examples/carinsurance/schema/PersistentClaim.java"
答案1
得分: 2
在Java和Kotlin中,在注解内声明数组的语法不同。对于Kotlin,您应该使用[]
,如下所示:
@JoinColumns(value = [
JoinColumn(name = "output_index", referencedColumnName = "output_index"),
JoinColumn(name = "transaction_id", referencedColumnName = "transaction_id")
])
private val EmpVehicles: List<PersistentEmployeeVehicles>
英文:
The syntax for declaring arrays within annotations is different between Java and Kotlin, for Kotlin, you should use []
like the following:
@JoinColumns(value = [
JoinColumn(name = "output_index", referencedColumnName = "output_index"),
JoinColumn(name = "transaction_id", referencedColumnName = "transaction_id") ])
private val EmpVehicles:List<PersistentEmployeeVehicles>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论