NHibernate 'touches' my native ISQLQuery - nhibernate

In the application I'm developing, I am using NHibernate as ORM.
My app has to support SQL Server, and MS Access (I'm using the NHibernate JetDriver).
Now, the thing is that I have a certain query which I cannot achieve using HQL or the ICriteria API; so, I'm using an ISQLQuery for that one.
Now, what bothers me, is that it seems that NHibernate is parsing the native SQL query as well, and thereby changing the SQL code of that query.
It seems that the specific Driver implementation is called, and my query is parsed; and in the case of the JetDRiver, the query is being modified by NHibernate which results in a query that is unexecutable.
So, why is it that NHibernate changes my native SQL queries ?

NHibernate does some changes even in native queries in order to be able to map the entities correctly.
My suggestion... download the JetDriver source from https://nhcontrib.svn.sourceforge.net/svnroot/nhcontrib/trunk/src/NHibernate.JetDriver/ and debug to see what's being broken. It might be a bug there.

Related

Query Builder vs. ORM?

What is the difference between a query builder and an ORM that developers use in their backend server-side code/logic for interacting with their database? It seems like the query builder can fulfill the goal of coding in the same language you are choosing to write the backend server-side code/logic to work with the database. However, I don't understand why an ORM comes in the picture then.
SQL query returns records (scalars) that do not automatically load more data if needed.
ORM can return you a Java object (say Person) with actual working methods that can load more data from database (without writing more queries explicitly).
For example if you call person.getAddress() it can return Address object that's just loads from database on the fly. Without writing new "select address" query.
Whatever is returned form SQL query (builder) does not work like that.

Doctrine2 dbal cache subquery

I have a very expensive subquery that I use for multiple queries in my repository.
I want to find a way to cache that subquery and use it's results in the other native sql queries.
I am using the Doctrine2 DBAL in a symfony2 project.
Native SQL is required due to the complexity of the subquery.
example:
select sum(volume) from ( expensive_subquery );
I have been reviewing Google, and the Doctrine2 documentation but have not found a good solution here.
Other methods are welcome, staying in the confines of the Doctrine2, Symfony2, SQL framework.
You have a lot of options. My first line of action would be to hash the select statement to act as a key and store the results in memcached or something similar. Then in your manager before your run the query. Check to see if the key/cache exists.. If it does,use the cached results.. If the cache didn't exist, create it after the long query runs.. Additionally, you might want to integrate cache expiration.

Execute complex query using Session (coldfusion.air.session class)

We are working on a sync application using ColdFusion 9.0.1 ActionScript ORM Library for AIR applications. Since this is application should work smoothly offline as well, there is a list of clients that has to be loaded when a user logs in, hence we are fetching data from all the required tables when application loads (is that the right way?). Now when we get the data from the required tables then based on the user who logs in we have to filter the clients, to filter this the query required is a complex one with joins between 5-6 tables and where clause. What I found that using the Coldfusion.Air.Session class we can only load objects of tables with simple where clause. There is non ORM way to load the data but I don't think that is the right method. Is there any method using this ORM framework to load data using such complex queries.
Thanks,
Gaurav
Are you using any CF code to send data back to your application? Have you tried HQL?
In other words you can write standard cfquery and dbtype="hql"
This will let you do almost anything you can do with a standard cfquery.
I am not directly familiar with the ActionScript ORM Library for AIR.

static sql for entity in nhibernate log file

I am using nhibernate to query my db and am seeing various statements in my log files as follow -
static sql for entity
static select for entity
version select
snapshot select
followed by queries using my domain entities.
I believe these are common when building a session factory, but I just wanted to make sure. Does anyone know what these entries mean?
thanks for any help.
It's just letting you know the sql it's going to use the predictable queries such as get by id etc. They are created when setting up the session factory and then cached for optimization. Very normal.

NHibernate: Retrieve SQL to be executed as a string

From an ICriteria, is it possible to retrieve a string containing the SQL that NHibernate is planning on executing?
I know that is possible to receive a trace, but I was wondering if there is a method that can be called that generates the SQL (for example, so you don't have to actually flush to the database).
It's not directly exposed anywhere. Keep in mind the generated SQL is dialect, driver and batcher dependant, so generation of the final SQL occurs late in the pipeline.
NHibernate Profiler works great for us. there's a trial available at nhprof.com/
edit: NHProf attaches itself on the connection from your machine to the database and captures any SQL passing by, with the number of results and the time spent on fetching processing. NHProf also gives you all sorts of advice that will improve performance.