babyfish-ct / jimmer

A revolutionary ORM framework for both java and kotlin.
Apache License 2.0
876 stars 88 forks source link

KAssociationIntegrityAssuranceFilter 不检查关联属性为null的情况 #661

Closed zhengchalei closed 2 months ago

zhengchalei commented 2 months ago

@MappedSuperclass
interface TenantAware {
    val tenantId: Int
}

@Component
class TenantFilter : KAssociationIntegrityAssuranceFilter<TenantAware> {

    override fun filter(args: KFilterArgs<TenantAware>) {
        1?.let {
            args.apply {
                where(table.tenantId.eq(it))
            }
        }
    }
}

@Entity
@Table(name = "book")
interface Book : TenantAware {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    val id: Int

    val name: String

    @ManyToOne
    @JoinColumn(name = "author_id")
    val author: Author
}

@Entity
@Table(name = "author")
interface Author : TenantAware {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    val id: Int

    val name: String
}

Cannot apply filter "ExportedFilter{filters=[JavaFilter(kotlinFilter=com.zhengchalei.jimmerdemo.TenantFilter@26994c6a)]}" for "com.zhengchalei.jimmerdemo.Book.author" because that property is not nullable org.babyfish.jimmer.sql.runtime.ExecutionException: Cannot apply filter "ExportedFilter{filters=[JavaFilter(kotlinFilter=com.zhengchalei.jimmerdemo.TenantFilter@26994c6a)]}" for "com.zhengchalei.jimmerdemo.Book.author" because that property is not nullable

从 AssociationIntegrityAssuranceFilter/KAssociationIntegrityAssuranceFilter允许用户对数据库的数据特色做出承诺,以打破这种限制。 这个结果是不是不符合预期

zhengchalei commented 2 months ago

复现 https://github.com/zhengchalei/jimmer-issues-661