我的存储库中有一个简单的查询,在给定post对象的情况下增加帖子的注释数量:
public interface PostsRepository extends PagingAndSortingRepository<Post, Long>{
//...
@Modifying
@Query("UPDATE Post p set p.numComments = p.numComments + 1 where p = :post")
void incrementNumComments(@Param("post") post obj);
//...
}
型号:
@Entity
@Table(name="posts")
@Inheritance(strategy= InheritanceType.JOINED)
public class Post {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "post_id", updatable = false, nullable = false)
@Access(AccessType.PROPERTY)
private Long id;
}
但是,hibernate似乎使用临时表来执行查询。以下是日志中生成的查询:
Hibernate: insert into HT_posts select pos0_.post_id as post_id from posts pos0_ where pos0_.s_id=?
Hibernate: update posts set num_comments=num_comments+1 where (post_id) IN (select post_id from HT_posts)
有没有办法阻止Hibernate为此查询使用临时表?
由于
答案 0 :(得分:3)
您可以找到有关Multitable bulk operations的详细信息。
正如@Giovanni所提到的,这是因为使用了InheritanceType.JOINED
。