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 256032 - JPQL result pane does not show all columns
Summary: JPQL result pane does not show all columns
Status: RESOLVED FIXED
Alias: None
Product: javaee
Classification: Unclassified
Component: Persistence (show other bugs)
Version: 8.1
Hardware: All All
: P2 normal (vote)
Assignee: Petr Hejl
URL:
Keywords: PATCH_AVAILABLE
Depends on:
Blocks:
 
Reported: 2015-10-19 22:53 UTC by pbelbin
Modified: 2016-05-20 01:39 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
sample project (4.90 KB, application/x-zip)
2015-11-04 21:18 UTC, matthias42
Details
proposed patch (31.80 KB, patch)
2015-11-04 21:58 UTC, matthias42
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description pbelbin 2015-10-19 22:53:38 UTC
[ JDK VERSION : 1.8.0_45 ]

1. create a jpa 2.1 (with EclipseLink) entity model that uses single-table
inheritance, with a base class, and two other classes that extend the base
class.  eg: a, a1, a2, using the default dtype string column mechanism for
single-table inheritance.
2. create two additional tables to which a join hierarchy is formed between
them.  eg: a <- b <- c
3. create a query that provides the id for c, which uses joins to be able to
obtain the related 'a' records, with a query similar to this:
SELECT a FROM A a JOIN a.b b JOIN b.pId c WHERE c.thingId = '01234567890';

the result in the output will only contain the discriminator column, in my
example.
Comment 1 pbelbin 2015-10-19 22:56:05 UTC
btw: 'a' entity should have multiple data columns, which 'a1' and 'a2' also inherit.
Comment 2 matthias42 2015-11-04 21:16:51 UTC
Reassigning to javaee, the described component (JPQLEditorTopComponent) is located in the j2ee.persistence module.
Comment 3 matthias42 2015-11-04 21:18:25 UTC
Created attachment 157152 [details]
sample project
Comment 4 matthias42 2015-11-04 21:22:23 UTC
Sample data/schema for project:

CREATE TABLE A (ID INTEGER GENERATED ALWAYS AS IDENTITY, DTYPE VARCHAR(31), TITLE VARCHAR(255), TITLEID INTEGER, PRIMARY KEY (ID));
INSERT INTO A (DTYPE, TITLE, TITLEID) 
	VALUES ('A1', 'X', NULL);
INSERT INTO A (DTYPE, TITLE, TITLEID) 
	VALUES ('A2', NULL, 1);
INSERT INTO A (DTYPE, TITLE, TITLEID) 
	VALUES ('A2', NULL, 2);
INSERT INTO A (DTYPE, TITLE, TITLEID) 
	VALUES ('A2', NULL, 3);
INSERT INTO A (DTYPE, TITLE, TITLEID) 
	VALUES ('A1', NULL, NULL);


----------

Sample jpa query:

select a from a1 a
Comment 5 matthias42 2015-11-04 21:58:13 UTC
Created attachment 157153 [details]
proposed patch

The problem lies in the reflection usage. The code scans the object, extracts the class of the object and then iterates over its declares methods. This misses the inherited methods and explains the problem pbeldin sees. The logic only works without inheritance and with homogeneous results.

The attached patch changes the logic and does this:

Directly after getting the result the whole resultset is scanned. First step is determining if an object list is created or a object[] list is created. The be handled as object[] all returned rows have to be arrays and be of same length and none may be none. If one of the constraint is violated the list is asumed to be a list of objects.

From the list "ReflectionInfo" is gathered - this consists of a column index and a property name. Column index is only non-null if each row is an array and denotes the index. Property name is null if the value is a basic type and the propertyname if attributes of the object are displayed.

Based on the ReflectionInfo the ReflectiveTableModel i constructed, that fetches the correct value from the backing data on the fly.
Comment 6 Petr Hejl 2016-05-19 14:04:44 UTC
Slightly modified patch pushed as web-main b49685f71ac5.

Thanks for it!
Comment 7 Quality Engineering 2016-05-20 01:39:37 UTC
Integrated into 'main-silver', will be available in build *201605200002* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)

Changeset: http://hg.netbeans.org/main-silver/rev/b49685f71ac5
User: Petr Hejl <phejl@netbeans.org>
Log: #256032 - JPQL result pane does not show all columns