JPA查询DTYPE [英] JPA query for DTYPE
问题描述
我有一个由两个jpa实体(继承)生成的表。因此,我们在数据库表中生成了一个DTYPE列,其中实体名称具有值。
如何编写jpa查询以获取任何给定实体的数据。即DTYPE ='A'?
我刚刚在jpa查询中尝试过使用DTYPE,但正如我所料,我收到了一个错误无法解析属性。请让我知道如何编写这个查询。
注意 - 我不想使用本机查询。
更新:
我有A类和AA类,它扩展了A. DTYPE有两个值A和AA。
当我查询A时,我得到所有A加AA实体。如何在查询A时排除AA?
只需在父类中添加一个简单字段dtype。
@ polumn(insertable = false,updatable = false)
private String dtype;
所以,你可以在您的JPQL查询中使用它
I have a single table which is generated from two jpa entities (inheritance). So we have a DTYPE column generated in the database table which has entity name has values.
How do I write a jpa query to fetch data for any given entity. i.e DTYPE = 'A'?
I just tried using DTYPE in jpa query but as expected I got an error "Could not resolve property". Please let me know how to write this query.
Note - I dont want to use native query.
Update:
I have class A and subclass AA which extends A. DTYPE has two values A and AA.
When I query for A, I get all the A plus AA entities. How to exclude AA when I query for A?
Simply add a simple field dtype in your parent class.
@Column(insertable = false, updatable = false) private String dtype;
And so, you can use it in your JPQL query
这篇关于JPA查询DTYPE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!