Glassfish Eclipselink join-fetch hint not working - glassfish

I'm having real difficulty getting the eclipselink.join-fetch hint to work in glassfish.
I have a Client object that contains a collection of Task objects and the Task object has a collection of WorkPeriod objects.
My code looks like this:
Query query = entityManager.createQuery("select client from Client client left join fetch client.tasks");
//Set hint to allow nested fetch joins
query.setHint("eclipselink.join-fetch","client.tasks.workPeriods");
List<Client> clients = query.getResultList();
But no matter what I do when I set the TOPLINK debug level to fine it always shows that the SQL which is actually run is:
SELECT t0.ID, t0.NAME, t1.ID, t1.DESCRIPTION FROM CLIENT t0 LEFT OUTER JOIN (CLIENT_TASK t2 JOIN TASK t1 ON (t1.ID = t2.tasks_ID)) ON (t2.Client_ID = t0.ID)
Clearly not doing the third tier of the join fetch.
Has anyone else had problems with this... or is it just me :-(
Any help or hints (no pun intended) would be much appreciated.

OK, after 8 hours of frustration I've got to the bottom of it.
Glassfish V2 doesn't use EclipseLink as it's persistence provider, it uses Toplink Essentitals. Unfortunately Toplink essentials doesn't provide a join-fetch hint (I was very confused by the following link which made me think it did: https://glassfish.dev.java.net/issues/show_bug.cgi?id=1200 although this is obviously a feature request NOT a feature).
So it would appear that what I'm attempting to do is not possible and if I want to do multi-level eager fetch in glassfish I'm going to have to get the EntityManagers delegate and use the toplink essentials Expressions directly.

Related

hibernate query doesn't get translated on saas sql properly

I'm using below query in a Spring Boot app repository. Although it runs fine locally, and the queries return expected values both on h2 console and SaaS SQL SSMS, but I get the error below when I call the API that uses this repository.
org.hibernate.exception.SQLGrammerException: Couldn't extract
ResultSet
here is the hibernate query:
#Query("FROM xyzTable t1 where (t1.field1, t1.field2) in (SELECT Max(t2.field1), t2.field2 FROM xyzTable t2 GROUP BY t2.field2) ORDER BY t1.field2")
I think it has something to do with "(t1.field1, t1.field2)" part of the query. If I use one field in the WHERE clause, it won't object.
any ideas?

EF core 3.1 can not run complex raw sql query

The following query was working fine with EF core 2 but EF core 3 would throw error!
I even could add some include after this query in EF core 2 which I let go now.
query:
// just to have an Id
var id = Guid.NewGuid();
var resutl = Context.Parties.FromSqlInterpolated($#"WITH mainOffice AS
(SELECT * FROM Parties as o1 WHERE (Discriminator = N'Office')
AND (Id = '{id}')
UNION ALL SELECT o.* FROM Parties AS o INNER JOIN mainOffice AS m
ON m.Id = o.ParentOfficeId)
SELECT * FROM mainOffice as f").ToList();
The error it produces is as follows:
FromSqlRaw or FromSqlInterpolated was called with non-composable SQL
and with a query composing over it. Consider calling AsEnumerable
after the FromSqlRaw or FromSqlInterpolated method to perform the
composition on the client side.
Knowing the following information might help:
Table "Parties" is a table per hierarchy
I tried to run the query both from the root type DbSet and the type I am interested for
No success with nether FromSqlRaw nor FromSqlInterpolated
Adding 'AsEnumerable' did not help too
Did I forget any thing? What am I doing wrong?
What does 'non-composable SQL' mean? Does it mean EF core is trying to interpret query?
I don't have the answer, but I know the reason now.
The reason this error is being generated is similar to this issue:
FromSql method when used with stored procedure cannot be composed
In my case weather or not I use any method, because the table I am trying to query is containing some different type (Table per hierarchy), my query will always be warped inside a select query to limit discriminators. Even though I write the query from the root, the wrapper select query is generated with all possible discriminators.
So it means I can only run queries that can be placed as sub query. My query can not, store procedures can not ...
I found a workaround for this issue,
You can create a view in database and a query type in your model and then run your query against this view (note that the way you do that has been changed from ef 2 to 3 as it is explained here)
So in this way inheritance and discriminators are not problems any more and query can be run.
Maybe related?
https://learn.microsoft.com/en-us/ef/core/what-is-new/ef-core-3.0/breaking-changes#linq-queries-are-no-longer-evaluated-on-the-client
Efcore 2 implicity performed linq to objects on parts of a query that it could not transform to sql. This functionality was removed in efcore 3.

Apache Ignite: Whether or not it is possible to do these things?

I am doing a POC to decide if Apache Ignite can do these things.
I have 3 important use cases:
Insert data into SQL. I know it does, but I want this with point 2 below.
Have a continuous query for a specific SQL select listen to the update
For example: Let's say I would like to have this listener run only for a
query like:
SELECT *
FROM TABLE_1 p1
inner join TABLE_2 p2
on (p1.id = p2.id)
Is it possible?
Occasionally be able to run a SELECT from external clients. I know it does but I want this with point 2 above.
You can do both selects and updates using SQL. Please refer to the documentation for all the details: https://apacheignite-sql.readme.io/
However, continuous queries are not SQL based. It's basically a listener that gets notified about updates in a cache. You can optionally have a remote filter on server side, but that's a piece of Java code, not a SQL query. More info here: https://apacheignite.readme.io/docs/continuous-queries

SQL Update Using From

I know this is a contrived example so please do not jump all over me for the uselessness of the code. This is an issue in more complex chunk of code but I wanted to isolate the I am having.
The error I am getting is 'SQL Error: ORA-00933: SQL command not properly ended'. Any ideas? I am using SQL Developer by the way.
Once again...this is a contrived example and while the join is pointless in this case it is not in the more complex example.
Here is the code:
Update u
set first300pa = 1
from GameData_ME u
inner join
GameData_ME v on u.pitchandeventid = v.pitchandeventid
As this blog says,
Those who transitioned from SqlServer
to Oracle might find the absence of
the UPDATE FROM a significant loss.
Fortunately, the blog continues by showing a lot of the power of Oracle's UPDATE and how to use it to perform the tasks you need (but it won't be with a FROM clause in the UPDATE statement... not in Oracle!-).

How do I construct a cross database query in MySQL?

I've got two databases on the same server. The Google gave me some hints but there wasn't anything "official" that I could find. Could someone point me to the documentation that explains how to do this? An explanation using PHP would be useful as well. Thanks!
I've got two databases on the same server. ...How do I construct a cross database query in MySQL?
You access other databases on the same MySQL instance by prefixing the table with the appropriate database name. IE:
SELECT *
FROM this_database.table_1 t1
JOIN that_database.table_2 t2 ON t2.column = t1.column
Keep in mind
A query executes with the credentials of the authentication used to set up the
connection. If you want to query two tables simultaneously across two (or more)
databases, the user used to run the query will need SELECT access to all
databases involved.
Reference:
Identity Qualifiers
SELECT * FROM DB1.myTable1 AS db1, DB2.myTable2 AS db2
http://www.dottedidesign.com/node/14 provides the following example:
SELECT
arbogast.node.nid as anid,
mcguffin.node.nid as mnid,
arbogast.node.title as atitle,
mcguffin.node.title as mtitle
FROM arbogast.node, mcguffin.node
WHERE arbogast.node.nid = 1
AND mcguffin.node.nid = arbogast.node.nid;
Where arbogast and mcguffin are different databases.