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 86235 - fix named query generation for composite pk
Summary: fix named query generation for composite pk
Status: RESOLVED WONTFIX
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-09-29 23:59 UTC by Rochelle Raccah
Modified: 2016-07-07 08:55 UTC (History)
2 users (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 Rochelle Raccah 2006-09-29 23:59:38 UTC
Right now the Entity from DB wizard generates named queries for most fields.  
In the case of a composite pk, it generates:
findBy<Field1>
findBy<Field2>
...
findBy<FieldN>

We really need to generate a named query like this (example case of 
order/lineitem):
name: findByPrimaryKey
query: SELECT o FROM Orderitem o WHERE o.orderitemPK.orderid = :orderid and 
o.orderitemPK.lineitemid = :lineitemid

The questions for HIE (Jano) are:
1) What should this new query be named?  Choices are:
- findBy<Field1><Field2>...<FieldN>
- findById
- findByP(rimary)K(ey)
- findByCompositeP(rimary)K(ey)
- something else?

Note that the generated PK class uses "PK" but the annotations for pk field 
use "Id".

2) If we choose a name other than the first one (involving field names), 
should we rename the named query for the non-composite case? For example, 
today we have Employee with a pk of empid, so we generate findByEmpid.  Should 
that be renamed to findById or whatever we decide in 1?
Pros: consistency
Cons: might confuse users since we are releasing 5.5 with the field name 
(findByEmpid) way

3) Should this new joined findByPK named query replace the individual 
findBy<Field1>, findBy<Field2>,...,findBy<FieldN> queries? Or should it 
augment them? Most of them are not too useful on their own, but there is the 
case of overlapping pk/fk case that makes one of them useful.
If we choose to keep the overlapping pk/fk case - it is more like a 
relationship field query and we don't generate those now.  We might have a 
bigger task to look at those.
Also, we need to consider 5.5 users who have all of these generated if we no 
longer generate them....
Comment 1 Andrei Badea 2007-02-15 15:43:23 UTC
These are not questions for HIE. These are questions for people working on JPA
support. Rochelle and Marina, I'd appreciate your input.

Ad #1: it seems we should use either findBy<Field1><Field2>...<FieldN> or
findById. The former makes sense because it is consistent with the single-field
queries, the latter is consistent with many people naming primary key columns
"ID". Of course, this is not consistent with naming composite primary key
classes <Entity>PK, if we want to keep that we should rather use findByP(k|K).

Note that if, in the future, we also decide to generate queries for composite
indexes (named findBy<Field1>...<FieldN>), there would be not way to tell the
queries for the primary key and indexes apart. The findBy(Id|PK) name would make
more sense in this light.

Ad #2,3: it could not only confuse users, but also break their existing code.

It would be better IMO to generate queries that make sense, that is, for the
primary key and indexed columns. But there could probably be an option to
generate queries for all columns (turned off by default). Not sure about queries
for relationships -- aren't those covered by the relationships between entity
classes?

This issue looks more like an enhancement to me.
Comment 2 Rochelle Raccah 2007-02-16 18:43:49 UTC
Andrei, you have our input, as I am the one who filed the initial bug and ran
the text by Marina before doing so.  We wanted HIE's input mainly on the
consistency/compatibility issues. I think the initial bug description does a
decent job of discussing the pros/cons. 
Comment 3 Andrei Badea 2007-02-19 12:29:14 UTC
There are many questions in the initial descriptions. I was asking if you have
any  answers to those questions, e.g. if you prefer any of the possible primary
key query name, etc.
Comment 4 Rochelle Raccah 2007-02-21 01:30:09 UTC
No real preferences, mostly asking for input.
Comment 5 Martin Balin 2016-07-07 08:55:41 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