Hi Kasim!
Sequenzes are not hibernate specific "stuff". Instead sequences are database
specific counters. Oracle are using sequnces, but MsSQL, MySQL, etc. are using identity
mappings. If you are using MySQL you probably use an auto_increment to get the same
feature as an Oracle sequence.
Setting the strategy attribute (of the GeneratedValue-annotation) to AUTO will let
Hibernate choose the strategy depending on the underlying database. I.e. Oracle will use
sequence, MySQL will use identity.
This is what you shall do to be sure you write an implementation that works for many
database providers/brands.
|
| ...
|
| @Entity
| @Table(name="the_object")
| public class TheObject {
|
| ...
|
| @Id
| @Column(name="id")
| @GeneratedValue(strategy=GenerationType.AUTO, generator="seqTheObject")
| @SequenceGenerator(name="seqTheObject",
sequenceName="SEQ_THE_OBJECT")
| private Long id;
|
| ...
|
| }
|
In this case, if you choose to use Oracle that is using sequnces, then you must have
created a sequence SEQ_THE_OBJECT declared in your Oracle database schema. You get a
create table syntax like:
| CREATE TABLE THE_OBJECT (
| ID NUMBER(10) NOT NULL,
| ...
| PRIMARY KEY(ID)
| );
|
| CREATE SEQUENCE SEQ_THE_OBJECT START WITH 1 INCREMENT BY 1;
|
|
On the other hand, if you choose MySQL as your database provider, then you set the id
column to use "AUTO_INCREMENT".
| CREATE TABLE THE_OBJECT (
| ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
| ...
| PRIMARY KEY(ID)
| )
|
I hope this answered your question.
Cheers
/Oskar
View the original post :
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4124271#...
Reply to the post :
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&a...