This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 211375

Summary: Schema generator should use sequence identity on PostgreSQL
Product: db Reporter: ringerc <ringerc>
Component: DB schemaAssignee: Libor Fischmeistr <lfischmeistr>
Status: NEW ---    
Severity: normal CC: sj-nb
Priority: P3    
Version: 7.1.2   
Hardware: All   
OS: All   
Issue Type: ENHANCEMENT Exception Reporter:

Description ringerc 2012-04-18 09:20:35 UTC
When generating JPA entities from a PostgreSQL database schema, NetBeans creates identity fields like:


    @Id
    @SequenceGenerator
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Basic(optional = false)
    @NotNull
    @Column(name = "id")
    private Integer id;

What it should really do for PostgreSQL is examine primary keys to see if there's a default of `nextval('some_seq_name')' and if there is, define the column as:


    @Id
    @SequenceGenerator(name="the_seq_name", sequenceName="the_seq_name", allocationSize=1)
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator="the_seq_name")
    @Basic(optional = false)
    @NotNull
    @Column(name = "id")
    private Integer id;

This will ensure that the correct PostgreSQL sequence is used to allocate IDs.

Note that the `allocationSize=1' is important to avoid another issue where JPA implementations will incorrectly assume the result of `nextval' is the highest of 50 allocated IDs. A correct value for `allocationSize' can be derived by examining `INFORMATION_SCHEMA.SEQUENCES' for the `increment' value of the sequence of interest.

I was a little surprised that there doesn't seem to be an obvious link in INFORMATION_SCHEMA between a generated column in a table and the associated sequence.
Comment 1 medeag 2012-09-24 08:47:15 UTC
It will be useful feature for oracle db also.