jack_zhang

Results 70 comments of jack_zhang

``` Customer customer = new Customer(); customer.setName("Jack"); customer.setAddress("上海"); //创建匹配器,即如何使用查询条件 ExampleMatcher matcher = ExampleMatcher.matching() //构建对象 .withMatcher("name", GenericPropertyMatchers.startsWith()) //姓名采用“开始匹配”的方式查询 .withIgnorePaths("focus"); //忽略属性:是否关注。因为是基本类型,需要忽略掉 //创建实例 Example ex = Example.of(customer, matcher); //查询 List ls = dao.findAll(ex);...

解决办法是把 `// @EntityGraph(attributePaths = {"thirdPartyTpusers","teacher","parent"}, type = EntityGraph.EntityGraphType.LOAD) 这个注解注释掉之后就会产生N+1的sql问题`注释去掉变成如下: ```` public interface TpuserRepository extends GenericUserRepository { @EntityGraph(attributePaths = {"thirdPartyTpusers","teacher","parent"}, type = EntityGraph.EntityGraphType.LOAD) List findAllByIdIn(Iterable ids); } ```` 我们再执行上面的测试用例,而打印的SQL就会变成一个SQL,如下: ```` 2021-09-17...

不过建议对JPA不熟悉的,建议实体上都不要用关联关系。用mysql的思路解决问题即可;

![image](https://user-images.githubusercontent.com/11462004/90979462-c82d9e80-e587-11ea-93b8-ddf5075a2d1f.png) ![image](https://user-images.githubusercontent.com/11462004/90979471-d4196080-e587-11ea-927e-a7a54299dee7.png)

![image](https://user-images.githubusercontent.com/11462004/90979556-6ae61d00-e588-11ea-8327-bbeca47c5f82.png) 一:如果实例里面没有如下标示的@version字段,那么如果ID为空,直接insert,如果ID有值,jpa会发起select查询看看这个id对应的记录是否存在,如果存在update,如果不存在insert; ```` @Version private Long version; ```` 二:如果实例有上的@Version字段 version和ID都要有值才会才发发起select查询对象是否数据库里面的有,如果有update,如果没有insert; 总结: 1. 当ID和Version字段都有值的情况下才会认为可能是新对象;当save的时候,每次都会执行两条sql。 2. 如果ID活着Version字段没有值,直接insert;

不知道的情况下:`spring.jpa.show-sql=true`自己观察

see: https://github.com/zhangzhenhuajack/spring-data-jpa-guide/wiki/SpringDataJpa%E4%B9%8BHibernate5.0%E7%9A%84Entity%E5%88%A4%E6%96%ADDirty%E7%9A%84%E8%BF%87%E7%A8%8B

这个有点高端,贴点例子,感觉就是正常的属性操作呀?和普通的应该没什么区别

@shaopro 怎么处理的?贴个例子学习下