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 81956 - Entity Classes from DB: should not generate multiple dbschema files per connection
Summary: Entity Classes from DB: should not generate multiple dbschema files per conne...
Status: RESOLVED FIXED
Alias: None
Product: javaee
Classification: Unclassified
Component: Persistence (show other bugs)
Version: 5.x
Hardware: All All
: P3 blocker (vote)
Assignee: Andrei Badea
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-08-04 18:18 UTC by Andrei Badea
Modified: 2006-09-10 18:34 UTC (History)
2 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
Incomplete implementation (21.93 KB, text/plain)
2006-08-17 17:01 UTC, Andrei Badea
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Andrei Badea 2006-08-04 18:18:22 UTC
Instead the existing dbschema file (if any) for the chosen connection / data
source should be updated. Cf. discussion in issue 74113.
Comment 1 Andrei Badea 2006-08-09 16:44:40 UTC
Imagine the scenario:

1) Create a dbschema file, select some but not all tables in your database.

2) Invoke the Entity Classes from DB, ignore the already selected database
schema and select the database connection used in step 1 instead. Select some
but not all tables. Finish the wizard.

The dbschema file created in step 1 (which did not contain all tables) is
overwritten with a file which contains everything. Do you consider this a corner
case? I don't, I would tend to consider it a data loss, even if the scenario is
unlikely because the wizard offers the dbschema file in step 2, not the database
connection.

There could be another solution. We could go back to the behavior in 5.0 for CMP
entity beans: write a new dbschema file for each wizard invocation, containing
only the tables generated in that invocation (by removing the unneeded tables
from the captured schema). For entity classes we can do the same or consider not
generating a dbschema file at all. I never understood why we generate one by
default anyway.

Opinions?
Comment 2 Rochelle Raccah 2006-08-09 19:14:31 UTC
My problem is that I think the db connection is offered by default in step 2,
not the dbschema.
Comment 3 Rochelle Raccah 2006-08-09 19:15:58 UTC
Oops, sorry, I meant in the case where you went through the wizard using the
connection the last time.  I see now in your case that you explicitly created
the schema first, so the schema would be selected.
Comment 4 Pavel Buzek 2006-08-09 19:43:44 UTC
> The dbschema file created in step 1 (which did not contain all tables) is
> overwritten with a file which contains everything. Do you consider this 
> a corner case? 

First, I think this is a corner case. I think (although I do not have the data
to prove it) that people do not create DB schema manually very often. It is just
a little bit convoluted scenario in my opinion. I think most users if they want
to generate entities just go and do exacly that. I see DB schema useful for
caching, but not as a primary artefact for _most users_. This is why I think
that generating many dbschema files is a bad thing. If they know that the DB has
changed they will use DB connection instead of dbschema and here again it is
good that we update the dbschema.

Second, I do not see what would be the benefit in generating a DB schema with
only the tables used for the last generation. How would they be useful? You
cannot generate anything new from them (everything was already generated). You
can regenerate the classes if you accidently deleted them, that's about it.
Also, since we use generated names for these dbschema files many files each with
different tables will be completely impossible to understand.

Third, I do not see a big problem if we add more tables to an already generated
dbschema file. The only potential issue is with huge database when you do not
want to have a huge dbschema - that's when I would create it manually. Then it
is natural to select the dbschema and not the connection in entity from DB
wizard. Otherwise (in most cases by far - IMO) if you start to use more tables
it is OK to add them into dbschema. It is data gain, not data loss :-)

I would stick with regenerating the existing schema for that connection.
Comment 5 Rochelle Raccah 2006-08-09 20:27:50 UTC
I agree with Pavel
Comment 6 Andrei Badea 2006-08-09 23:07:37 UTC
I mostly agree too. Not with the data gain part :-) and I still believe we could
be doing something the user might not want, but that scenario is indeed
unlikely. I will implement the initial description.
Comment 7 Andrei Badea 2006-08-17 17:01:36 UTC
Created attachment 33028 [details]
Incomplete implementation
Comment 8 Andrei Badea 2006-08-17 17:04:01 UTC
I can't finish this before the vacation. If anyone wants and has time, please
finish it. All that should be needed is to rewrite the dbschema files in
DBSchemaManager.updateDBSchemas().
Comment 9 Andrei Badea 2006-09-10 18:34:25 UTC
Fixed.

Checking in
src/org/netbeans/modules/j2ee/persistence/wizard/fromdb/Bundle.properties;
/cvs/j2ee/persistence/src/org/netbeans/modules/j2ee/persistence/wizard/fromdb/Attic/Bundle.properties,v
 <--  Bundle.properties
new revision: 1.1.2.3.2.30; previous revision: 1.1.2.3.2.29
done
RCS file:
/cvs/j2ee/persistence/src/org/netbeans/modules/j2ee/persistence/wizard/fromdb/Attic/DBSchemaFileList.java,v
done
Checking in
src/org/netbeans/modules/j2ee/persistence/wizard/fromdb/DBSchemaFileList.java;
/cvs/j2ee/persistence/src/org/netbeans/modules/j2ee/persistence/wizard/fromdb/Attic/DBSchemaFileList.java,v
 <--  DBSchemaFileList.java
new revision: 1.1.2.1; previous revision: 1.1
done
Checking in
src/org/netbeans/modules/j2ee/persistence/wizard/fromdb/DBSchemaManager.java;
/cvs/j2ee/persistence/src/org/netbeans/modules/j2ee/persistence/wizard/fromdb/Attic/DBSchemaManager.java,v
 <--  DBSchemaManager.java
new revision: 1.1.2.7; previous revision: 1.1.2.6
done
Checking in
src/org/netbeans/modules/j2ee/persistence/wizard/fromdb/DBSchemaUISupport.java;
/cvs/j2ee/persistence/src/org/netbeans/modules/j2ee/persistence/wizard/fromdb/Attic/DBSchemaUISupport.java,v
 <--  DBSchemaUISupport.java
new revision: 1.1.2.7; previous revision: 1.1.2.6
done
Checking in
src/org/netbeans/modules/j2ee/persistence/wizard/fromdb/DatabaseTablesPanel.java;
/cvs/j2ee/persistence/src/org/netbeans/modules/j2ee/persistence/wizard/fromdb/Attic/DatabaseTablesPanel.java,v
 <--  DatabaseTablesPanel.java
new revision: 1.1.2.39; previous revision: 1.1.2.38
done
Checking in
src/org/netbeans/modules/j2ee/persistence/wizard/fromdb/RelatedCMPHelper.java;
/cvs/j2ee/persistence/src/org/netbeans/modules/j2ee/persistence/wizard/fromdb/Attic/RelatedCMPHelper.java,v
 <--  RelatedCMPHelper.java
new revision: 1.1.2.2.2.12; previous revision: 1.1.2.2.2.11
done
Checking in
src/org/netbeans/modules/j2ee/persistence/wizard/fromdb/RelatedCMPWizard.java;
/cvs/j2ee/persistence/src/org/netbeans/modules/j2ee/persistence/wizard/fromdb/Attic/RelatedCMPWizard.java,v
 <--  RelatedCMPWizard.java
new revision: 1.1.2.2.2.22; previous revision: 1.1.2.2.2.21
done