类型不匹配:推断的类型是() -> JoinColumn,但期望的是JoinColumn。

huangapple go评论94阅读模式
英文:

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 = &#39;4.3.11.RELEASE&#39;
spring_boot_version = &#39;2.0.2.RELEASE&#39;
spring_boot_gradle_plugin_version = &#39;2.1.1.RELEASE&#39;
jvmTarget = &quot;1.8&quot;
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 = &quot;TBL_EMPLOYEES&quot;)
class PersistentEmployees(
    @Column(name = &quot;EmployeeId&quot;)
    var Pid: Long,

    @Column(name = &quot;EmployeeName&quot;)
    var EmployeeName: String,

    @Column(name = &quot;EmployeeAddress&quot;) 
    var EmployeeAddress: String,

    @OneToMany(cascade = [(CascadeType.PERSIST)])
    @JoinColumns({
        JoinColumn(name = &quot;output_index&quot;, referencedColumnName = &quot;output_index&quot;);
        JoinColumn(name = &quot;transaction_id&quot;, referencedColumnName = &quot;transaction_id&quot;) })        
    private val EmpVehicles:List&lt;PersistentEmployeeVehicles&gt;
    
) : PersistentState(), Serializable

@Entity
@Table(name = &quot;TBL_EMPLOYEE_VEHICLES&quot;)
class PersistentEmployeeVehicles(
    @Column(name = &quot;ID&quot;)
    var ID: UUID,

    @Column(name = &quot;VEHICLETYPE&quot;) 
    var VEHICLETYPE: String,
    
    @Column(name = &quot;VEHICLEMODEL&quot;) 
    var VEHICLEMODEL: String,
    
    @Column(name = &quot;VEHICLENUMBER&quot;) 
    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 = &quot;output_index&quot;, referencedColumnName = &quot;output_index&quot;),
    JoinColumn(name = &quot;transaction_id&quot;, referencedColumnName = &quot;transaction_id&quot;) ])      
private val EmpVehicles:List&lt;PersistentEmployeeVehicles&gt;

huangapple
  • 本文由 发表于 2020年1月6日 20:36:10
  • 转载请务必保留本文链接:https://go.coder-hub.com/59612247.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定