Home | 简体中文 | 繁体中文 | 杂文 | Github | 知乎专栏 | Facebook | Linkedin | Youtube | 打赏(Donations) | About
知乎专栏

第 48 章 Spring Data with MySQL

目录

48.1. 选择数据库表引擎
48.2. 声明实体
48.2.1. @Entity 声明实体
48.2.2. @Table 定义表名
48.2.3. @Id 定义主键
48.2.4. @Column 定义字段:
48.2.5. 非数据库字段
48.2.6. @Lob 注解属性将被持久化为 Blog 或 Clob 类型
48.2.7. @NotNull 不能为空声明
48.2.8. @Temporal 日期定义
48.2.9. 创建日期
48.2.10. @DateTimeFormat 处理日期时间格式
48.2.11. Enum 枚举数据类型
48.2.12. SET 数据结构
48.2.13. JSON 数据类型
48.2.14. 嵌入
48.2.15. @JsonIgnore
48.2.16. @EnableJpaAuditing 开启 JPA 审计功能
48.2.17. 注释 @Comment
48.2.18. @Pattern 数据匹配
48.2.19. 实体继承
48.3. 映射集合属性
48.3.1. List 集合
48.3.2. 数组集合
48.3.3. Map 集合
48.3.4. Set 集合
48.3.5. 外键名称
48.3.6. 集合表子查询
48.4. 外键
48.4.1. @JoinColumn
48.4.2. @OneToOne
48.4.3. OneToMany 一对多
48.4.4. ManyToMany 多对多
48.4.5. 外键级联删除
48.4.6. 外键级联操作
48.4.7. @JoinTable
48.4.8. @OrderBy
48.4.9. @JsonIgnoreProperties
48.4.10. 允许外键为 NULL
48.4.11. 只要外键,不要数据结构
48.5. 索引
48.5.1. 普通索引
48.5.2. 组合索引
48.5.3. 唯一索引
48.6. Repository
48.6.1. JpaRepository
48.6.2. CrudRepository
48.6.3. PagingAndSortingRepository
48.6.4. findByXXX
48.6.5. count 操作
48.6.6. delete 删除操作
48.6.7. IsNull
48.6.8. In/NotIn
48.6.9. TRUE / FALSE
48.6.10. Before/After
48.6.11. Exists
48.6.12. OrderBy
48.6.13. GreaterThan
48.6.14. Sort 排序操作操作
48.6.15. Pageable 翻页操作
48.6.16. @DynamicInsert 与 @DynamicUpdate
48.6.17. 继承已存在的 Repository
48.6.18. 自定义返回字段
48.7. TransactionTemplate
48.8. JPQL @Query
48.8.1. @Modifying 更新/删除
48.8.2. 参数传递
48.8.3. 原生 SQL 操作
48.8.4. @Query 与 Pageagble
48.8.5. 返回指定字段
48.8.6. 返回指定的模型
48.8.7. 通过定义接口,返回指定字段
48.8.8. 修改返回数据
48.8.9. 事务 @Transactional
48.8.10. IN / NOT 子查询
48.9. FAQ 常见问题
48.9.1. Could not write JSON: failed to lazily initialize a collection of role
48.9.2. Query did not return a unique result: 2 results were returned
48.9.3. Executing an update/delete query
48.9.4. could not initialize proxy [cn.netkiller.domain.Device#16] - no Session
48.9.5. this is incompatible with sql_mode=only_full_group_by
48.9.6. A TupleBackedMap cannot be modified

48.1. 选择数据库表引擎

正常创建表会使用数据库默认引擎,有时数据库默认引擎并不是我们需要的,通过下面配置可以指定表引擎

			
# Spring boot 1.x.x
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQLInnoDBDialect

# Spring boot 2.0.2
spring.jpa.hibernate.use-new-id-generator-mappings=true
spring.jpa.database-platform=org.hibernate.dialect.MySQL5InnoDBDialect