【发布时间】:2016-11-25 17:00:33
【问题描述】:
我在我的存储库中有一个简单的查询来增加给定帖子对象的帖子的 cmets 数量:
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 我也怀疑过,但如果注释是罪魁祸首,我不确定如何纠正。