Reasons to use a persistence framework in Java EE? - spring

I'm working on a Java EE Application, and I use Spring as framework.
Now I've seen people talking about ORM Frameworks (Hibernate/JPA/iBatis...) but I don't know what might be the reasons to use those frameworks?
I mean what those frameworks will change in the project functions & performance?
if you can give me a clear example it will be great.

Since you will get bored by writing the SQL insert/update/select statements for entire java objects and keep the Object <-> SQL code in shape when your object changes. JPA is actually a part of the Java EE standard.
However, it will not provide any means to keep you from knowing what you are doing with the database, except for very simple cases. My experience is that any JPA framework will add just another layer of complexity to performance issue track down and debugging.
In the end, you might end up need to understand how JPQL (SQL-ish syntax for JPA) translate into SQL for every combination of JPA provider (OpenJPA, HIbernate, eclipse link..) and datbase implementation. This will be non trivial.
If you have no specific performance requirements and just want easy object persistance, give it go! Hibernate seems to be state of the art atm.

To avoid writing your own SQL for everything, and to [partially] bridge the object-relational gulf ("abyss").
For simple requirements, ORMs are great, and make thinking about some DB stuff go away--with the caveat that you still need to be aware of what's actually happening on the DB side to prevent what can be serious performance implications.
For complicated requirements, you'll learn to understand why they call ORMs the "Vietname of computer science"... "We have learned the lessons of Vietnam... do not go to Vietnam."

Related

Is there a way to use Panache in Quarkus in a "standalone way"

I use Quarkus for my backend application since few months and today i have a specific use case :
I have a lot of database (sqlite) and it's not possible for me to specify all of this database in the application.propertie. So, i wrote some code, using agroal, to access to my database. The thing is that, if I do that, i am wondering how i can mix that with panache ?
Panache & panache entity is really nice and easy to use, but in my case, i'm a little bit on the edge of the framework and i can't find a good way to do what i need.
By managing my databases by myself and agroal as a pool, it's "low level" and i can't find how to use the power of Panache instead of writing all SQL query by hand.
Thank'a a lot.

Spring Data Neo4j (SDN) 4.0 runtime polymorphism

Spring Data Neo4j (SDN) 4.0 did away with #RelationshipType and #Labels, among other tools that could be used to implement dynamic typing or runtime polymorphism. In SDN 4.0 all polymorphic possibilities (labels and relationship types) must be modeled explicitly, statically, in Java prior to build time. Given those limitations, I am unable to migrate my SDN 3.x code, which took advantage of those features, forward.
I would appreciate any insight, work arounds, alternative tools, etc. anyone has to offer. The only alternative right now that I see is to unplug SDN and write directly to Neo4j.
Thanks
We're very aware that the lack of runtime polymorphism is currently frustrating some SDN 3 users who want to migrate to SDN 4. And while there may be workarounds in many cases, we also accept that having to refactor application code is not ideal.
We do want to address this, however to enable runtime polymorphism will require both architectural and implementation changes, so its not something we can expect to accomplish in just a few days. Unfortunately, right now we can't commit to when we will be in a position to start that work, because the product road map is still being discussed with the development team and the product owner, Neo Technology.
If you can stay with SDN 3 that might be the best option right now until this feature is available in SDN 4.

Spring slow performance at "Web Framework Benchmarks" website

It looks like the performance of Spring (Boot) is relatively low compare to other frameworks at "Web Framework Benchmarks" website Web Framework Benchmarks. I looked at the source code (JSON serialization) and could not find anything odd. So I am wondering whether the low performance is caused by Tomcat or by the framework itself?
Slow? It seems to be more or less in the middle of the ranks. Which doesn't seem too bad considering that it is actually a framework. The definition of framework for that set of benchmarks is very liberal, given that it includes benchmarks for a pretty raw Undertow application and another for a raw Servlet.
But given that the Spring benchmark itself is running on Undertow, it wouldn't be Tomcat causing the issue. :)
Looking at the source for the various benchmarks, they are really not comparing like for like. For example, the Spring benchmark project builds a reasonably standard multi-tiered application with ORM entities mapped with JPA and Hibernate, re-usable repository classes, etc.
On the other hand the Wicket application just has a controller with a JDBC call. It even uses a hand-cranked template for generating JSON. You could write a Spring application that way if you wanted to, but nobody would be impressed.
The Undertow benchmark again does little more than query a database with JDBC and spit out a response. It's not surprising that it would be faster than itself with a full stack framework running on it.
Of course, they hopefully get you to think about your priorities in writing an application. Do you want a full stack framework, which lets you write less code, provides various security features, helps you to achieve code re-use, and make your application more testable and maintainable? Or are you willing to sacrifice all that for speed?

Usecase of Spring DAO

I'm wondering what is the typical usecase of Spring DAO where we can easily switch between different persistence frameworks.
Apart from abstracting the boiler-plate code (for JDBC, Hibernate like) Why does any application want to change its ORM frameworks so frequently?
By using a DAO pattern with a distinct DAO interface, this enables you to mock the DAO implementation. With this you improve testability of your code, as you are then able to write tests that do not need database access.
It is not only about frequently being able to switch between ORM frameworks, but is also about reducing effort if you are enforced to change the ORM.
Another reason is, that you might have different data sources like a database, a webservice or the file system for example. In this case you don't abstract the ORM but simply the persistence mechanism in general.
I think the real important idea behind DAOs are that you have just one spot where all data access related code for a particular entity ist located. That makes testing and refactoring of your persistence layer easier and your code is better readable.
Furthermore, it makes the code better readable. Think of a new developer in your team that should implement a feature. If she needs to access the databasase she would look into the dao for data access methods.
If you scatter the data access code in different services the risk is pretty high that someone produces code duplicates.

Hibernate, iBatis, Spring JDBC Template, which one to use? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I am developing a web app in java. I am thinking of using Spring MVC. But at ORM side, I have a decision to make. I have studied about ORMs like Hibernate,iBatis, Spring JDBC Template etc.
I find iBatis and Spring JDBC Template (using RowMapper) are almost same, where you map each query to an object. So you have to write a class for each query.
In Hibernate, you map each table with a class.It reduces the need to write SQL.
I guess Hibernate is preferable when you are not good in SQL.In my case, I am quite comfortable in SQL, so want to use iBatis or Spring JDBC Template which will give me good control over SQL and these are less complex than Hibernate.
But Hibernate provide caching which other ORMs do not provide.
So my questions:
Which one to use between iBatis and Spring JDBC Template?
Is Hibernate caching (or any other Hibernate feature which I do not know) so good that I should go with Hibernate instead of other ORMs?
I guess Hibernate is preferable when you are not good in SQL
I disagree with the idea that you should use Hibernate, or any other ORM because you're not very good at SQL.
Whilst it's true that Hibernate will generate your SQL for you, not understanding what it's doing is a recipe for a performance disaster.
As a Hibernate developer I am pretty good at SQL too ;) In fact the beginning of my career was working exclusively with relational (and even some pre-relational) databases. Anyway I really don't get this misconception that hand writing SQL being "more maintainable" or giving "better control". But if you do buy into that misconception then you can actually tell Hibernate the SQL you want it to use for all CRUD operations pertaining to each and every entity (see #SQLInsert, #SQLUpdate, etc).
Again, I find that not nearly as maintainable. Personally, I would much rather have Hibernate manage the INSERT/UPDATE/DELETE SQL for me. Loading data on the other hand is a situation where I generally want a little more control. But Hibernate (and JPA providers in general) already give you this kind of control through HQL/JPQL and Criteria queries. In my opinion, if you are relying on Session.get you are simply asking for bad performance. And that has nothing to do with using O/RM. That's just not good data loading plan because the amount of data you need (even related to the same entity) is different based on the application use case. For example, loading Employees for a drop-down list requires much different amount of data from generating a departmental roster. And thats the control.
By all means use what feels most comfortable to you and meets the goals/requirements of the application. Just make sure your comparison points between technologies and products are factual and not just misconception.
Caching is a fair point with regard to O/RM. In fact JPA (as of 2.0) requires some level of caching. However, be aware that caching at the O/RM level often leads to worse performance. You really need to understand the semantics of the particular data you would like to cache. Some data is good candidate for caching, some are not. Also, it is often much better to cache "above" the O/RM level.
Personally I would choose Hibernate because I believe (1) it strikes the best balance between abstraction while still giving access to SQL power (this is largely true of JPA providers in general) and (2) it has the most complete feature set of any persistence provider out there.
Well, your choice should depend of what you are developing the application for. I would say that Hibernate is the more powerful among the above mentioned ORMs and has a strong community and caching is really strong. But really strong caching is sometimes a problem and has it's memory intensive.
Am a myBatis user and believe it's a mid-way and provides all that you need. Well, myBatis would be my personal choice over Spring JDBC template.

Resources