惟愿此间无白头 2020-04-19 22:49 采纳率: 0%
浏览 185

JPA 主键生成策略为 Table 时,初始主键值为什么不是预期的值?

各位大佬帮帮小弟吧。求求了!!!

@Id
@GeneratedValue(strategy = GenerationType.TABLE, generator = "ID_GENERATOR")
@TableGenerator(name = "ID_GENERATOR", table = "jpa_id_generators", pkColumnName = "PK_NAME", pkColumnValue = "CUSTOMER_ID", valueColumnName = "PK_VALUE")
public Integer getId() {
    return id;
}

图片说明

Customer customer = new Customer();
customer.setAge(19);
customer.setEmail("tc@qq.com");
customer.setLastName("tc");
customer.setCreatedTime(new Date());
customer.setBirth(new Date());
entityManager.persist(customer);

按理来说,allocationSize 默认为 50,initialValue 默认为 0,不写的话 id 就是从 50 开始。实际上是从 -47 开始。allocationSize 我赋值为 100,id 就从 -97开始,这是怎么回事?
图片说明

这是配置文件:

<persistence-unit name="jpa-1" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<!-- 添加持久化类 -->
<class>jpa.helloworld.Customer</class>
    <properties>
        <property name="hibernate.connection.url" value="jdbc:mysql:///jpa?serverTimezone=UTC"/>
            <property name="hibernate.connection.driver_class" value="com.mysql.cj.jdbc.Driver"/>
            <property name="hibernate.connection.username" value="root"/>
            <property name="hibernate.connection.password" value="1024"/>
            <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect"/>
            <property name="hibernate.show_sql" value="true"/>
            <property name="hibernate.format_sql" value="true"/>
            <property name="hibernate.hbm2ddl.auto" value="update"/>
    </properties>
</persistence-unit>
  • 写回答

1条回答 默认 最新

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥15 easyclick重启app
      • ¥15 Python求质数问题
      • ¥15 ros系统里Python版本问题
      • ¥15 不兼容驱动程序删不了,内核隔离打不开
      • ¥15 Centos7重启网卡自动down,只能手动up
      • ¥15 multisim用74ls148做一个5号病号呼叫系统
      • ¥15 单片机,传感器,LCD1602
      • ¥15 关于adams 批处理仿真时间太长的问题
      • ¥15 fate部署问题请求帮助
      • ¥15 关于#arcpy#的问题:arcpy栅格计算器批处理(语言-python)