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 130464 - Generate fields for foreign keys referencing not included tables
Summary: Generate fields for foreign keys referencing not included tables
Status: RESOLVED FIXED
Alias: None
Product: javaee
Classification: Unclassified
Component: Persistence (show other bugs)
Version: 7.1.2
Hardware: All All
: P2 blocker (vote)
Assignee: Sergey Petrov
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-03-18 23:09 UTC by kodaman
Modified: 2012-05-31 14:19 UTC (History)
0 users

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 kodaman 2008-03-18 23:09:39 UTC
A few things here:

1. In my experiences, it appears if you generate an entity from database schema and choose not to "Include Related
Tables", then it will not generate fields that reference other tables. This is occurring on SQL server for me. What
should occur is that all columns should be generated and just not mapped as collections but rather their actual column
names. For instance, if I have fooId in my Bar table and I don't generate the Foo class at the time, the fooId column is
not generated in the Bar table.

2. I have no way to tell NetBeans NOT to do collections on foreign keys. I can uncheck "Include Related Tables" but my
table has a constraint on itself (i.e. parent-child) it generates the collection. There should be an option NOT to
create relationships.

3. You add a NamedQueries annotation that is empty.
Comment 1 Andrei Badea 2008-03-20 18:18:10 UTC
I could reproduce #1, but not #3. Do you always get an empty NamedQueries annotation, or only for certain tables? If the
latter, could you please attach the script to create such a table? Thanks.
Comment 2 Andrei Badea 2008-03-24 19:11:40 UTC
After thinking about this a bit, I think the behavior you request in #1 doesn't necessarily makes sense for everyone.
The wizard would have to provide an option for it, which is too big a change to be made in 6.1. Moreover, it is not a
defect really.
Comment 3 kodaman 2008-03-31 18:35:30 UTC
For #3, I don't use a script, I use the dialog in NB.

As for #1, it is a legitimate issue because what if I just want to reference one table via JPA? I won't get all columns
on that table. Agreed it may not be a defect, but it would be nice to get all columns of a table when I reverse engineer
its schema.

Of course, these aren't huge issues. I built an ant script using Hibernate Tools to solve my problems.
Comment 4 kodaman 2008-03-31 18:37:30 UTC
er...what I posted about #3 doesn't really make sense. It does happen for me on all tables in SQL server, but it's
hardly an issue, just a note. Ignore #3.
Comment 5 kidvid 2012-05-31 13:23:10 UTC
The #1 part of this ticket is causing some real problems for us, and is requiring a lot of hand modification of netbeans generated database entites.

If you create a new entity class (not update an existing one), and you only select a single table, it should generate getters and setters for every column in the table, even if that column is a foreign key.

Here's an example:

I have two tables:  employee and state_code_lookup.

The employee table has a column in it called "state_cd" that references the state_code_lookup.

Right now, if you choose to generate an entity class for the employee table and you choose nothing else in the picklist, it will not generate the column variable for the state_cd.

If it's a new entity class, and you only select one table then you're essentially telling the generator to make you a standalone entity object with all of the columns specified in it.  Anything else is a bug in my opinion, because otherwise, the resulting entity class isn't usable.

In this example, it's not a huge issue to fix by hand, but the developer shouldn't have to.  Unfortunately, with our project, some of our tables have not just one foreign key column in them, but dozens.
Comment 6 Sergey Petrov 2012-05-31 14:18:50 UTC
usually @Column for missed relationships will not represent tables properly, because table relationships is part of a table, but in 7.2 you can choose to generate missed columns on last wizard step.
see http://wiki.netbeans.org/NewAndNoteworthyNB72#Generation_options
hope it is.