New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
clarify SqlResultSetMapping with multiple EntityResult and conflicting aliases #350
Comments
Or should a JPA provider try to match the results also based on table name through |
For me, that is the most reasonable expectation. From
Strictly following this documentation section, the expectation should be that explicit So that's how I would read it. |
I implemented the matching with the table name now in Hibernate, but the Oracle and SQL Server JDBC drivers do not provide the table name for selection items, so the only possible interpretations I can imagine are:
I'll have to test that, but I fear that EclipseLink might have chosen option 2. as interpretation accidentally, because the test Can @lukasj share some details here with respect to expectations or how EclipseLink interpreted this? We really need to clarify this in the specification and adapt the test data of the test to avoid this confusion. |
I just verified that EclipseLink in fact chose to interpret this as described in option 2, which can't be a sensible thing to expect from a JPA provider. The code handling this is in In Hibernate we chose to throw an error in such an ambiguous case to signal that explicit aliases are required. It would be a pity if we'd have to put this safety net behind a flag for passing the TCK. Can we fix this in a 3.0.2 version of the TCK? @scottmarlow |
See jakartaee/persistence#350 for further discussion
Tests can be excluded but not updated in a service (micro) release such as I'll bring more attention to this issue on the Persistence mailing list so that we might hear from others on the jakartaee/platform-tck#843 change. |
I think it's pretty clear that this is simply an erroneous example, which directly contradicts the text of the specification that it accompanies. Now, 3.10.16.1 of the current release of the spec is IMO rather unclear, and is urgently in need of a rewrite. But, in order to see that the example is simply wrong, we can go back to the very first release of the JPA spec, and see that the exact same example is given, but the text which accompanies it states quite explicitly that:
(My emphasis.) It's quite clear, then, that the example does not obey this rule, and is simply a mistake in the JPA 1.0 specification. And, FTR, I'm quite certain that the we (the EJB 3.0 expert group) never had any intention that result set mappings could be inferred from anything beyond the column alias. Now, that quoted text was removed somewhere along the way to JPA 2.1. Why, I have no idea. But, AFAICS, it wasn't replaced with any text which states what should happen if this case is allowed, and I read the following, rather imprecise text as implying that that restriction stated in the removed text is still implicitly assumed:
So I would say that this example and the TCK test derived from it are simply wrong. |
This would make things a lot easier. Like I wrote, also EclipseLink relies only on the column alias, and since it doesn't do any kind of alias collision validation, it doesn't understand that the result set mapping for this query doesn't "work". IMO the test should be excluded for now and for 3.0.2+ the spec text and TCK sample should be updated to use proper column aliases. |
As per https://jakarta.ee/committees/specification/tckprocess, approval is the default after 14 days (March 4 I think), unless the challenge is accepted/denied before then. |
Isn't it wrong match? As I understand the wording and the flow of the text in the spec, my understanding is that there is a mismatch of the wording and example in the initial description of this issue. To the example given, following text applies: The following query and SqlResultSetMapping metadata illustrates the return of multiple entity types. It assumes default metadata and column name defaults. ...so the returned entry is supposed to be an array of form then the spec says the When the column names of the SQL result do not correspond to ... and:
Or am I missing something? |
Ok, so in the spec, the first example Query q = em.createNativeQuery(
"SELECT o.id, o.quantity, o.item, i.id, i.name, i.description " +
"FROM Order o, Item i " +
"WHERE (o.quantity > 25) AND (o.item = i.id)",
"OrderItemResults");
@SqlResultSetMapping(name="OrderItemResults", entities={
@EntityResult(entityClass=com.acme.Order.class),
@EntityResult(entityClass=com.acme.Item.class)
}) is just there to show this is wrong/problematic and should be replaced with explicit aliases? |
Is my understanding correct, that the example in the specification document is for illustrating a problematic case where aliases are required? @lukasj |
yes, that is my understanding. First it shows what can be problematic and then it shows the solution for it. I think it was wrong to just copy the first snippet to tcks. There can be various solutions - from entirely dropping the test to updating snippet together with the test to follow expectations. |
Ok, thanks for the prompt response. Do you think the specification language should be changed for this case to require the JPA provider to throw an error? |
Are we ready to mark this challenge as accepted so that we can generate a new Persistence 3.0 Standalone TCK with the com/sun/ts/tests/jpa/core/annotations/nativequery/Client.java#nativeQueryTest1 excluded? |
yes, Does the text in the spec need to be changed as well? What I have in mind is to change:
to
|
Looks good to me! |
…licting aliases Signed-off-by: Lukas Jungmann <lukas.jungmann@oracle.com>
Signed-off-by: Scott Marlow <smarlow@redhat.com>
…aee/persistence#350 and also increment Persistence TCK version to 3.0.2 Signed-off-by: Scott Marlow <smarlow@redhat.com>
In 3.10.16.1. the spec mentions a particular example that the test(
com/sun/ts/tests/jpa/core/annotations/nativequery/Client.java#nativeQueryTest1
) refers to and saysThe example being
Both
o.id
andi.id
select items would get the column aliasid
, so AFAIU, according to the specification, this would require the introduction of an alias in the SQL and the use of@FieldResult
to disambiguate which result set index should be for which attribute. Yet this TCK test expects this to work and I think that this might be just by accident, because in the test data(see https://github.com/eclipse-ee4j/jakartaee-tck/blob/master/src/com/sun/ts/tests/jpa/core/annotations/nativequery/Client.java#L69) the corresponding item for an order has the sameid
. So the test doesn't necessarily clarify or assert how this case should be supported.Should JPA providers assume that a result set column can only be "consumed" for a single attribute mapping i.e. the first encounter of a column label
id
is consumed for theOrder#id
attribute and the second one forItem#id
?The text was updated successfully, but these errors were encountered: