|
|
|
|
|
|
1
|
# spring-boot-jpa
|
1
|
# spring-boot-jpa
|
|
2
|
|
2
|
|
|
3
|
-spring boot 2
|
|
|
|
4
|
-JPA相关的代码
|
|
|
|
5
|
-
|
|
|
|
6
|
-结果
|
|
|
|
7
|
-1. insert 无主键
|
|
|
|
8
|
-{"ex":{"exClass":"org.springframework.orm.jpa.JpaSystemException","message":"ids for this class must be manually assigned before calling save(): ltass.staudy.spring.data.jpa.entity.User; nested exception is org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before calling save(): ltass.staudy.spring.data.jpa.entity.User"},"exCause":{"causeBy":"org.hibernate.id.IdentifierGenerationException","message":"ids for this class must be manually assigned before calling save(): ltass.staudy.spring.data.jpa.entity.User"}}
|
|
|
|
9
|
-
|
|
|
|
10
|
-2. insert 非空字段未设定
|
|
|
|
11
|
-{"ex":{"exClass":"org.springframework.dao.DataIntegrityViolationException","message":"could not execute statement; SQL [n/a]; constraint [null]; nested exception is org.hibernate.exception.ConstraintViolationException: could not execute statement"},"exCause":{"causeBy":"org.hibernate.exception.ConstraintViolationException","message":"could not execute statement"}}
|
|
|
|
12
|
-
|
|
|
|
13
|
-3. insert 字段长度越界
|
|
|
|
14
|
-{"ex":{"exClass":"org.springframework.dao.DataIntegrityViolationException","message":"could not execute statement; SQL [n/a]; nested exception is org.hibernate.exception.DataException: could not execute statement"},"exCause":{"causeBy":"org.hibernate.exception.DataException","message":"could not execute statement"}}
|
|
|
|
15
|
-
|
|
|
|
16
|
-4.insert 主键冲突
|
|
|
|
17
|
-{"ex":{"exClass":"org.springframework.dao.DataIntegrityViolationException","message":"could not execute statement; SQL [n/a]; constraint [PRIMARY]; nested exception is org.hibernate.exception.ConstraintViolationException: could not execute statement"},"exCause":{"causeBy":"org.hibernate.exception.ConstraintViolationException","message":"could not execute statement"}}
|
|
|
|
18
|
-
|
|
|
|
19
|
-5.insert 唯一索引冲突
|
|
|
|
20
|
-{"ex":{"exClass":"org.springframework.dao.DataIntegrityViolationException","message":"could not execute statement; SQL [n/a]; constraint [PRIMARY]; nested exception is org.hibernate.exception.ConstraintViolationException: could not execute statement"},"exCause":{"causeBy":"org.hibernate.exception.ConstraintViolationException","message":"could not execute statement"}}
|
|
|
|
21
|
-
|
|
|
|
22
|
-6. update 无主键
|
|
|
|
23
|
-{"ex":{"exClass":"org.springframework.orm.jpa.JpaSystemException","message":"ids for this class must be manually assigned before calling save(): ltass.staudy.spring.data.jpa.entity.User; nested exception is org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before calling save(): ltass.staudy.spring.data.jpa.entity.User"},"exCause":{"causeBy":"org.hibernate.id.IdentifierGenerationException","message":"ids for this class must be manually assigned before calling save(): ltass.staudy.spring.data.jpa.entity.User"}}
|
|
|
|
24
|
-
|
|
|
|
25
|
-7 update 非空字段未设定
|
|
|
|
26
|
-{"ex":{"exClass":"org.springframework.dao.DataIntegrityViolationException","message":"could not execute statement; SQL [n/a]; constraint [null]; nested exception is org.hibernate.exception.ConstraintViolationException: could not execute statement"},"exCause":{"causeBy":"org.hibernate.exception.ConstraintViolationException","message":"could not execute statement"}}
|
|
|
|
27
|
-
|
|
|
|
28
|
-8. update 字段长度越界
|
|
|
|
29
|
-"ex":{"exClass":"org.springframework.dao.DataIntegrityViolationException","message":"could not execute statement; SQL [n/a]; nested exception is org.hibernate.exception.DataException: could not execute statement"},"exCause":{"causeBy":"org.hibernate.exception.DataException","message":"could not execute statement"}}
|
|
|
|
30
|
-
|
|
|
|
31
|
-9. update 乐观锁冲突 即 Version冲突
|
|
|
|
32
|
-{"ex":{"exClass":"org.springframework.orm.ObjectOptimisticLockingFailureException","message":"Object of class [ltass.staudy.spring.data.jpa.entity.User] with identifier [1]: optimistic locking failed; nested exception is org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect) : [ltass.staudy.spring.data.jpa.entity.User#1]"},"exCause":{"causeBy":"org.hibernate.StaleObjectStateException","message":"Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect) : [ltass.staudy.spring.data.jpa.entity.User#1]"}}
|
|
|
|
33
|
-
|
|
|
|
34
|
-10. update 唯一索引冲突
|
|
|
|
35
|
-{"ex":{"exClass":"org.springframework.dao.DataIntegrityViolationException","message":"could not execute statement; SQL [n/a]; constraint [PRIMARY]; nested exception is org.hibernate.exception.ConstraintViolationException: could not execute statement"},"exCause":{"causeBy":"org.hibernate.exception.ConstraintViolationException","message":"could not execute statement"}}
|
|
|
|
|
|
3
|
+spring boot 2
|
|
|
|
4
|
+JPA相关的代码
|
|
|
|
5
|
+
|
|
|
|
6
|
+结果
|
|
|
|
7
|
+#1. insert 无主键
|
|
|
|
8
|
+{"ex":{"exClass":"org.springframework.orm.jpa.JpaSystemException","message":"ids for this class must be manually assigned before calling save(): ltass.staudy.spring.data.jpa.entity.User; nested exception is org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before calling save(): ltass.staudy.spring.data.jpa.entity.User"},"exCause":{"causeBy":"org.hibernate.id.IdentifierGenerationException","message":"ids for this class must be manually assigned before calling save(): ltass.staudy.spring.data.jpa.entity.User"}}
|
|
|
|
9
|
+
|
|
|
|
10
|
+#2. insert 非空字段未设定
|
|
|
|
11
|
+{"ex":{"exClass":"org.springframework.dao.DataIntegrityViolationException","message":"could not execute statement; SQL [n/a]; constraint [null]; nested exception is org.hibernate.exception.ConstraintViolationException: could not execute statement"},"exCause":{"causeBy":"org.hibernate.exception.ConstraintViolationException","message":"could not execute statement"}}
|
|
|
|
12
|
+
|
|
|
|
13
|
+#3. insert 字段长度越界
|
|
|
|
14
|
+{"ex":{"exClass":"org.springframework.dao.DataIntegrityViolationException","message":"could not execute statement; SQL [n/a]; nested exception is org.hibernate.exception.DataException: could not execute statement"},"exCause":{"causeBy":"org.hibernate.exception.DataException","message":"could not execute statement"}}
|
|
|
|
15
|
+
|
|
|
|
16
|
+#4.insert 主键冲突
|
|
|
|
17
|
+{"ex":{"exClass":"org.springframework.dao.DataIntegrityViolationException","message":"could not execute statement; SQL [n/a]; constraint [PRIMARY]; nested exception is org.hibernate.exception.ConstraintViolationException: could not execute statement"},"exCause":{"causeBy":"org.hibernate.exception.ConstraintViolationException","message":"could not execute statement"}}
|
|
|
|
18
|
+
|
|
|
|
19
|
+#5.insert 唯一索引冲突
|
|
|
|
20
|
+{"ex":{"exClass":"org.springframework.dao.DataIntegrityViolationException","message":"could not execute statement; SQL [n/a]; constraint [PRIMARY]; nested exception is org.hibernate.exception.ConstraintViolationException: could not execute statement"},"exCause":{"causeBy":"org.hibernate.exception.ConstraintViolationException","message":"could not execute statement"}}
|
|
|
|
21
|
+
|
|
|
|
22
|
+#6. update 无主键
|
|
|
|
23
|
+{"ex":{"exClass":"org.springframework.orm.jpa.JpaSystemException","message":"ids for this class must be manually assigned before calling save(): ltass.staudy.spring.data.jpa.entity.User; nested exception is org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before calling save(): ltass.staudy.spring.data.jpa.entity.User"},"exCause":{"causeBy":"org.hibernate.id.IdentifierGenerationException","message":"ids for this class must be manually assigned before calling save(): ltass.staudy.spring.data.jpa.entity.User"}}
|
|
|
|
24
|
+
|
|
|
|
25
|
+#7 update 非空字段未设定
|
|
|
|
26
|
+{"ex":{"exClass":"org.springframework.dao.DataIntegrityViolationException","message":"could not execute statement; SQL [n/a]; constraint [null]; nested exception is org.hibernate.exception.ConstraintViolationException: could not execute statement"},"exCause":{"causeBy":"org.hibernate.exception.ConstraintViolationException","message":"could not execute statement"}}
|
|
|
|
27
|
+
|
|
|
|
28
|
+#8. update 字段长度越界
|
|
|
|
29
|
+"ex":{"exClass":"org.springframework.dao.DataIntegrityViolationException","message":"could not execute statement; SQL [n/a]; nested exception is org.hibernate.exception.DataException: could not execute statement"},"exCause":{"causeBy":"org.hibernate.exception.DataException","message":"could not execute statement"}}
|
|
|
|
30
|
+
|
|
|
|
31
|
+#9. update 乐观锁冲突 即 Version冲突
|
|
|
|
32
|
+{"ex":{"exClass":"org.springframework.orm.ObjectOptimisticLockingFailureException","message":"Object of class [ltass.staudy.spring.data.jpa.entity.User] with identifier [1]: optimistic locking failed; nested exception is org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect) : [ltass.staudy.spring.data.jpa.entity.User#1]"},"exCause":{"causeBy":"org.hibernate.StaleObjectStateException","message":"Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect) : [ltass.staudy.spring.data.jpa.entity.User#1]"}}
|
|
|
|
33
|
+
|
|
|
|
34
|
+#10. update 唯一索引冲突
|
|
|
|
35
|
+{"ex":{"exClass":"org.springframework.dao.DataIntegrityViolationException","message":"could not execute statement; SQL [n/a]; constraint [PRIMARY]; nested exception is org.hibernate.exception.ConstraintViolationException: could not execute statement"},"exCause":{"causeBy":"org.hibernate.exception.ConstraintViolationException","message":"could not execute statement"}}
|