You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have TestEntity backed by table name TEST as shown below and have enabled spring data envers. The audit table is called TEST_AUD. I am trying to write a custom query to fetch the Revisions based on userId, but couldn't find a way to do it. please could someone help with this?
@Entity
@Table(name = "TEST")
public class TestEntity {
@Id
private long id;
@Column("USER_ID")
private long userId;
}
Thanks
The text was updated successfully, but these errors were encountered:
What is not supported are @Query annotations or query derivation where a query is derived from the method name.
The first doesn't seem to be feasible since there doesn't seem to be a query language for querying revisions.
The second would need someone to come up with reasonable semantics that doesn't interfere with the semantics of the query derivation of the main repository.
I seriously doubt this is worth the effort since the number of ways one might want to query revisions is pretty huge and we would always only be able to support a slim slice via query derivation.
If anybody has a suggestion for reasonable semantics a comment describing it would be most welcome.
A custom implementation might look like this:
public class CustomCountryRepositoryImpl implements CustomCountryRepository {
@Autowired
EntityManager entityManager;
@Override
public List<Country> findByDate(Date revisionDate) {
AuditReader auditReader = AuditReaderFactory.get(entityManager);
Number revision = auditReader.getRevisionNumberForDate(revisionDate);
return auditReader //
.createQuery() //
.forEntitiesAtRevision(Country.class, revision) //
.getResultList();
}
}
The interfaces to go with that would look like:
@Transactional
public interface CustomCountryRepository {
List<Country> findByDate(Date revisionDate);
}
Hi,
I have
TestEntity
backed by table nameTEST
as shown below and have enabled spring data envers. The audit table is calledTEST_AUD
. I am trying to write a custom query to fetch theRevisions
based onuserId
, but couldn't find a way to do it. please could someone help with this?Thanks
The text was updated successfully, but these errors were encountered: