Hibernate Envers-如何使用查询注释并传递sql脚本在CrudRepository上审计插入操作

问题描述

嗨,我正在与Envers合作来审核某人的实体操作并且工作正常,但是在一种情况下,我确定如何继续使其工作并审核某些操作(其中@Query提供了sql)注释,所以这是这种情况的示例:

CrudRepository:

@RepositoryRestResource
public interface BucketContentReferenceRepository extends CrudRepository<BucketContentReference,Long> {
  

  @Modifying
  @Transactional
  @Query(value =
      "INSERT INTO bucket_content_references "
          + "(bucket_id,content_reference_id,position) "
          + "VALUES (?1,?2,IFNULL((SELECT MAX(position) + 1 FROM (SELECT position,bucket_id FROM bucket_content_references) ibcr WHERE ibcr.bucket_id = ?1),1))",nativeQuery = true)
  int addBucketContentReferenceIdToEnd(
      @Param("bucketId") final Long bucketId,@Param("contentReferenceId") final Long contentReferenceId);

以及我要审核的实体:

@Getter
@Setter
@ToString(exclude = { "bucket","contentReference","mediaId","airingId" })
@Entity
@Table(name = "bucket_content_references")
@Audited
@AuditTable("bucket_content_references_audit")
@JsonInclude(Include.NON_NULL)
public class BucketContentReference implements Serializable,Comparable<BucketContentReference>,PositionableEntity {
  private static final long serialVersionUID = 1L;

  @Id
  @GeneratedValue
  private Long id;

  @ManyToOne
  @JoinColumn(name = "bucketId")
  private Bucket bucket;

  @ManyToOne
  @JoinColumn(name = "contentReferenceId")
  private ContentReference contentReference;

  @Column
  private String mediaId;

  @Column
  private String airingId;

  @Column(nullable = false)
  private Integer position;

  @Tolerate
  protected BucketContentReference() {
    super();
  }

  public BucketContentReference(Bucket bucket,ContentReference contentReference,Integer position) {
    super();
    this.bucket = bucket;
    this.contentReference = contentReference;
    this.position = position;
  }

  public boolean hasMediaId() {
      return this.mediaId != null;
  }

  public boolean hasAiringId() {
      return this.airingId != null;
  }

  @Override
  public int compareto(BucketContentReference bucketContentReference) {
    return position.compareto(bucketContentReference.position);
  }
}

感谢您的帮助!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...