开发者

Hibernate with MySQL : Auto-Generate Id : Equivalent of Sequence (Oracle) in MySQL

As far as i Understand, when 'Native' class is used for auto id generation in Oracle, a single hibernate sequence is created, from where all the IDs are supplied to whichever table needed.

But i dont see this happen with MySQL. Instead, id's for each table start with 1.

Please correct me if am wrong开发者_运维百科.

Also, if i want the same tu happen on MySQL, what should be done.

Thanks All.

Raj.


As far as I Understand, when 'Native' class is used for auto id generation in Oracle, a single hibernate sequence is created, from where all the IDs are supplied to whichever table needed.

This occurs if you don't specify any sequence name, unlike this:

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

And actually most of time, people do NOT want a unique sequence, they prefer one sequence per table.

But I don't see this happen with MySQL. Instead, id's for each table start with 1.

With MySQL, the native generator will default to an identity strategy i.e. will use identity columns, which are per table.

Also, if I want the same to happen on MySQL, what should be done.

By same, I guess you mean using sequential IDs for all your entities. Give the table generator a try :

<generator class="table">
</generator>

But this won't perform as well as sequence or identity columns. Also, people usually tend to prefer not sharing IDs between entities as I already wrote. I would think about this again.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜