Have a JavaEE application that is being migrated from Oracle to SQL Server 2016.
Uses Java 1.7, jboss 4.2.3.GA and hibernate 3.2.4.sp1.
The application uses the javax EntityManager for DB access and so queries look like this:
List<ServiceProvider> providers = entityManager
.createQuery("FROM ServiceProvider sp order by sp.id")
.setMaxResults(spCount)
.getResultList();
But a SQL Trace shows the query being wrapped in exec sp_executesql.
For example the above becomes exec sp_executesql N'SELECT TOP (50) ....'
If I trace a query coming from say an SSRS report, it is not wrapped in the sp_executesql.
What is responsible for this transformation?
** edited to a single focused question.
As #MarkRotteveel mentioned in his comment, it seems the MS JDBC driver uses sp_executesql when executing a prepared statement. Once we fixed our missing pool-size and prepared-statement-cache-size options we see no difference between Oracle 12g and SQL Server 2016 so I don't believe there is a performance hit by using sp_executesql or if there it, it is very minimal.
<min-pool-size>20</min-pool-size>
<max-pool-size>220</max-pool-size>
<prepared-statement-cache-size>100</prepared-statement-cache-size>
Interestingly enough, Hibernate executes fewer queries when targeting MSSQL than Oracle. The query in my original post results in 12 Oracle queries vs 10 in MSSQL.
Related
Running spring-boot 2.1.3.RELEASE and using liquibase 3.6.3 on Oracle 12.1.0.2.v15, I get exception on startup:
Did not update change log lock correctly.\n\n 0 rows were updated instead of the expected 1 row using executor oracle there are 0 rows in the table
This:
https://github.com/liquibase/liquibase/blob/master/liquibase-core/src/main/java/liquibase/lockservice/StandardLockService.java#L334
Investigating, I suspect it might be related to some missing right of my user as it works fine on a database created with AWS RDS 12.1.0.2.v15 but not on the on premise database.
The only noticeable difference is that the user for on premise has no access to v$parameter so I get:
Could not set check compatibility mode on OracleDatabase, assuming not running in any sort of compatibility mode: Cannot read from v$parameter: ..
Has anybody an idea ?
Can it be related to autocommit default value ?
Any link to requirements for Oracle user when using liquibase ?
So the issue ended up being an Oracle user misconfiguration by DBA, he had no privileges on tablespace.
But this issue didn't appear in logs.
Once I removed liquibase context:
spring.liquibase.contexts
The issue appeared clearly:
ORA-01950 : no privileges on tablespace ....
I have a Oracle UCP connection Pool responsible for executing queries from the Java application. I want to see all the queries in the logs that this UCP takes care of.
I followed this guide https://docs.oracle.com/cd/E11882_01/java.112/e12265/dgn_conpool.htm#CIHIGBIJ to use the property of 'oracle.ucp.level' to set the log level to FINEST.
I couldnt see the sql queries in logs. I could see all other information like getting a connection, DB URL etc in the logs but I couldnt see the SELECT query that was executed by this connection pool.
Is there a way we could see the SELECT, INSERT and UPDATE queries executed by the Oracle UCP ?
If not the whole query , Atleast can we see whether it is a SELECT or INSERT or UPDATE ?
I have a Spring Boot (1.5.5) application using Hibernate (5.4.0) to query Oracle database. The application is deployed on WebLogic 12c. One of its query sometimes (50%) timed out (timeout set to 2 minutes). This query is to join two tables (one of the tables has 25 million rows; the other has 800K rows), aggregate and get the count on a column.
When the application runs on Tomcat (which comes with SpringBoot), this query always works fine. I also check the execution plan and the query is fast enough (10 seconds on Oracle SQL developer).
I wonder why sometimes this query timed out when the application runs on WebLogic.
Thank you in advance for your help.
I'm trying to integrate Hibernate into my Netbeans project to connect to Microsoft SQL Server. I've run the Hibernate Configuration file wizard (and set up a new database connection). I've set the dialect to SqlServerDialect. I initially set up the connection with the db_owner schema. I've run test queries on the connection and they all return the correct information.
However, when I try to run either the Hibernate Mapping wizard or the Hibernate Reverse Engineering wizard, there are no available tables to select.
I'm using the JDBC from Microsoft (version 4). There are other similar questions already posted, but no answers that have been provided work.
It turns out I selected the wrong default schema. I selected db_owner and it should have been dbo. When I checked the connection under the services tab and expanded the default schema, it showed no tables. Apparently the SQL executor uses other schemas besides the default to find results.
I'm using hibernate to manage DB operations and MySQL in my application - use org.hibernate.dialect.MySQLInnoDBDialect as the hibernate dialect. But for testing purposes I'm using HSQLDB 1.8.0.10.
I have problem with query like this (working good on mysql not on hsql):
SELECT DISTINCT(id) FROM table ORDER BY name;
I know that the problem is with distinct and order by (http://weblogs.sqlteam.com/jeffs/archive/2007/12/13/select-distinct-order-by-error.aspx ) and solution of this could be for example:
SELECT DISTINCT(id) FROM table GROUP BY id ORDER BY MAX(name);
But my question is, if there is any possibility to using MySQL dialect in HSQLDB and not have to using this solution?
HSQLDB implements the SQL Standard correctly and does not allow the ambiguous query. It is not possible to change its behaviour.
It is better to modify your MySQL queries to be standard compliant. This allows you to port your application to another database more easily.