我在我的存储库中有一个简单的查询,用于根据帖子对象增加评论数量:
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在此查询中使用临时表?
谢谢。
@Inheritance(strategy= InheritanceType.JOINED)
。 - Giovanni