5

I use play! framework 2.0 and postgresql.
in my db there is users table and every user ofcourse has a unique id.
so I defined it as serial.

my question is: how to represent a field which it's data type is serial
in my java project.

p.s. I understood play! framework uses Hibernate annotation

1
  • 1
    serial is "just" an integer. Commented Aug 4, 2012 at 9:47

2 Answers 2

7

From the PostgreSQL documentation, the SERIAL type is equivalent to an ìnteger` with a sequence, so:

CREATE TABLE tablename (
    colname SERIAL
);

is equivalent to specifying:

CREATE SEQUENCE tablename_colname_seq;
CREATE TABLE tablename (
    colname integer DEFAULT nextval('tablename_colname_seq') NOT NULL
);

The @Id JPA annotation on the Long type will provide a sequence (equivalent to AUTO_INCREMENT in MySQL).

So, in you class, just use:

@Id
public Long id;
Sign up to request clarification or add additional context in comments.

Comments

0

OK. I just added the annotation @Id

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.