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 - Schema generator should use sequence identity on PostgreSQL
Summary: Schema generator should use sequence identity on PostgreSQL
Status: NEW
Alias: None
Product: db
Classification: Unclassified
Component: DB schema (show other bugs)
Version: 7.1.2
Hardware: All All
: P3 normal with 4 votes (vote)
Assignee: Libor Fischmeistr
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-04-18 09:20 UTC by ringerc
Modified: 2013-08-01 12:52 UTC (History)
1 user (show)

See Also:
Issue Type: ENHANCEMENT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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.