我正在尝试选择我的每个trackedResource实体的最新修订版,其中position_source_feed_id具有特殊的价值。
我有一个功能性的PostgreSQL查询:
select tr0.*
from
trackedresource_aud tr0
where
tr0.position_source_feed_id='7870b8b9-4b98-4ea7-8fb8-99746d7f0e85'
and
tr0.rev=(
select
max(tr1.rev)
from
trackedresource_aud tr1
where
tr1.id=tr0.id
and
tr1.position_source_feed_id=tr0.position_source_feed_id
)
order by
tr0.rev desc
;但我似乎无法得到一个匹配的AuditQuery。
当我尝试上面的createNativeQuery时,我得到:
javax.persistence.PersistenceException: org.hibernate.MappingException: No Dialect mapping for JDBC type: 1111可能是因为实体上有几个UUID字段,包括position_source_feed_id
发布于 2019-08-07 20:56:05
我希望下面的查询能够工作:
AuditReader reader = AuditReaderFactory.get( session );
YourEntity lastRevision = reader.createQuery()
.forRevisionsOfEntity( YourEntity.class, true, false )
.add( AuditEntity.property( "position_source_feed_id" ).eq( feedId ) )
.addOrder( AuditEntity.revisionNumber().desc() )
.setMaxResults( 1 )
.getSingleResult();对于YourEntity的所有修订,查询的工作方式只对返回实际实体本身(不包括删除)的查询感兴趣,其中position_source_feed_id等于提供的值。结果集然后被限制在最高的修订数,并被返回。
https://stackoverflow.com/questions/57365833
复制相似问题