hibernate主键生成策略值sequence

时间:2014-05-04 18:01:18   收藏:0   阅读:330

主键生成策略采用sequence,但没有指定具体的sequence的时候,Hibernate会访问一个默认的sequence,是hibernate_sequence,我们也需要在数据库中建立这个sequence

xml文件配置,采用默认seq

<id name="pkId" type="java.math.BigDecimal">
            <column name="PK_ID" precision="22" scale="0" />
            <generator class="sequence" />
        </id>

采用指定eeq

<generator class="sequence" >
            	<param name="sequence">seq_t_user</param>
</generator>

注解配置seq

@SequenceGenerator (name = "SEQ", sequenceName = "SEQ_T_CMP_CITY", allocationSize = 1)
	@Id
	@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SEQ")
	@Column(name = "id")

public Integer getId() { 
return id ;
}


hibernate主键生成策略值sequence,布布扣,bubuko.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!