Search code examples
javapostgresqljpaglassfisheclipselink

EclipseLink & PostgreSQL doesn't use BIGSERIAL to Long id


i expected below code to create table which has BIGSERIAL column type id.

@Entity
public class NewEntity1 implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
...

but it created:

CREATE TABLE NEWENTITY1 (ID  SERIAL NOT NULL, PRIMARY KEY (ID))

i want to make it BIGSERIAL column (not SERIAL). how can i fix this?

my environment:

  • NetBeans7.1
  • GlassFish 3.1.1(NetBeans bundled)
  • EclipseLink 2.3.0.v20110604-r9504(NetBeans bundled)
  • PostgreSQL 9.1.2 (JDBC driver: postgresql-9.0-801.jdbc4.jar)

thanks.


Solution

  • The problem here is that EclipseLink PostgreSQLPlatform hard codes the string it uses within the printFieldIdentityClause to be "SERIAL". This should be customizable though, so please file a bug to have it changed.

    Other than using columnDefinition, you can create a sublclass of the PostgreSQLPlatform and override the printFieldIdentityClause method to print off what you need. Ie:

    @Override
        public void printFieldIdentityClause(Writer writer) throws ValidationException {
            try {
                writer.write(" SERIAL");
            } catch (IOException ioException) {
                throw ValidationException.fileError(ioException);
            }
        }
    

    and then set your persistence unit properties to use your platform class instead:

    <property name="eclipselink.target-database" value="yourpackage.yourPlatformClass"/>