users@glassfish.java.net

Re: [Fwd: Use of SERIAL and BIGSERIAL w/ EJB3 and POSTGRES]

From: <glassfish_at_javadesktop.org>
Date: Tue, 07 Aug 2007 12:31:30 PDT

You can use either:

Table sequencing:
@Id
@GeneratedValue(strategy=TABLE, generator="EMPLOYEE_TABLE_GENERATOR")
@TableGenerator(
    name="EMPLOYEE_TABLE_GENERATOR",
    table="CMP3_EMPLOYEE_SEQ",
    pkColumnName="SEQ_NAME",
    valueColumnName="SEQ_COUNT",
    pkColumnValue="EMPLOYEE_SEQ",
    initialValue=50
)


or Identity (all the tables should be defined with Identity in this case)
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private int requestID;

or sequences
@Id
@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="TTT_SEQUENCE_GENERATOR")
@SequenceGenerator(name="TTT_SEQUENCE_GENERATOR", sequenceName="seq_name", allocationSize=1)
@Column(name = "id", nullable = false)
private int requestID;

In that case you need to override PostgreSQLPlatform:
public class PostgreSQLPlatformSupportingSequences extends PostgreSQLPlatform {
    public boolean shouldNativeSequenceAcquireValueAfterInsert() {
        return false;
    }
    public void platformSpecificSequencingInitialization(DatabaseSession session) {
    }
}
[Message sent by forum member 'ailitche' (ailitche)]

http://forums.java.net/jive/thread.jspa?messageID=229898