I am considering migrating an application from hibernate/MySQL to hibernate-ogm/MongoDB. However my application relies heavily on criteria queries. I see that in 5.4.1 they are not supported yet. Does someone know what are the plans ahead for criteria queries? Should I convert to JP-QL or is it worth waiting for the implementation of criteria queries in hibernate-ogm?
We don't have plans to implement Criteria at the moment.
I wouldn't wait for it.
Related
I am currently working on a project where I have to retrieve some rows from the database based on some filters (I also have to paginate them).
My solution was to make a function that generates the queries and to query the database directly (it works and it's fast)
When I presented this solution to the senior programmer he told me this is going to work but it's not a long-term solution and I should rather use Spring Specifications.
Now here comes my questions :
Why is Spring Specifications better than generating a query?
Is a query generated by Spring Specifications faster than a normal query?
Is it that big of a deal to use hard-coded queries ?
Is there a better approach to this problem ?
I have to mention that the tables in the database don't store a lot of data, the biggest one (which will be queried the least) has around 134.000 rows after 1 year since the application was launched.
The tables have indexes on the rows that we will use to filter.
A "function that generates the queries" sounds like building query strings by concatenating smaller parts based on conditions. Even presuming this is a JPQL query string and not a native SQL string that would be DB dependent, there are several problems:
you lose the IDEs help if you ever refactor your entities
not easy to modularize and reuse parts of the query generation logic (eg. if you want to extract a method that adds the same conditions to a bunch of different queries with different joins and aliases for the tables)
easy to break the syntax of the query by a typo (eg. "a=b" + "and c=d")
more difficult to debug
if your queries are native SQL then you also become dependent on a database (eg. maybe you want your integration tests to run on an in-memory DB while the production code is on a regular DB)
if in your project all the queries are generated in a way but yours is generated in a different way (without a good reason) then maintenance of the will be more difficult
JPA frameworks generate optimized queries for most common use cases, so generally speaking you'll get at least the same speed from a Specification query as you do from a native one. There are times when you need to write native SQL to further optimize a query but these are exceptional cases.
Yes, it's bad practice that makes maintenance a nightmare
This is what is want to achieve using MyBatis cache(or combining with ehCache/others):
-load the entire result set for an aggregate query into cache
-ability to query this result set and apply sql based filter(between start and end dates)
I searched around the web but could not find an answer to this. Please help.
Suggestions welcome.
Ehcache has search API, you can load entries to cache and afterwords search it based on whatever criteria you like, including dates.
Of course this means implementing caching mechanism yourself, maybe by extending EhcacheCache or since you're using Spring maybe extending AbstractCacheManager or EhCacheCacheManager could be an option.
But there should be performance conciderations, since cache is mean not for querying, but for caching, especially standalone Ehcache version.
I have to make some filters, such as get persons who are in a given department, and I was wondering about the best way to do it.
Some of them are going to require the join of multiple tables.
Does anyone know about the main differences between CDbCriteria and Query Builder? I would particularly like to know about the compatibility with databases.
I found this in the Yii documentation about Query Builder:
It offers certain degree of DB abstraction, which simplifies migration to different DB platforms.
Is it the same for the CDbCriteria objects? Is it better?
The concept of CDbCriteria is used when working with Yii's active record (AR) abstraction (which is usually all of the time). AR requires that you have created models for the various tables in your database.
Query builder a very different way to access the database; in effect it is a structured wrapper that allows you to programmatically construct an SQL query instead of just writing it out as a string (as an added bonus it also offers a degree of database abstraction as you mention).
In a typical application there would be little to no need to use query builder because AR already provides a great deal of functionality and it also offers the same degree of database abstraction.
In some cases you might want to run a very specific type of query that is not convenient or performant to issue through AR. You then have two options:
If the query is fixed or almost fixed then you can simply issue it through DAO; in fact the query builder documentation mentions that "if your queries are simple, it is easier and faster to directly write SQL statements".
If the query needs to be dynamically constructed then query builder becomes a good fit for the job.
So as you can see, query builder is not all that useful most of the time. Only if you want to write very customized and at the same time dynamically constructed queries does it make sense to use it.
The example feature that you mention can and should be implemented using AR.
I am looking for a third party component which allows a non technical user to create simple adhoc LINQ queries by dragging and dropping the available fields and run it against a data model that I will be populating using Entity Framework. I've used http://devtools.korzh.com/eq/dotnet/ component previously to generate adhoc SQL queries but I want something similar for LINQ.
I am looking for only simple query generator, the most complex queries will include group by on couple of columns with summation on say revenue field(Or any measure field).
Do any of you guys know of any visually appealing tool already available in the market? If not then may be suggest an approach on how I can build it myself!
Many Thanks
Mithun
Best I have seen is LinqPad, its not the best "visual" query builder out there but it is pretty easy to test out LINQ queries.
(source: linqpad.net)
Actually EasyQuery will support LINQ queries in upcoming version 3.4.0.
You can contact the support team to get access to this functionality on BETA stage.
AFAIK,MySQL performs really bad at this,
what's your solution?
BTW,what's the solution of SO?
EDIT
Please pay attention that free-text search itself is pretty fast in MySQL,
but not the case when the result also needs to be sorted on an attribute!
Apache SOLR (Lucene) is pretty capable.
I think stack overflow uses SQL Server in the background with the built in fulltext search capabilities offered by the database. Oracle offers Oracle intermedia (Oracle 9i), later called Oracle Text, which is very well integrated and efficient. Postgresql offers a standard built-in module called tsearch2. I'm not sure about MySql, but looking at the other 3 databases I've mentioned, fulltext is something that is certainly complex and takes time to mature as a feature.
I recommend Sphinx Search : needs to be configured and some modifications to your code, but really worth it.
On a forum with 1+ million messages, a full-text search takes just a few milliseconds.
SO uses the full-text search capabilities of Microsoft SQL Server, it's been mentioned several times in the podcast and on the blog (ex: https://blog.stackoverflow.com/2008/11/sql-2008-full-text-search-problems/) In this blog entry, Jeff mentions possibly moving to Lucene.net in the future.
I'm currently evaluating Haystack and Solr for searching. in a couple of projects.