
Spring Data JPA
-小末
这个作者很懒,什么都没留下…
展开
-
JPA插入枚举类型字段
JPA插入枚举类型字段,有三种方式:例如,我们有个枚举类:public enum Gender { BOY("1" , "boy" , "Boy"); GIRL("2" , "boy" , "Boy"); private int value; private String s1; private String s2; //....省略}1. 插入枚举名称的值,即字符串将BOY或GIRL存入表中,实体类字段如下:public .原创 2020-06-17 12:33:36 · 7345 阅读 · 1 评论 -
Multiple representations of the same entity 原因之一
项目中利用SpringDataJPA技术进行新增实体时,产生Multiple representations of the same entity异常。这个异常原因有很多,但在我这里就是就是当我循环save实体时,实体没有指定主键策略,两个实体的id相同了,就报这个错误了。记录一下。。。...原创 2020-06-08 17:12:03 · 2457 阅读 · 0 评论 -
JPA问题 : Field id doesnt have a default value
一、问题描述修改实体主键的设置方式为int自增模式,也就是@Id@GeneratedValue(strategy=GenerationType.IDENTITY)private int id;本以为直接用repository.save,直接万事大吉,结果报错:Field 'id' doesn't have a default value二、解决办法查了很多资料,有的说表结构没有勾选自增选项云云,但我这是jpa自动建表啊,也不用我手动去搞表结构。后来发现我把表结构删了重新执原创 2020-06-08 17:04:11 · 4261 阅读 · 1 评论 -
Spring Data JPA模糊查询加分页
接口如下://你的repository继承JpaRepository,利用Containing关键字Page<User> findByUsernameContainingOrderByCreateTimeDesc(String username,Pageable pageable);调用://查询第1页2条名字含有“丽”的用户,并按创建时间倒序排列,模糊查询Cont...原创 2019-04-24 15:21:17 · 3456 阅读 · 3 评论 -
Spring Data JPA方法关键字规则
关键词 样例 JPQL代码段 And findByLastnameAndFirstname … where x.lastname = ?1 and x.firstname = ?2 Or findByLastnameOrFirstname … where x.lastname = ?1 or x.firstname = ?2 Is,Equals ...原创 2019-04-24 17:09:33 · 1859 阅读 · 0 评论 -
SpringDataJPA排序sort问题
通常我们写分页涉及到排序问题,一般我们直接在Controller参数设置Pageable进行处理:@PageableDefault(page = 0, size = 10, sort = "create_time") Pageable pageable关键在于sort参数对查询出来的集合进行排序,sort参数对应的是实体里的字段,一般我们的实体字段都是驼峰结构。然后发现个有趣的bug...原创 2019-07-23 09:49:15 · 1269 阅读 · 1 评论