我有一张带有促销 id 注释的表格
@SequenceGenerator(name="GEN_PROMID", sequenceName="SEQ_PROMOTIONID", allocationSize=1)
@Id
@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="GEN_PROMID")
@Column(name="PROMOTIONID")
private Long promotionid;
但是即使将 allocationSize 指定为 1,hibernate 也会不一致地增加数字。以下是数据库中promotionid 的最新降序值
1440
1420
1407
1406
1405
1404
1403
1402
1401
1400
1380
1360
1342
1341
1340
1320
1305
我在某处读到 Hibernate 可能会使用 hilo seq_hilo 算法和org.hibernate.id.SequenceHiLoGenerator
生成器,即使@SequenceGenerator
已定义。另请阅读以下链接,我们可以使用它@GenericGenerator
来解决链接中的此问题
- http://lists.jboss.org/pipermail/hibernate-issues/2009-March/014663.html
- https://hibernate.atlassian.net/browse/ANN-354
有人可以在这种情况下提供详细信息吗?@GenericGenerator
语法看起来并不简单。应@SequenceGenerator
否使用。有时@SequenceGenerator
可以完美运行并生成正确的主键。
PS。我正在使用 Hibernate 3.5 和 Oracle 11g DB
编辑
序列码 -
CREATE SEQUENCE SEQ_PROMOTIONID
INCREMENT BY 1
START WITH 100;
编辑 2
更多分析表明,“总是”插入至少一个可被 20 整除的值。由于 Oracle 的序列默认缓存为 20,因此在正常的 hibernate 增量和缓存值之间看起来有些冲突。还观察到,当插入之间有时间间隔时,它会转到下一个可被 20 整除的值,否则会适当地增加到 1
1440 12-NOV-14 09.33.09.686000000 AM
1420 07-NOV-14 07.21.41.238000000 AM
1407 03-NOV-14 11.40.41.508000000 AM
1406 03-NOV-14 11.31.37.341000000 AM
1405 03-NOV-14 04.57.53.356000000 AM
1404 03-NOV-14 04.56.39.074000000 AM
1403 03-NOV-14 04.55.17.741000000 AM
1402 03-NOV-14 04.30.59.980000000 AM
1401 03-NOV-14 04.27.14.016000000 AM
1400 03-NOV-14 04.19.23.736000000 AM
1380 27-OCT-14 11.06.33.360000000 AM
1360 17-OCT-14 11.59.15.738000000 AM
1342 15-OCT-14 01.57.50.253000000 PM
1341 15-OCT-14 01.55.39.173000000 PM
1340 14-OCT-14 07.07.14.283000000 AM
1320 10-OCT-14 10.41.04.766000000 AM
1305 07-OCT-14 11.08.10.388000000 AM
1304 07-OCT-14 05.00.50.295000000 AM
1303 07-OCT-14 04.59.01.434000000 AM
1302 06-OCT-14 11.34.43.012000000 AM
1301 06-OCT-14 11.31.18.855000000 AM
1300 06-OCT-14 11.27.16.237000000 AM
1280 04-OCT-14 04.47.40.391000000 AM
1261 01-OCT-14 05.09.06.291000000 PM
1260 01-OCT-14 10.18.41.060000000 AM
1241 22-SEP-14 07.04.45.593000000 AM
1240 22-SEP-14 04.57.25.289000000 AM
1220 19-SEP-14 06.55.31.450000000 AM
1200 16-SEP-14 09.03.04.763000000 AM
1181 10-SEP-14 07.44.04.115000000 AM
1180 08-SEP-14 11.05.30.590000000 AM
1168 04-SEP-14 05.09.46.000000000 AM
1167 02-SEP-14 07.47.52.454000000 AM
1166 02-SEP-14 07.46.52.043000000 AM
1165 02-SEP-14 07.45.38.323000000 AM
1164 02-SEP-14 07.43.27.562000000 AM
1163 02-SEP-14 07.41.11.702000000 AM
1162 02-SEP-14 07.39.27.336000000 AM
1161 02-SEP-14 07.37.35.561000000 AM
1160 02-SEP-14 07.36.12.776000000 AM
1140 28-AUG-14 06.09.08.346000000 AM
1122 25-AUG-14 09.15.51.112000000 AM
1121 25-AUG-14 09.14.30.789000000 AM
1120 25-AUG-14 09.12.54.710000000 AM
1100 20-AUG-14 05.46.08.394000000 AM
1080 14-AUG-14 10.44.54.917000000 AM
1061 09-AUG-14 06.00.43.708000000 AM
1060 07-AUG-14 02.12.24.893000000 PM
1042 04-AUG-14 07.34.57.224000000 AM
1041 04-AUG-14 07.32.16.555000000 AM
1040 04-AUG-14 07.28.34.526000000 AM
1021 01-AUG-14 11.45.22.141000000 AM
1020 31-JUL-14 09.46.17.765000000 AM
1002 23-JUL-14 01.33.45.940000000 AM
1001 22-JUL-14 11.07.54.784000000 AM
1000 21-JUL-14 06.50.43.991000000 AM