jack_zhang

Results 70 comments of jack_zhang

发现书中第289页有个笔误?倒数第7行 return builder.dataSource(db2DataSouce) 中db2应改为db1 ![image](https://user-images.githubusercontent.com/11462004/186061958-61f62a34-4aa7-4842-8bc8-052f45db3aa7.png)

@shaopro 目前了解到JPA只能mapping视图,不能创建view,数据库的视图在JPA里面是read only的

有反应图片没了,可以看: http://www.jackzhang.cn/spring-data-jpa-guide/SpringDataJpa%E9%AB%98%E7%BA%A7%E7%94%A8%E6%B3%95%E8%A1%A5%E5%85%85/SpringDataJpa%E4%B9%8BHibernate5.0%E7%9A%84Entity%E5%88%A4%E6%96%ADDirty%E7%9A%84%E8%BF%87%E7%A8%8B.html

是在 user.setName("age"),之前设置 sleep 发现的吗?你怎么看到 `执行 count 查询的时候也会触发 AutoFlush 方法`这个现象的?

从sql日志上,来看,你怎么确定的不是事务执行完(事务 commit 之前)执行的autoFlush,而是你执行了count语句之后执行的autoFlush ?

![image](https://user-images.githubusercontent.com/11462004/92544239-00b7c280-f280-11ea-842b-57e2330e7d86.png) 经过测试是完全可以的,需要注意的是 @Query返回的可以直接用接口,如果用class **Dto的话需要配合 spel表达式,另外DTO有很多局限性,就是对DTO的构造方法有要求最好只有一个

DTO的话需要注意构造方法: ![image](https://user-images.githubusercontent.com/11462004/92544353-4d9b9900-f280-11ea-911d-84b94195e06a.png)

上面只是一种简便方法,创建三个实体,中间表分别用两个ManyToOne

https://docs.jboss.org/hibernate/orm/5.2/userguide/html_single/Hibernate_User_Guide.html#associations-one-to-one

```` @Entity(name = "Person") public static class Person implements Serializable { @Id @GeneratedValue private Long id; @NaturalId private String registrationNumber; @OneToMany(mappedBy = "person", cascade = CascadeType.ALL, orphanRemoval = true) private...