admin管理员组文章数量:1122832
I am trying to define @Filter on Entity
,and it's not working on my test code
This is my entity:
@Entity
@FilterDef(
name = "tenantFilter",
parameters = [ParamDef(name = "tenantId", type = "string")],
)
@Filters(
value = [
Filter(name = "tenantFilter", condition = "tenant_id = :tenantId")
]
)
class DemoEntity {
lateinit var tenantId: String
}
This is my test code:
var demoEntity = DemoEntity()
demoEntity.id = "1"
demoEntity.tenantId = "tenant1"
demoRepository.save(demoEntity)
demoEntity = DemoEntity()
demoEntity.id = "2"
demoEntity.tenantId = "tenant2"
demoRepository.save(demoEntity)
val session = entityManager.unwrap(Session::class.java)
val enableFilter = session.enableFilter("tenantFilter")
enableFilter.setParameter("tenantId", "tenant1")
val query = entityManager.createQuery("from DemoEntity ").resultList
session.disableFilter("tenantFilter")
println(query)
Ouput:
[DemoEntity(id='1', tenantId='tenant1', createdAt=2024-11-22T11:35:24.902234, updatedAt=2024-11-22T11:35:24.902234), DemoEntity(id='2', tenantId='tenant2', createdAt=2024-11-22T11:35:24.959239, updatedAt=2024-11-22T11:35:24.959239)]
本文标签: javaHibernate Filter Not Working as ExpectedStack Overflow
版权声明:本文标题:java - Hibernate @Filter Not Working as Expected - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736305762a1932704.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论