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 105724 - Incorrectly generated entity class for PostgreSQL's table
Summary: Incorrectly generated entity class for PostgreSQL's table
Status: RESOLVED FIXED
Alias: None
Product: db
Classification: Unclassified
Component: DB schema (show other bugs)
Version: 6.x
Hardware: All All
: P2 blocker (vote)
Assignee: Andrei Badea
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-06-05 13:46 UTC by Jan Stola
Modified: 2007-07-24 13:27 UTC (History)
2 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jan Stola 2007-06-05 13:46:40 UTC
Entity classes are not generated correctly for PostgreSQL's tables. The primary 
keys are handled incorrectly. For example, I tried to create a table CUSTOMER 
with the same structure as the example table in GlassFish and it generated 
CustomerPK embeddable with no fields, two default constructors and error in 
toString() method. This embedded class is used in the generated Customer class 
which is incorrect because the CUSTOMER table has one primary key column: 
CUSTOMER_ID. So, CustomerPK shouldn't be used at all and customerId field 
should be marked as @Id instead.
The generated entity doesn't work - it is even non-compilable.
Comment 1 Erno Mononen 2007-07-20 12:32:30 UTC
Seems that the generator gets confused when the name of the primary key field is in quotes, i.e. 

customer_id integer not null primary key works, but

"customer_id" integer not null primary key does not.

Comment 2 Erno Mononen 2007-07-20 13:15:19 UTC
Reassigning to db/dbschema for further evaluation. The problem seems to be caused by that 
UniqueElement#getColumns().length is 0 for primary keys returned by TableElement#getPrimaryKey() when the name of the 
primary key is in quotes, whereas for names without quotes it is correctly 1. This confuses the entity generator so 
that it generates a separate PK class. 

I tested with PostgreSQL 8.2.4 and 8.2-505 JDBC 3 driver.
Comment 3 Erno Mononen 2007-07-20 13:16:59 UTC
Forgot to change the component, see above.
Comment 4 Andrei Badea 2007-07-23 13:51:16 UTC
The PostgreSQL driver quotes quoted index columns when returning them from DatabaseMetaData.getIndexInfo(). E.g. it
returns "CUSTOMER_ID" instead of CUSTOMER_ID.
Comment 5 Andrei Badea 2007-07-23 15:00:51 UTC
Added some enhanced support for PostgreSQL, otherwise known as a hack. Also filed PostgreSQL bug 3480.

Checking in src/org/netbeans/modules/dbschema/jdbcimpl/TableElementImpl.java;
/cvs/db/model/src/org/netbeans/modules/dbschema/jdbcimpl/TableElementImpl.java,v  <--  TableElementImpl.java
new revision: 1.6; previous revision: 1.5
done
Comment 6 Andrei Badea 2007-07-24 13:27:28 UTC
Marking as closed.