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.
Related
I'm currently trying to figure out how powerful ORMs are. I've written pretty simple web applications where you just needed simple CRUD queries and was super happy with the ORM I was using. But for complex analytical queries I didn't even attempt to use the ORM. It might very well be that in the specific cases it was just my limited knowledge. But on a more general note, are there any statements about any ORM that they can / cannot represent any possible SQL query? How powerful are ORMs?
(I'm most familiar with SQLAlchemy of Python)
Please note:
Yes, many ORMs support sending raw SQL. I don't consider that part of the ORM, though. My question is specifically about the ORM part only.
It's subtle. The point of an ORM is to map object to relational constructs. The ORMs I've used (mostly based on the ActiveRecord pattern) do a really good job of mapping basic SQL constructs into the object-oriented development language, and allowing you to reason at the level of an object instance in your app, rather than rows, columns and joins. As you note, this really accelerates CRUD development tasks.
In theory, I think it is possible to represent every SQL Query to an ORM construct (assuming the ORM supports all the SQL constructs in the underlying database engine).
But you probably don't want to. If your application manages orders, having CRUD functionality from the ORM is really useful. But to write the report showing order values by sales person by month in a tabular layout would involve lots of ORM complexity, but could be represented in a fairly simple SQL Query. While the ORM may support every language construct from the underlying database engine, it probably doesn't make any promises about performance.
Is there any java library to build sql queries based on pojos,
Like something similar to hibernate hql queries.
Object sql queries than translated to elastic search sql queries.
Current requirement is to send sql queries through rest apis.
There is jooq library whic can generate for many databases using dialects but currently it doesnt support for EsDriver which is elastic search jdbc driver.
Regards
Rajesh Giriyappa
I find your question a bit confusing. however, I'm gonna mention some facts that might help you.
First of all, elasticsearch is far away from a relational database system. It is a search engine implemented on top of Apache Lucene and stores semi-structured documents in its own data structure called index and it is used for Information Retrieval purposes. having said that, it is impossible to run SQL queries against elasticsearch because obviously it is not an RDBMS.
Furthermore, JPA is targeted only for providing solutions for working with RDBMSs so you can not connect to elasticsearch with JDBC, Hibernate etc.
If you want to connect to elasticsearch in a java application, you should use standard clients provided by elasticsearch itself.
https://www.elastic.co/guide/en/elasticsearch/client/java-rest/7.13/index.html
In my Project iam about to use Hibernate but one create confusion is:
That I Read somewhere:
Hibernate has its own query language, i.e hibernate query language which is database independent
So if we change the database, then also our application will works as HQL is database independent
HQL contains database independent commands
Does it means that we dont have to write stored proceedure and views while using Hibernate in java?
Short answer: You dont have to write any query and/or stored procedure. (Also you can hibernate tell to create/update all required tables for you, during application start.)
Long answer: Hibernate can be used without any manual definition of a query. (Using the EntityManager, you can simple tell hibernate to get everything of user.class from the database.) However it does support HQL as well as SQL-Queries, also.
SQL Queries of course will stop to work, when you switch to another database later on. HQL will work for every Database, because hibernate is able to translate HQL Queries to any (of the supported) Database Languages.
But be aware: In my Opinion Hibernate is damn slow if you let hibernate do all the work. (Hibernate fires a LOT of single Select Queries, when loading entities with complex relations)
After seeing this image:
http://2.bp.blogspot.com/_T-uXeKcGTnM/TIdoKBGwk9I/AAAAAAAABcs/CLW3_cRlN78/s1600/tumblr_kxovt0VLZy1qappj8.png
I wonder is exists any tool for translating SQL querys into MongoDB map/reduce query model??
Larger version of the image: http://rickosborne.org/download/SQL-to-MongoDB.pdf
Update to the question asked in Jan 2011:
A couple of sites exist now to convert sql to mongodb.
Convert MySQL Queries to MongoDB Syntax
http://www.querymongo.com/
And
Convert sql to mongodb
http://klaus.dk/sqltomongodb/
The simple anwser? No.
The slightly more complex anwser is some people have had luck translating more complex SQL to Mapreduce functions ...
http://rickosborne.org/blog/index.php/2010/02/08/playing-around-with-mongodb-and-mapreduce-functions/
http://rickosborne.org/blog/index.php/2010/02/19/yes-virginia-thats-automated-sql-to-mongodb-mapreduce/
However, that said ... generally speaking you might as well learn mapreduce properly because if the data is in MongoDB already ... you'll really need to know how to properly query MongoDB to get anything meaningful done!
MongoDB has wonderful and helpful docs http://www.mongodb.org/display/DOCS/Advanced+Queries
As well as an easy to use online tutorial: http://try.mongodb.org/
The simple answer: Yes. Hibernate OGM - JPA for NoSQL.
JPA is Java API for mapping objects to data stores.
It includes JPQL, a query language similar to SQL which adds the OOP concepts. It's not SQL, but you don't want pure SQL - that was designed for the relational paradigm.
Hibernate OGM proposes to simplify the programming model by embracing JPA/Hibernate APIs and semantics to store data in NoSQL stores like JBoss Enterprise Data Grid instead of the traditional RDBMS. (source)
Also see this Hibernate OGM: JPA for NoSQL talk by Hardy Ferentschik
Recently I happened to see this website mongoquery.com, you can try it.
You can use free sql to mongodb converter like: https://rapidapi.com/ariefsam/api/easy-sql-to-mongodb-aggregation/
Just to add to the last comment
re:The simple answer: Yes. Hibernate OGM - JPA for NoSQL.
JPA is Java API for mapping objects to data stores.
It includes JPQL, a query language similar to SQL which adds the OOP concepts. It's not SQL, but you don't want pure SQL - that was designed for the relational paradigm.
There is a company called UnityJDBC that has released a JDBC driver for Mongo that allows you to run SQL queries against mongo in any java application that supports JDBC.
you can download this driver free at
http://www.unityjdbc.com/mongojdbc/mongo_jdbc.php
hope this helps
You can also http://teiid.org which gives full range of SQL based access to MongoDB. You can use SQL through JDBC/ODBC or use REST/ODATA based access to MongoDB. Teiid uses MongoDB's aggregation framework to provide advanced SQL MongoDB query conversation.
I'm wondering if its possible to do ORM using SQL.2003 object types (aka STRUCTs, aka non-scalar types).
The idea behind that is to avoid the "n+1 selects" problem by retrieving complete objects directly from the database. Sort of eager "FetchMode.JOIN", but in the database.
Are there any ORM frameworks fpor Java or .Net which support SQL object types at all?
At least JDBC has the getObject method and I've also found an example of user-defined types in ADO.Net
As an Oracle developer, I may be biased towards database-centric approaches and I also didn't use ORM before. But Oracle features Object Views which let you compose objects from several relational tables. I bet these could be magnitudes faster than pulling all those single records out of the database, let alone issuing n+1 selects.
I am the developer of jOOQ, and I am striving to make jOOQ exactly what you need. jOOQ currently supports any of these Oracle features:
All types of SQL constructs, including nested selects, aliasing, union operations, etc
Stored procedures and functions
Packages
VARRAY types (mapped to Java arrays)
UDT types (mapped to Java objects)
combinations thereof
More support will be added in the near future, for advanced Oracle concepts such as
TABLE types
CURSOR, REF CURSOR types
Other collection types
Object views are currently not supported in the way you described, but I'll clearly put them on the roadmap.
See more on http://www.jooq.org