Spring JPA: Query builder versus Criteria Builder , which one to use? - orm

I am going to start new project that would play with very large database, thus would be having lots of database operation.
I have decided to use Spring JPA as my ORM. Now Spring JPA provides various techniques to use in DAO layer. I am confused between Criteria builder and Query DSL. Both seems to solve my problem well and I guess there is not point using both of them in a same project because they provide same functionality.
So now which one to use and why ?

The JPA 2 Criteria API and Querydsl are equivalent in functionality, but Querydsl has been designed to be more fluent and look more like JPQL/SQL. So it can be used as a replacement for both JPQL and JPA 2 Criteria.
Here is also a blogpost on the topic which shows how compact Querydsl queries are in comparison to the JPA 2 Criteria API Querydsl as an alternative to the JPA 2 Criteria API
This answer is biased, since I am behind Querydsl.

Related

Can I use SQL Queries instead of Entity framework in .NET Core clean architecture?

While researching about the clean architecture of .NET Core, I understand that only Entity Framework is being used.
I wanted to know whether we can use raw SQL queries by making a connection to SQL with connection strings.
Clean architecture doesn't restricts you to entity frame work. You can also look into micro ORM e.g. Dapper which can be used to write sql queries. It's very powerful and gives you many out of box capabilities e.g. mapping. Infact if you don't want full ORM functionality Dapper is recommended in Microsoft docs.
Dapper
Dapper for read queries

Are EclipseLink's COLUMN and TABLE functions DBMS independent?

If you read this EclipseLink's User-/Developer Guide it doesn't mention whether the TABLE and COLUMN functions are database independent and I'm not sure at all if i should use them considering that i'm working with some oracle, postgres and sqlserver databases.
Question
Are these functions DBMS independent?
The very first sentence of that UserGuide gives a an important piece of information:
The Java Persistence Query Language (JPQL) is the query language defined by JPA. JPQL is similar to SQL, but operates on objects, attributes and relationships instead of tables and columns.
That is, JPQL != SQL in a strict sense. JPQL is a query language for the purpose to query object in an environment of an object relational mapper (ORM). In this context, an ORM abstracts the actual DBMS ("the SQL world"). EclipseLink fully implements standard JPQL as defined in the JPA specification documents (versions 1, 2.0, 2.1, 2.2).
Moreover, EclipseLink
provides many extensions to the standard JPA JPQL. These extensions provide access to additional database features many of which are part of the SQL standard, provide access to native database features and functions, and provide access to EclipseLink specific features. EclipseLink JPQL extensions are referred to as the EclipseLink Query Language (EQL).
What does this mean for
COLUMN operation to allow querying on non mapped columns, and
TABLE operation to allow querying on non mapped tables?
EQL is an extension of the basic ORM implementation of EclipseLink to provide you an enhanced way of querying objects and meta-information of their corresponding database columns. This is implemented specific for each vendor - depending on the configured JPA dialect - OR as vendor-neutral as possible.
In essence, it should be safe to use these functions as far as different DBM systems are concerned. Still, you will bind your application to EclipseLink once and for all, robbing yourself the possibility to switch to different JPA providers, e.g. Hibernate, in case you want to experiment or for reasons of performance.
Hope it helps.

Perform pure sql query using Fluent NHibernate in asp.net mvc4

how to perform a pure SQL join query using Fluent NHibernate and send the result to the view from controller in asp.net mvc4
You may use the HQL query interface of nhibernate. The HQL language is designed to be independent of database provider.
All common joins can be expressed in HQL. Please read chapter 14 of the nhibernate documentation (with examples at chapter 14.12).

linq to sql, why to use it in MVC instead of traditional queries?

is it necessary to use LINQ for sql purposes in MVC ? can't we use traditional queries like:
Select name from tbl where id = 2;
instead of LINQ ? and why linq in any case ?
ASP.NET MVC in no way restricts your choice of data access technology. In fact, model binding works with objects, and MVC has no idea whether your objects represent some database or not.
Besides, if you were to use LINQ at all, you would do best to use Entity Framework (a.k.a. LINQ to Entities) and not LINQ to SQL, which is much more limited.
Linq to SQL, EntityFramework, nHibernate - are ORM (Object-relational mapping) tools. ORM represent database objects as standard .NET classes.
Raw SQL can be used, when you are inserting a lot of data, and you need a good performance. In all other cases you should to use ORM.
And if you decide to use ORM, I advise you to use EntityFramework; it's more powerful than LINQ to SQL.
You don't need to use linq at all. I usually use dapper.net for my data layer, mapping SQL queries to objects. It's personal preference.
You are not obliged to use Entities Framework, as you are not obliged to use anything in particular.
Microsoft strongly suggests using the Entities Framework because it is an ORM integrating very easily with the whole Microsoft ecosystem, using the LINQ query language which is integrated in the .NET languages specification. This integration happens through the Linq to Entities query language and the respective tools provided in Visual Studio.
As you will see, Entities Framework (as every other ORM) has the overhead of the learning but in my opinion, it totally pays you back as using an ORM leads to faster development and more maintainable source code. I would strongly suggest using an ORM (it has many advantages) and I suppose since you are already familiar with Microsoft ecosystem, Entities Framework would be the best choice.
Hope I helped!
Well, if you want to use this style of queries you can use stored procedures this is to close to the normal query, just and a Linq-to-SQL file into your project and drag and drop you stored procedures then you can use them like methods and this is a link http://msdn.microsoft.com/en-us/library/bb386946.aspx
Note that Linq-to-SQL is integrated only with SQL Server
No, you do not have to use LINQ at all, or any other ORM frameworks, you an work directly against a database.
In .Net this is typically done using ADO.Net, for example using the System.Data.SQL namespace.
See code examples and official documentation here

Is NHibernate LINQ stable and do all NHibernate bolt on projects allow it

I have been a long time user of Subsonic due to its ease of use and LINQ integration.
I now have to use something else because I need to be able to use Oracle.
I have 2 databases with the same schema therefore I want to have 1 set of POCO's and then change a connection string to switch between SQL & Oracle depending on the requirements.
Is this possible firstly, is LINQ fully functioning and stable in NHibernate and do Castle ActiveRecord and Fluent Hibernate allow the LINQ querying?
It is stable.
It is not fully functioning, and it is not planned to be fully functioning. I don't think there exists linq providers supporting 100% everything. The question should be: "Is it fully function for the queries you need to execute?" (The answer to that question would be yes in 99% of the cases)
You can find reported bugs/missing features in Jira
Fluent NHhibernate doesn't do any querying, just mapping. Castle active record doesn't query either. The linq namespace does not have a reference to active record or fluent and vise versa.
I wouldn't classify the NHibernate LINQ implementation as stable yet. The LINQ provider is still fairly young, so chance of hitting an unsupported query scneario still may be considerable in my opinion. However, other NHibernate query options are plentiful to workaround any issues the LINQ provider might throw up.