http://www.blogjava.net/ITdavid/archive/2009/02/25/256605.html
注解方式的主键配置
注解方式的主键配置
非自增字段为主键,注解annotation表示
以N_LOG_ID字段为例:
@Id
@Column(name = "N_LOG_ID", unique = true, nullable = false)
自增字段为主键,注解annotation表示
以N_LOG_ID字段为例:
Oracle数据库
@Id
@SequenceGenerator(name = "PK_PACKETLOG", sequenceName = "SEQ_PACKETLOG")
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "PK_PACKETLOG")
@Column(name = "N_LOG_ID", unique = true, nullable = false)
@SequenceGenerator(name = "PK_PACKETLOG", sequenceName = "SEQ_PACKETLOG")
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "PK_PACKETLOG")
@Column(name = "N_LOG_ID", unique = true, nullable = false)
Oracle自增需要一个Sequence实现,其中注解@SequenceGenerator的name 属性的值可以自定义且不能有相同的值(建议如例子一样名字规范些),sequenceName 属性的值配置成Oracle中建立的Sequence名。@GeneratedValue注解简单写如例子,详细配置可查询。