【发布时间】:2012-04-01 18:44:25
【问题描述】:
我一直在通过不同的论坛搜索信息,并尝试了不同的解决方案,但我仍然无法纠正我的问题。
我正在使用 hibernate4 注释来映射我的实体。在mysql中使用hibernate创建表时,未检测到自动增量键。
我有以下代码:
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(unique = true, nullable = false)
private int responseId;
我也试过了:
@Id
@GenericGenerator(name="generator", strategy="increment")
@GeneratedValue(generator="generator")
private int responseId;
使用 hibernate id 会自动分配给一行,但在 mysql 表中它没有 AutoIncrement 约束。我必须手动将字段标记为 AI。当我手动插入记录以进行测试或对表使用 jdbc 语句时,这会出现问题。请让我知道我在阻止休眠 id 分配 AutoIncrement Contraint 的配置中缺少什么。
【问题讨论】:
-
如何让注释创建表格?我们通常采取相反的方式
-
我们创建类和关系,然后通过将休眠属性 hibernate.hbm2ddl.auto 设置为“更新”生成表。
标签: mysql hibernate auto-increment hibernate-annotations