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 81716 - Entity Classes from DB: cannot generate from tables without primary keys
Summary: Entity Classes from DB: cannot generate from tables without primary keys
Alias: None
Product: javaee
Classification: Unclassified
Component: Persistence (show other bugs)
Version: 5.x
Hardware: PC Windows 7
: P2 blocker (vote)
Assignee: Andrei Badea
: 130854 (view as bug list)
Depends on:
Reported: 2006-08-02 15:57 UTC by cf126330
Modified: 2017-07-13 18:42 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT
Exception Reporter:

snapshot of the problem (143.49 KB, image/jpeg)
2017-07-13 18:39 UTC, vinh_truong

Note You need to log in before you can comment on or make changes to this bug.
Description cf126330 2006-08-02 15:57:50 UTC
Java Persistence API allows mapping an entity class to a table with no primary
key.  This is currently supported in JavaEE SDK 5, SJSAS 9.0 PE, Glassfish,
Toplink, and Hibernate Entity Manager.  But in NetBeans 5.5 beta 2
entity-class-from -db wizard, all tables without primary keys are grayed out, so
users can't use this feature.

Some glassfish users reported this problem at forum (in Chinese):

The reason he/she is asking this question is, his company used C and Informix 7
before, and it has been working pretty well for 7 years. They don't know why
these tables have no primary key (most only have unique index), since original
developers have left.

Now they are working on a new project, and evaluating EJB 3 (persistence) for
possible use.  They need to use these legacy data, but don't want change the
database structure.  They have hundreds of tables like this and some talbes
contain several million records. 

Some more info from discussion on around August 1, 2006:
[Marina Vatkina]
NetBeans will have hard time distinguishing between unique keys for
the purpose of PK and for e.g. 1-1 relationship (or any other unique
key for that matter). But NetBeans should allow (if it doesn't) to map
existing classes to existing tables with entity PKs mapped to unique

[Gordon Yorke]
NetBeans could let the user specify the unique columns on the table before
generation if the are no PK's defined in the table Metadata, or generate the
tables and allow the user to add the @Id annotation to the code at a later stage.

[Craig Russell]
I was one of the people with input to the original design decision (5  years
ago) to disallow generation of persistent classes where there  was no primary
key column in the table. We did not try to guess if  the user intended that one
of the unique constraints was supposed to  map to an identity field.

As I understand it, during generation of the class, the wizard needs  additional
user input or needs to take a guess as to which unique  constraint should map to
@Id. It's not clear what a rational default  should be in the case that there
are multiple unique constraints that  might be mapped. And since the Id field is
immutable after persist,  it's not clear that you would have a usable class by
mapping such a  table.

A feature in the wizard to guess the Id of a table without a primary  key can be
added but wasn't part of the original design specification.

I'd suggest filing a feature request in Glassfish/Netbeans so we can  track it
Comment 1 Sergey Petrov 2009-12-11 03:37:19 UTC
*** Bug 130854 has been marked as a duplicate of this bug. ***
Comment 2 Martin Balin 2016-07-07 08:53:54 UTC
This old bug may not be relevant anymore. If you can still reproduce it in 8.2 development builds please reopen this issue.

Thanks for your cooperation,
NetBeans IDE 8.2 Release Boss
Comment 3 vinh_truong 2017-07-13 18:39:09 UTC
Created attachment 164761 [details]
snapshot of the problem
Comment 4 vinh_truong 2017-07-13 18:39:49 UTC
I have same problem in NB 8.2