我正在使用Hibernate @NotAudited
,我想只使用实体中某些集合的详细信息来获取实体的修订版。
但我可以看到为实体中的所有集合触发的hibernate查询导致性能问题。
也无法在集合中使用@ManyToOne
@JoinColumn(name="ADDR_ID")
public Address getAddress() { return address; }
@OneToMany
@JoinColumn(name="CUST_ID")
public Set<Order> getOrders() {return orders;}
注释以避免在此特定查询中,因为在这些集合的其他方案中需要进行审核。
例如,如果我的审核实体将这两个联接作为集合。 但我希望查询获取我的实体的修订版仅获取地址信息并忽略订单信息,是否可能?我不想用@NotAudited注释订单信息,因为在其他情况下可能需要历史信息。
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<select name="cat">
<option value="0">choose category</option>
<option value="1">Cat 1</option>
<option value="2">Cat 2</option>
</select>
<select name="subcat" style="display:none">
</select>
答案 0 :(得分:0)
与this Hibernate documentation example一样,如果我的Customer
与Address
关联:
@Audited( withModifiedFlag = true )
@Entity(name = "Customer")
public class Customer {
...
@ManyToOne(fetch = FetchType.LAZY)
private Address address;
}
我使用this query查询修订版:
List<Customer> customers = AuditReaderFactory
.get( entityManager )
.createQuery()
.forRevisionsOfEntity( Customer.class, false, true )
.add( AuditEntity.id().eq( 1L ) )
.add( AuditEntity.property( "lastName" ).hasChanged() )
.getResultList();
仅包含Customers
的查询,而不是Address
:
select
c.id as id1_3_0_,
c.REV as REV2_3_0_,
defaultrev1_.REV as REV1_4_1_,
c.REVTYPE as REVTYPE3_3_0_,
c.REVEND as REVEND4_3_0_,
c.created_on as created_5_3_0_,
c.createdOn_MOD as createdO6_3_0_,
c.firstName as firstNam7_3_0_,
c.firstName_MOD as firstNam8_3_0_,
c.lastName as lastName9_3_0_,
c.lastName_MOD as lastNam10_3_0_,
c.address_id as address11_3_0_,
c.address_MOD as address12_3_0_,
defaultrev1_.REVTSTMP as REVTSTMP2_4_1_
from
Customer_AUD c cross
join
REVINFO defaultrev1_
where
c.id = ?
and c.lastName_MOD = ?
and c.REV=defaultrev1_.REV
order by
c.REV asc
-- binding parameter [1] as [BIGINT] - [1]
-- binding parameter [2] as [BOOLEAN] - [true]
你是否经历过这样的关系:
AuditQuery innerJoinAuditQuery = AuditReaderFactory
.get( entityManager )
.createQuery()
.forEntitiesAtRevision( Customer.class, 1 )
.traverseRelation( "address", JoinType.INNER );
或者,您是如何最终加入所有协会的?