@javax.persistence.TableGenerator(
name="my_table_gen",//table生成器本身的名字
table="gen_table",//生成器产生的表的名字
pkColumnName = "pk_key",
//表中的主键的字段名 Name of the primary key column in the table.
valueColumnName = "pk_value",
pkColumnValue="id",运用该生成器的主键字段名
allocationSize=1
)
在mysql 中 key和 value是关键字 所以这里valueColumnName 和PkCoulmnName 不能写成value 和 key 否则程序会报错
@GeneratedValue(strategy=GenerationType.TABLE,generator="my_table_gen")
mysql> select * from gen_table;
+--------+----------+
| pk_key | pk_value |
+--------+----------+
| id | 2 |
+--------+----------+
1 row in set (0.00 sec)
mysql> select * from professor;
+----+------+--------+
| id | name | title |
+----+------+--------+
| 1 | xxd | deputy |
+----+------+--------+
1 row in set (0.00 sec)
阅读(387) | 评论(0) | 转发(0) |