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

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

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".

  1. import net.corda.core.schemas.MappedSchema
  2. import net.corda.core.schemas.PersistentState
  3. import javax.persistence.*;
  4. import java.io.Serializable;
  5. import java.util.List;
  6. import java.util.UUID
  7. object Schema1
  8. object SchemaV1 : MappedSchema(
  9. schemaFamily = Schema1.javaClass,
  10. version = 1,
  11. mappedTypes = listOf(PersistentEmployees::class.java,PersistentEmployeeVehicles::class.java))
  12. {
  13. @Entity
  14. @Table(name = "TBL_EMPLOYEES")
  15. class PersistentEmployees(
  16. @Column(name = "EmployeeId")
  17. var Pid: Long,
  18. @Column(name = "EmployeeName")
  19. var EmployeeName: String,
  20. @Column(name = "EmployeeAddress")
  21. var EmployeeAddress: String,
  22. @OneToMany(cascade = [CascadeType.PERSIST])
  23. @JoinColumns({
  24. JoinColumn(name = "output_index", referencedColumnName = "output_index"),
  25. JoinColumn(name = "transaction_id", referencedColumnName = "transaction_id") })
  26. private val EmpVehicles:List<PersistentEmployeeVehicles>
  27. ) : PersistentState(), Serializable
  28. @Entity
  29. @Table(name = "TBL_EMPLOYEE_VEHICLES")
  30. class PersistentEmployeeVehicles(
  31. @Column(name = "ID")
  32. var ID: UUID,
  33. @Column(name = "VEHICLETYPE")
  34. var VEHICLETYPE: String,
  35. @Column(name = "VEHICLEMODEL")
  36. var VEHICLEMODEL: String,
  37. @Column(name = "VEHICLENUMBER")
  38. var VEHICLENUMBER: String
  39. )
  40. }

问题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-

  1. cordaReleaseGroup=net.corda
  2. cordaVersion=4.0
  3. gradlePluginsVersion=4.0.45
  4. kotlinVersion=1.2.71
  5. junitVersion=4.12
  6. quasarVersion=0.7.10
  7. spring_version = &#39;4.3.11.RELEASE&#39;
  8. spring_boot_version = &#39;2.0.2.RELEASE&#39;
  9. spring_boot_gradle_plugin_version = &#39;2.1.1.RELEASE&#39;
  10. jvmTarget = &quot;1.8&quot;
  11. log4jVersion =2.11.2
  12. platformVersion=4
  13. slf4jVersion=1.7.25
  14. 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".

  1. import net.corda.core.schemas.MappedSchema
  2. import net.corda.core.schemas.PersistentState
  3. import javax.persistence.*;
  4. import java.io.Serializable;
  5. import java.util.List;
  6. import java.util.UUID
  7. object Schema1
  8. object SchemaV1 : MappedSchema(
  9. schemaFamily = Schema1.javaClass,
  10. version = 1,
  11. mappedTypes = listOf(PersistentEmployees::class.java,PersistentEmployeeVehicles::class.java))
  12. {
  13. @Entity
  14. @Table(name = &quot;TBL_EMPLOYEES&quot;)
  15. class PersistentEmployees(
  16. @Column(name = &quot;EmployeeId&quot;)
  17. var Pid: Long,
  18. @Column(name = &quot;EmployeeName&quot;)
  19. var EmployeeName: String,
  20. @Column(name = &quot;EmployeeAddress&quot;)
  21. var EmployeeAddress: String,
  22. @OneToMany(cascade = [(CascadeType.PERSIST)])
  23. @JoinColumns({
  24. JoinColumn(name = &quot;output_index&quot;, referencedColumnName = &quot;output_index&quot;);
  25. JoinColumn(name = &quot;transaction_id&quot;, referencedColumnName = &quot;transaction_id&quot;) })
  26. private val EmpVehicles:List&lt;PersistentEmployeeVehicles&gt;
  27. ) : PersistentState(), Serializable
  28. @Entity
  29. @Table(name = &quot;TBL_EMPLOYEE_VEHICLES&quot;)
  30. class PersistentEmployeeVehicles(
  31. @Column(name = &quot;ID&quot;)
  32. var ID: UUID,
  33. @Column(name = &quot;VEHICLETYPE&quot;)
  34. var VEHICLETYPE: String,
  35. @Column(name = &quot;VEHICLEMODEL&quot;)
  36. var VEHICLEMODEL: String,
  37. @Column(name = &quot;VEHICLENUMBER&quot;)
  38. var VEHICLENUMBER: String
  39. )
  40. }

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,您应该使用[],如下所示:

  1. @JoinColumns(value = [
  2. JoinColumn(name = "output_index", referencedColumnName = "output_index"),
  3. JoinColumn(name = "transaction_id", referencedColumnName = "transaction_id")
  4. ])
  5. 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:

  1. @JoinColumns(value = [
  2. JoinColumn(name = &quot;output_index&quot;, referencedColumnName = &quot;output_index&quot;),
  3. JoinColumn(name = &quot;transaction_id&quot;, referencedColumnName = &quot;transaction_id&quot;) ])
  4. 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:

确定