I have a table person{id,personName,birthDate}. In the table I have to get all the person details by their birthDate with out comparing its time. I have the following query
Query q = entitymanager.createQuery(select p from person p where
CAST(p.birthDate as date) = :birthdate);
q.setparameter("birthdate",new Date(),TemporalType.DATE) ;
When I test the above query using mysql, it gives the correct result. But it is not functioning correctly in Oracle. I tried the between...and logic by setting the starting time as 0:0:0 and the ending time as 23:59:59. Is there any other alternative.
I am using JPA 1.0 with hibernate as a service provider. Thanks in advance for your help.
Related
I am trying to get data from a single Oracle database table in Power BI Desktop. This table has around 2 million rows of data.
The following Query works just fine:
let
Source = Oracle.Database("PPM_PROD", [HierarchicalNavigation=true]),
PPM_DEV = Source{[Schema="PPM_DEV"]}[Data],
Timesheets = PPM_DEV{[Name="BI_TIMESHEET"]}[Data]
in
Timesheets
However, if I add an SQL statement as below, I run into problems:
let
Source = Oracle.Database("PPM_PROD", [HierarchicalNavigation=true, Query="SELECT * FROM PPM_DEV.BI_TIMESHEET#(lf)WHERE (ACTUAL_TIME > 0) OR (OVERTIME > 0) "]),
PPM_DEV = Source{[Schema="PPM_DEV"]}[Data],
Timesheets = PPM_DEV{[Name="BI_TIMESHEET"]}[Data]
in
Timesheets
This query will not get any data and data load/refresh will be stuck at "Evaluating" phase forever. Any suggestions will be greatly appreciated.
In this case, I'd recommend not using the SQL statement but rather filtering it in the Power Query Editor. In the most common filtering scenarios, Power Query will transform the filter steps applied into a native query similar to your SQL statement.
You can still use a SQL statement if you prefer but the steps
PPM_DEV = Source{[Schema="PPM_DEV"]}[Data],
Timesheets = PPM_DEV{[Name="BI_TIMESHEET"]}[Data]
don't make sense if you've already selected and filtered the Timesheets table. Those steps are there to navigate to the schema and table you intend to query but you've already handled that in your SQL.
I have a mapping in Oracle data integrator that works correctly, I need to filter by a column and exclude the rows where the length of that column equals 3. I can't find the correct function to do it. I already tried with LENGTH (column) = 3 and it doesn't work...
Does anyone know the way?
Oracle Data Integrator is most of the time generating code that is pushed down to the underlying technology. So it depends which technology you are using.
For instance if you are using an IKM using the Oracle technology, the code will be execute by the Oracle database. In that case LENGTH(column_name) <> 3 should work.
I'm using entity framework core for mysql, and i've been running a complex linq query which i'm trying to optimise.
I turned on logging in the mysql server to view the resulting queries from the linq queries.
Oddly, none of it made sense as my complex query that joined 5 tables and performed multiple group bys, where, and order by clause was registered in the logs as 5 separate select all columns from table statements.
So, I tried a simple group by statement for one table. The resulting sql log produced "Select all_columns from table_name order by groupbyid".
Can anyone explain what happened here?
Thanks in advance.
More info as requested:
Sql query:
var queryCommand = (from p in _context.TableExtract group p by p.tableExtractPersonId);
queryCommand.ToList();
Resulting mysql log after:
SELECT .... [very long list of column names]
FROM TableExtract AS p
ORDER BY p.tableExtractPersonId
I've tried two different entity framework libraries: MySql.Data.EntityFrameworkCore(v8.0.17) and Pomelo.EntityFrameworkCore.MySql (v2.2.20) with the same results. I've tried .net core 3.0 and also received the same results. I'm going to try .net standard next.
Ok. I found it:
var queryCommand = (from p in _context.TableExtract group p by p.tableExtractPersonIdinto g select g.Key)
Forces linq to evaluate as a SQL group by. Otherwise apparently it does it's own thing with the group by.
Given the schema below, I'm trying to build an EF query that returns Contacts that are missing required Forms. Each Contact has a ContactType that is related to a collection of FormTypes. Every Contact is required to have at lease one Form (in ContactForm) of the FormTypes related to its ContactType.
The query that EF generates from the linq query below works against Sql Server, but not against Oracle.
var query = ctx.Contacts.Where (c => c.ContactType.FormTypes.Select (ft => ft.FormTypeID)
.Except(c => c.Forms.Select(f => f.FormTypeID)).Any());
I'm in the process of refactoring a data layer so that all of the EF queries that work against Sql Server will also work against Oracle using Devart's dotConnect data provider.
The error that Oracle is throwing is ORA-00904: "Extent1"."ContactID": invalid identifier.
The problem is that Oracle apparently doesn't support referencing a table column from a query in a nested subquery of level 2 and deeper. The line that Oracle throws on is in the Except (or minus) sub query that is referencing "Extent1"."ContactID". "Extent1" is the alias for Contact that is defined at the top level of the query. Here is Devart's explanation of the Oracle limitation.
The way that I've resolved this issue for many queries is by re-writing them to move relationships between tables out of the Where() predicate into the main body of the query using SelectMany() and in some cases Join(). This tends to flatten the query being sent to the database server and minimizes or eliminates the sub queries produced by EF. Here is a similar issue solved using a left outer join.
The column "Extent1"."ContactID" exists and the naming syntax of the query that EF and Devart produce is not the issue.
Any ideas on how to re-write this query will be much appreciated. The objective is a query that returns Contacts missing Forms of a FormType required by the Contact's ContactType that works against Oracle and Sql Server.
The following entity framework query returns all the ContactIDs for Contacts missing FormTypes required by their ContactType when querying against both Sql Server and Oracle.
var contactNeedsFormTypes =
from c in Contacts
from ft in c.ContactType.FormTypes
select new { ft.FormTypeID, c.ContactID};
var contactHasFormTypes =
from c in Contacts
from f in c.Forms
select new { c.ContactID, f.FormTypeID};
var contactsMissingFormTypes =
from n in contactNeedsFormTypes
join h in contactHasFormTypes
on new {n.ContactID, n.FormTypeID} equals new {h.ContactID, h.FormTypeID}
into jointable
where jointable.Count()==0
select n.ContactID;
contactsMissingFormTypes.Distinct();
I'm trying to write this query using Hibernate 3 and Oracle 10.
from Alert alert
where alert.expiration > current_date()
order by alert.priority, alert.updated, alert.name
It's creating SQL like this -
Hibernate: select alert0_.ANNOUNCEMENTS_ID as ANNOUNCE1_1_, alert0_.ANNOUNCEMENT
S_NAME as ANNOUNCE2_1_, alert0_.ANNOUNCEMENTS_PRIORITY as ANNOUNCE3_1_, alert0_.
ANNOUNCEMENTS_EXPIRATION as ANNOUNCE4_1_, alert0_.ANNOUNCEMENTS_UPDATE_DATE as A
NNOUNCE5_1_ from NYC311_ANNOUNCEMENTS alert0_ where (alert0_.ANNOUNCEMENTS_EXPIR
ATION>current_date()) order by alert0_.ANNOUNCEMENTS_PRIORITY , alert0_.ANNOUNC
EMENTS_UPDATE_DATE , alert0_.ANNOUNCEMENTS_NAME
I'm getting all of these wacky errors like "missing right parenthesis" when there is apparently perfectly balanced parenthesis.
Why is Oracle freaking out at this? Is there a better way to write my HQL query?
Shouldn't it be current_date?
Hibernate will translate it to the proper dialect.
I did not find a real "Hibernate will translate this to that" reference documentation, but the expression, in general, can be found in HQL Expressions for Hibernate 4.3.
Then there is the Java Persistence API 2.0 (JPA) specification which defines expressions for the Java Persistence query language (JPQL) and their meaning e.g. for current_date:
4.6.17.2.3 Datetime Functions functions_returning_datetime:= CURRENT_DATE | CURRENT_TIME | CURRENT_TIMESTAMP The datetime functions
return the value of current date, time, and timestamp on the database
server.
Is current_date() a Hibernate function?
I would use sysdate instead. like this:
where alert.expiration > sysdate
Or to ignore time of day:
where alert.expiration > trunc(sysdate)