mirror of
https://github.com/corda/corda.git
synced 2025-06-18 07:08:15 +00:00
hibernate mapping changes (#2337)
* add foreign key names and move the participants mapping to the subclass so that the table name can be configured * update api-current file * fix compilation errors * PR changes * PR changes
This commit is contained in:
@ -2613,22 +2613,22 @@ public final class net.corda.core.schemas.CommonSchemaV1 extends net.corda.core.
|
|||||||
@org.jetbrains.annotations.NotNull public final net.corda.core.identity.AbstractParty getIssuer()
|
@org.jetbrains.annotations.NotNull public final net.corda.core.identity.AbstractParty getIssuer()
|
||||||
@org.jetbrains.annotations.NotNull public final byte[] getIssuerRef()
|
@org.jetbrains.annotations.NotNull public final byte[] getIssuerRef()
|
||||||
@org.jetbrains.annotations.NotNull public final net.corda.core.identity.AbstractParty getOwner()
|
@org.jetbrains.annotations.NotNull public final net.corda.core.identity.AbstractParty getOwner()
|
||||||
@org.jetbrains.annotations.Nullable public final Set getParticipants()
|
@org.jetbrains.annotations.Nullable public Set getParticipants()
|
||||||
public final long getQuantity()
|
public final long getQuantity()
|
||||||
public final void setIssuer(net.corda.core.identity.AbstractParty)
|
public final void setIssuer(net.corda.core.identity.AbstractParty)
|
||||||
public final void setIssuerRef(byte[])
|
public final void setIssuerRef(byte[])
|
||||||
public final void setOwner(net.corda.core.identity.AbstractParty)
|
public final void setOwner(net.corda.core.identity.AbstractParty)
|
||||||
public final void setParticipants(Set)
|
public void setParticipants(Set)
|
||||||
public final void setQuantity(long)
|
public final void setQuantity(long)
|
||||||
##
|
##
|
||||||
@javax.persistence.MappedSuperclass @net.corda.core.serialization.CordaSerializable public static class net.corda.core.schemas.CommonSchemaV1$LinearState extends net.corda.core.schemas.PersistentState
|
@javax.persistence.MappedSuperclass @net.corda.core.serialization.CordaSerializable public static class net.corda.core.schemas.CommonSchemaV1$LinearState extends net.corda.core.schemas.PersistentState
|
||||||
public <init>(Set, String, UUID)
|
public <init>(Set, String, UUID)
|
||||||
public <init>(net.corda.core.contracts.UniqueIdentifier, Set)
|
public <init>(net.corda.core.contracts.UniqueIdentifier, Set)
|
||||||
@org.jetbrains.annotations.Nullable public final String getExternalId()
|
@org.jetbrains.annotations.Nullable public final String getExternalId()
|
||||||
@org.jetbrains.annotations.Nullable public final Set getParticipants()
|
@org.jetbrains.annotations.Nullable public Set getParticipants()
|
||||||
@org.jetbrains.annotations.NotNull public final UUID getUuid()
|
@org.jetbrains.annotations.NotNull public final UUID getUuid()
|
||||||
public final void setExternalId(String)
|
public final void setExternalId(String)
|
||||||
public final void setParticipants(Set)
|
public void setParticipants(Set)
|
||||||
public final void setUuid(UUID)
|
public final void setUuid(UUID)
|
||||||
##
|
##
|
||||||
public class net.corda.core.schemas.MappedSchema extends java.lang.Object
|
public class net.corda.core.schemas.MappedSchema extends java.lang.Object
|
||||||
|
@ -32,14 +32,14 @@ object NodeInfoSchemaV1 : MappedSchema(
|
|||||||
|
|
||||||
@Column(name = "addresses")
|
@Column(name = "addresses")
|
||||||
@OneToMany(cascade = arrayOf(CascadeType.ALL), orphanRemoval = true)
|
@OneToMany(cascade = arrayOf(CascadeType.ALL), orphanRemoval = true)
|
||||||
@JoinColumn(name = "node_info_id")
|
@JoinColumn(name = "node_info_id", foreignKey = ForeignKey(name = "FK__info_hosts__infos"))
|
||||||
val addresses: List<NodeInfoSchemaV1.DBHostAndPort>,
|
val addresses: List<NodeInfoSchemaV1.DBHostAndPort>,
|
||||||
|
|
||||||
@Column(name = "legal_identities_certs")
|
@Column(name = "legal_identities_certs")
|
||||||
@ManyToMany(cascade = arrayOf(CascadeType.ALL))
|
@ManyToMany(cascade = arrayOf(CascadeType.ALL))
|
||||||
@JoinTable(name = "node_link_nodeinfo_party",
|
@JoinTable(name = "node_link_nodeinfo_party",
|
||||||
joinColumns = arrayOf(JoinColumn(name = "node_info_id")),
|
joinColumns = arrayOf(JoinColumn(name = "node_info_id", foreignKey = ForeignKey(name = "FK__link_nodeinfo_party__infos"))),
|
||||||
inverseJoinColumns = arrayOf(JoinColumn(name = "party_name")))
|
inverseJoinColumns = arrayOf(JoinColumn(name = "party_name", foreignKey = ForeignKey(name = "FK__link_ni_p__info_p_cert"))))
|
||||||
val legalIdentitiesAndCerts: List<DBPartyAndCertificate>,
|
val legalIdentitiesAndCerts: List<DBPartyAndCertificate>,
|
||||||
|
|
||||||
@Column(name = "platform_version")
|
@Column(name = "platform_version")
|
||||||
|
@ -5,8 +5,8 @@ import net.corda.core.identity.AbstractParty
|
|||||||
import org.hibernate.annotations.Type
|
import org.hibernate.annotations.Type
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import javax.persistence.Column
|
import javax.persistence.Column
|
||||||
import javax.persistence.ElementCollection
|
|
||||||
import javax.persistence.MappedSuperclass
|
import javax.persistence.MappedSuperclass
|
||||||
|
import javax.persistence.Transient
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* JPA representation of the common schema entities
|
* JPA representation of the common schema entities
|
||||||
@ -23,9 +23,8 @@ object CommonSchemaV1 : MappedSchema(schemaFamily = CommonSchema.javaClass, vers
|
|||||||
/** [ContractState] attributes */
|
/** [ContractState] attributes */
|
||||||
|
|
||||||
/** X500Name of participant parties **/
|
/** X500Name of participant parties **/
|
||||||
@ElementCollection
|
@Transient
|
||||||
@Column(name = "participants")
|
open var participants: MutableSet<AbstractParty>? = null,
|
||||||
var participants: MutableSet<AbstractParty>? = null,
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a [LinearState] [UniqueIdentifier]
|
* Represents a [LinearState] [UniqueIdentifier]
|
||||||
@ -34,6 +33,7 @@ object CommonSchemaV1 : MappedSchema(schemaFamily = CommonSchema.javaClass, vers
|
|||||||
var externalId: String?,
|
var externalId: String?,
|
||||||
|
|
||||||
@Column(name = "uuid", nullable = false)
|
@Column(name = "uuid", nullable = false)
|
||||||
|
@Type(type = "uuid-char")
|
||||||
var uuid: UUID
|
var uuid: UUID
|
||||||
|
|
||||||
) : PersistentState() {
|
) : PersistentState() {
|
||||||
@ -48,9 +48,8 @@ object CommonSchemaV1 : MappedSchema(schemaFamily = CommonSchema.javaClass, vers
|
|||||||
/** [ContractState] attributes */
|
/** [ContractState] attributes */
|
||||||
|
|
||||||
/** X500Name of participant parties **/
|
/** X500Name of participant parties **/
|
||||||
@ElementCollection
|
@Transient
|
||||||
@Column(name = "participants")
|
open var participants: MutableSet<AbstractParty>? = null,
|
||||||
var participants: MutableSet<AbstractParty>? = null,
|
|
||||||
|
|
||||||
/** [OwnableState] attributes */
|
/** [OwnableState] attributes */
|
||||||
|
|
||||||
|
@ -6,6 +6,9 @@ from the previous milestone release.
|
|||||||
|
|
||||||
UNRELEASED
|
UNRELEASED
|
||||||
----------
|
----------
|
||||||
|
* JPA Mapping annotations for States extending ``CommonSchemaV1.LinearState`` and ``CommonSchemaV1.FungibleState`` on the
|
||||||
|
`participants` collection need to be moved to the actual class. This allows to properly specify the unique table name per a collection.
|
||||||
|
See: DummyDealStateSchemaV1.PersistentDummyDealState
|
||||||
|
|
||||||
* X.509 certificates now have an extension that specifies the Corda role the certificate is used for, and the role
|
* X.509 certificates now have an extension that specifies the Corda role the certificate is used for, and the role
|
||||||
hierarchy is now enforced in the validation code. See ``net.corda.core.internal.CertRole`` for the current implementation
|
hierarchy is now enforced in the validation code. See ``net.corda.core.internal.CertRole`` for the current implementation
|
||||||
|
@ -31,6 +31,26 @@ We also strongly recommend cross referencing with the :doc:`changelog` to confir
|
|||||||
UNRELEASED
|
UNRELEASED
|
||||||
----------
|
----------
|
||||||
|
|
||||||
|
* For existing contract ORM schemas that extend from `CommonSchemaV1.LinearState` or `CommonSchemaV1.FungibleState`,
|
||||||
|
you will need to explicitly map the `participants` collection to a database table. Previously this mapping was done in the
|
||||||
|
superclass, but that makes it impossible to properly configure the table name.
|
||||||
|
The required change is to add the ``override var participants: MutableSet<AbstractParty>? = null`` field to your class, and
|
||||||
|
add JPA mappings. For ex., see this example:
|
||||||
|
|
||||||
|
.. sourcecode:: kotlin
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name = "cash_states_v2",
|
||||||
|
indexes = arrayOf(Index(name = "ccy_code_idx2", columnList = "ccy_code")))
|
||||||
|
class PersistentCashState(
|
||||||
|
|
||||||
|
@ElementCollection
|
||||||
|
@Column(name = "participants")
|
||||||
|
@CollectionTable(name="cash_states_v2_participants", joinColumns = arrayOf(
|
||||||
|
JoinColumn(name = "output_index", referencedColumnName = "output_index"),
|
||||||
|
JoinColumn(name = "transaction_id", referencedColumnName = "transaction_id")))
|
||||||
|
override var participants: MutableSet<AbstractParty>? = null,
|
||||||
|
|
||||||
Testing
|
Testing
|
||||||
~~~~~~~
|
~~~~~~~
|
||||||
|
|
||||||
|
@ -4,10 +4,7 @@ import net.corda.core.identity.AbstractParty
|
|||||||
import net.corda.core.schemas.CommonSchemaV1
|
import net.corda.core.schemas.CommonSchemaV1
|
||||||
import net.corda.core.schemas.MappedSchema
|
import net.corda.core.schemas.MappedSchema
|
||||||
import net.corda.core.utilities.OpaqueBytes
|
import net.corda.core.utilities.OpaqueBytes
|
||||||
import javax.persistence.Column
|
import javax.persistence.*
|
||||||
import javax.persistence.Entity
|
|
||||||
import javax.persistence.Index
|
|
||||||
import javax.persistence.Table
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Second version of a cash contract ORM schema that extends the common
|
* Second version of a cash contract ORM schema that extends the common
|
||||||
@ -19,6 +16,14 @@ object SampleCashSchemaV2 : MappedSchema(schemaFamily = CashSchema.javaClass, ve
|
|||||||
@Table(name = "cash_states_v2",
|
@Table(name = "cash_states_v2",
|
||||||
indexes = arrayOf(Index(name = "ccy_code_idx2", columnList = "ccy_code")))
|
indexes = arrayOf(Index(name = "ccy_code_idx2", columnList = "ccy_code")))
|
||||||
class PersistentCashState(
|
class PersistentCashState(
|
||||||
|
|
||||||
|
@ElementCollection
|
||||||
|
@Column(name = "participants")
|
||||||
|
@CollectionTable(name="cash_states_v2_participants", joinColumns = arrayOf(
|
||||||
|
JoinColumn(name = "output_index", referencedColumnName = "output_index"),
|
||||||
|
JoinColumn(name = "transaction_id", referencedColumnName = "transaction_id")))
|
||||||
|
override var participants: MutableSet<AbstractParty>? = null,
|
||||||
|
|
||||||
/** product type */
|
/** product type */
|
||||||
@Column(name = "ccy_code", length = 3)
|
@Column(name = "ccy_code", length = 3)
|
||||||
var currency: String,
|
var currency: String,
|
||||||
|
@ -8,10 +8,7 @@ import net.corda.core.utilities.MAX_HASH_HEX_SIZE
|
|||||||
import net.corda.core.utilities.OpaqueBytes
|
import net.corda.core.utilities.OpaqueBytes
|
||||||
import org.hibernate.annotations.Type
|
import org.hibernate.annotations.Type
|
||||||
import java.time.Instant
|
import java.time.Instant
|
||||||
import javax.persistence.Column
|
import javax.persistence.*
|
||||||
import javax.persistence.Entity
|
|
||||||
import javax.persistence.Index
|
|
||||||
import javax.persistence.Table
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Second version of a cash contract ORM schema that extends the common
|
* Second version of a cash contract ORM schema that extends the common
|
||||||
@ -24,6 +21,14 @@ object SampleCommercialPaperSchemaV2 : MappedSchema(schemaFamily = CommercialPap
|
|||||||
indexes = arrayOf(Index(name = "ccy_code_index2", columnList = "ccy_code"),
|
indexes = arrayOf(Index(name = "ccy_code_index2", columnList = "ccy_code"),
|
||||||
Index(name = "maturity_index2", columnList = "maturity_instant")))
|
Index(name = "maturity_index2", columnList = "maturity_instant")))
|
||||||
class PersistentCommercialPaperState(
|
class PersistentCommercialPaperState(
|
||||||
|
|
||||||
|
@ElementCollection
|
||||||
|
@Column(name = "participants")
|
||||||
|
@CollectionTable(name="cp_states_v2_participants", joinColumns = arrayOf(
|
||||||
|
JoinColumn(name = "output_index", referencedColumnName = "output_index"),
|
||||||
|
JoinColumn(name = "transaction_id", referencedColumnName = "transaction_id")))
|
||||||
|
override var participants: MutableSet<AbstractParty>? = null,
|
||||||
|
|
||||||
@Column(name = "maturity_instant")
|
@Column(name = "maturity_instant")
|
||||||
var maturity: Instant,
|
var maturity: Instant,
|
||||||
|
|
||||||
|
@ -77,7 +77,8 @@ object VaultSchemaV1 : MappedSchema(schemaFamily = VaultSchema.javaClass, versio
|
|||||||
@CollectionTable(name = "vault_linear_states_parts",
|
@CollectionTable(name = "vault_linear_states_parts",
|
||||||
joinColumns = arrayOf(
|
joinColumns = arrayOf(
|
||||||
JoinColumn(name = "output_index", referencedColumnName = "output_index"),
|
JoinColumn(name = "output_index", referencedColumnName = "output_index"),
|
||||||
JoinColumn(name = "transaction_id", referencedColumnName = "transaction_id")))
|
JoinColumn(name = "transaction_id", referencedColumnName = "transaction_id")),
|
||||||
|
foreignKey = ForeignKey(name = "FK__lin_stat_parts__lin_stat"))
|
||||||
@Column(name = "participants")
|
@Column(name = "participants")
|
||||||
var participants: MutableSet<AbstractParty>? = null,
|
var participants: MutableSet<AbstractParty>? = null,
|
||||||
// Reason for not using Set is described here:
|
// Reason for not using Set is described here:
|
||||||
@ -109,7 +110,8 @@ object VaultSchemaV1 : MappedSchema(schemaFamily = VaultSchema.javaClass, versio
|
|||||||
@CollectionTable(name = "vault_fungible_states_parts",
|
@CollectionTable(name = "vault_fungible_states_parts",
|
||||||
joinColumns = arrayOf(
|
joinColumns = arrayOf(
|
||||||
JoinColumn(name = "output_index", referencedColumnName = "output_index"),
|
JoinColumn(name = "output_index", referencedColumnName = "output_index"),
|
||||||
JoinColumn(name = "transaction_id", referencedColumnName = "transaction_id")))
|
JoinColumn(name = "transaction_id", referencedColumnName = "transaction_id")),
|
||||||
|
foreignKey = ForeignKey(name = "FK__fung_st_parts__fung_st"))
|
||||||
@Column(name = "participants")
|
@Column(name = "participants")
|
||||||
var participants: MutableSet<AbstractParty>? = null,
|
var participants: MutableSet<AbstractParty>? = null,
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ class DummyDealContract : Contract {
|
|||||||
override fun generateMappedObject(schema: MappedSchema): PersistentState {
|
override fun generateMappedObject(schema: MappedSchema): PersistentState {
|
||||||
return when (schema) {
|
return when (schema) {
|
||||||
is DummyDealStateSchemaV1 -> DummyDealStateSchemaV1.PersistentDummyDealState(
|
is DummyDealStateSchemaV1 -> DummyDealStateSchemaV1.PersistentDummyDealState(
|
||||||
_participants = participants.toSet(),
|
participants = participants.toMutableSet(),
|
||||||
uid = linearId
|
uid = linearId
|
||||||
)
|
)
|
||||||
else -> throw IllegalArgumentException("Unrecognised schema $schema")
|
else -> throw IllegalArgumentException("Unrecognised schema $schema")
|
||||||
|
@ -4,9 +4,7 @@ import net.corda.core.contracts.UniqueIdentifier
|
|||||||
import net.corda.core.identity.AbstractParty
|
import net.corda.core.identity.AbstractParty
|
||||||
import net.corda.core.schemas.CommonSchemaV1
|
import net.corda.core.schemas.CommonSchemaV1
|
||||||
import net.corda.core.schemas.MappedSchema
|
import net.corda.core.schemas.MappedSchema
|
||||||
import javax.persistence.Entity
|
import javax.persistence.*
|
||||||
import javax.persistence.Table
|
|
||||||
import javax.persistence.Transient
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An object used to fully qualify the [DummyDealStateSchema] family name (i.e. independent of version).
|
* An object used to fully qualify the [DummyDealStateSchema] family name (i.e. independent of version).
|
||||||
@ -22,11 +20,15 @@ object DummyDealStateSchemaV1 : MappedSchema(schemaFamily = DummyDealStateSchema
|
|||||||
@Table(name = "dummy_deal_states")
|
@Table(name = "dummy_deal_states")
|
||||||
class PersistentDummyDealState(
|
class PersistentDummyDealState(
|
||||||
/** parent attributes */
|
/** parent attributes */
|
||||||
@Transient
|
@ElementCollection
|
||||||
val _participants: Set<AbstractParty>,
|
@Column(name = "participants")
|
||||||
|
@CollectionTable(name = "dummy_deal_states_participants", joinColumns = arrayOf(
|
||||||
|
JoinColumn(name = "output_index", referencedColumnName = "output_index"),
|
||||||
|
JoinColumn(name = "transaction_id", referencedColumnName = "transaction_id")))
|
||||||
|
override var participants: MutableSet<AbstractParty>? = null,
|
||||||
|
|
||||||
@Transient
|
@Transient
|
||||||
val uid: UniqueIdentifier
|
val uid: UniqueIdentifier
|
||||||
|
|
||||||
) : CommonSchemaV1.LinearState(uid, _participants)
|
) : CommonSchemaV1.LinearState(uuid = uid.id, externalId = uid.externalId, participants = participants)
|
||||||
}
|
}
|
||||||
|
@ -49,7 +49,7 @@ class DummyLinearContract : Contract {
|
|||||||
linearBoolean = linearBoolean
|
linearBoolean = linearBoolean
|
||||||
)
|
)
|
||||||
is DummyLinearStateSchemaV2 -> DummyLinearStateSchemaV2.PersistentDummyLinearState(
|
is DummyLinearStateSchemaV2 -> DummyLinearStateSchemaV2.PersistentDummyLinearState(
|
||||||
_participants = participants.toSet(),
|
participants = participants.toMutableSet(),
|
||||||
uid = linearId,
|
uid = linearId,
|
||||||
linearString = linearString,
|
linearString = linearString,
|
||||||
linearNumber = linearNumber,
|
linearNumber = linearNumber,
|
||||||
|
@ -4,6 +4,7 @@ import net.corda.core.contracts.ContractState
|
|||||||
import net.corda.core.identity.AbstractParty
|
import net.corda.core.identity.AbstractParty
|
||||||
import net.corda.core.schemas.MappedSchema
|
import net.corda.core.schemas.MappedSchema
|
||||||
import net.corda.core.schemas.PersistentState
|
import net.corda.core.schemas.PersistentState
|
||||||
|
import org.hibernate.annotations.Type
|
||||||
import java.time.Instant
|
import java.time.Instant
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import javax.persistence.*
|
import javax.persistence.*
|
||||||
@ -36,6 +37,7 @@ object DummyLinearStateSchemaV1 : MappedSchema(schemaFamily = DummyLinearStateSc
|
|||||||
var externalId: String?,
|
var externalId: String?,
|
||||||
|
|
||||||
@Column(name = "uuid", nullable = false)
|
@Column(name = "uuid", nullable = false)
|
||||||
|
@Type(type = "uuid-char")
|
||||||
var uuid: UUID,
|
var uuid: UUID,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -4,9 +4,7 @@ import net.corda.core.contracts.UniqueIdentifier
|
|||||||
import net.corda.core.identity.AbstractParty
|
import net.corda.core.identity.AbstractParty
|
||||||
import net.corda.core.schemas.CommonSchemaV1
|
import net.corda.core.schemas.CommonSchemaV1
|
||||||
import net.corda.core.schemas.MappedSchema
|
import net.corda.core.schemas.MappedSchema
|
||||||
import javax.persistence.Column
|
import javax.persistence.*
|
||||||
import javax.persistence.Entity
|
|
||||||
import javax.persistence.Table
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Second version of a cash contract ORM schema that extends the common
|
* Second version of a cash contract ORM schema that extends the common
|
||||||
@ -17,6 +15,14 @@ object DummyLinearStateSchemaV2 : MappedSchema(schemaFamily = DummyLinearStateSc
|
|||||||
@Entity
|
@Entity
|
||||||
@Table(name = "dummy_linear_states_v2")
|
@Table(name = "dummy_linear_states_v2")
|
||||||
class PersistentDummyLinearState(
|
class PersistentDummyLinearState(
|
||||||
|
|
||||||
|
@ElementCollection
|
||||||
|
@Column(name = "participants")
|
||||||
|
@CollectionTable(name = "dummy_linear_states_v2_participants", joinColumns = arrayOf(
|
||||||
|
JoinColumn(name = "output_index", referencedColumnName = "output_index"),
|
||||||
|
JoinColumn(name = "transaction_id", referencedColumnName = "transaction_id")))
|
||||||
|
override var participants: MutableSet<AbstractParty>? = null,
|
||||||
|
|
||||||
@Column(name = "linear_string") var linearString: String,
|
@Column(name = "linear_string") var linearString: String,
|
||||||
|
|
||||||
@Column(name = "linear_number") var linearNumber: Long,
|
@Column(name = "linear_number") var linearNumber: Long,
|
||||||
@ -25,11 +31,7 @@ object DummyLinearStateSchemaV2 : MappedSchema(schemaFamily = DummyLinearStateSc
|
|||||||
|
|
||||||
@Column(name = "linear_boolean") var linearBoolean: Boolean,
|
@Column(name = "linear_boolean") var linearBoolean: Boolean,
|
||||||
|
|
||||||
/** parent attributes */
|
|
||||||
@Transient
|
|
||||||
val _participants: Set<AbstractParty>,
|
|
||||||
|
|
||||||
@Transient
|
@Transient
|
||||||
val uid: UniqueIdentifier
|
val uid: UniqueIdentifier
|
||||||
) : CommonSchemaV1.LinearState(uid, _participants)
|
) : CommonSchemaV1.LinearState(uuid = uid.id, externalId = uid.externalId, participants = participants)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user