在LinearState状态下查询嵌套集合 [英] Querying nested collections in LinearState states

查看:56
本文介绍了在LinearState状态下查询嵌套集合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们是否有用于嵌套在状态内的可查询持久性集合的模式?

Do we have a pattern for queryable persistent collections nested within a state?

class ALinearState(val items: List<Item>) : LinearState 
data class Item(name: String, ...)

给定的 ALinearState alpha ,我们希望为同一 UniqueIdentifier 。每个版本都有一组离散的。我们希望能够在表中查询与过滤器匹配的,然后恢复 alpha 的设置状态匹配筛选出的

For a given ALinearState, alpha we wish to store versions for the same UniqueIdentifier. Each version will have a discrete set of items. We want to be able to query a table for items that match a filter, then recover the set states of alpha that match the filtered items.

是否有实现此目标的方法?
谢谢。

Is there a way of achieving this? Thanks.

推荐答案

您可以使用任何形式的JPA /休眠模型定义来代表您的合同国。例如:

You can represent you Contract States using any form of JPA/Hibernate model definition. For example:

object TestSchema : MappedSchema(SchemaFamily::class.java, 1, setOf(Parent::class.java, Child::class.java)) {
    @Entity
    @Table(name = "Parents")
    class Parent : PersistentState() {
        @OneToMany(fetch = FetchType.LAZY)
        @JoinColumns(JoinColumn(name = "transaction_id", referencedColumnName = "transaction_id"), JoinColumn(name = "output_index", referencedColumnName = "output_index"))
        @OrderColumn
        @Cascade(CascadeType.PERSIST)
        var children: MutableSet<Child> = mutableSetOf()
    }

    @Entity
    @Table(name = "Children")
    class Child {
        @Id
        @GeneratedValue
        @Column(name = "child_id", unique = true, nullable = false)
        var childId: Int? = null

        @ManyToOne(fetch = FetchType.LAZY)
        @JoinColumns(JoinColumn(name = "transaction_id", referencedColumnName = "transaction_id"), JoinColumn(name = "output_index", referencedColumnName = "output_index"))
        var parent: Parent? = null
    }
}

在后续查询中,可能最好使用JDBC查询执行您可能拥有的任何自定义查询(使用标准JDBC或Hibernate)。

In terms of subsequent query, it would probably be best to use a JDBC query to execute any custom queries you may have (using standard JDBC or Hibernate).

这篇关于在LinearState状态下查询嵌套集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆