Hibernate OGM & Hibernate OGM first and second level cache - hibernate-ogm

Will Hibernate OGM supports Cassandra? Since OGM provides JPA support to persist data in NoSQL DBs and it reuses Hibernate core engine, what about first and second level cache? Will OGM supports 1st and 2nd level cache?

Yes supporting Cassandra is on the roadmap; there was an experimental first patch already, but then we stopped evolving it as Cassandra's team was heavily updating their Java client API. Development should resume soon, but we depend on contributors.
Roadmap for Hibernate OGM
And yes you can use 2nd level cache as usual: everything except the storage operations are handled by the usual Hibernate ORM code. Of course some concepts might not be available, for example since Cassandra does not support transactions you won't be able to configure a TransactionManager.

Related

Performance Issues when Upgrading OpenJPA to Hibernate

We upgraded from Open JPA -2.4.3 with Spring 4.3.19.RELEASE to Hibernate-
5.4.8.Final with Spring-5.2.6.RELEASE. We had to change ORM provider since spring 5.0 and related Spring Data did not have an OpenJPA vendor adapter. Upgrade caused Performance issues for our Batch Jobs, they were running 10 times slower than before.
We finally ended up migrating the non performing queries to Native SQL Queries.
From performance dumps it Sessions are not being released after the transaction is committed in Hibernate
Question:
Has anyone encounter similar issues and how they resolved it?
One side note, not sure whether its related or not: we have observed is OpenJPA is using OpenJpa is using WeakHashMap and Hibernate is using Concurrent Hashmap.
[1]: https://i.stack.imgur.com/4hE3V.png - Using OpenJPA
[2]: https://i.stack.imgur.com/sXRiw.png - Using Hiberate

Difference between Apache Open JPA and Spring JPA

I would like to know what's the key difference between Apache Open JPA and Spring JPA.
Spring already has a mature JPA for dealing with all kinds of Java persistence but still saw few projects in my company where they uses Apache Open JPA.
Can we integrate Apache Open JPA with Spring. Also like to know what are key benefits of Open JPA.
for example ElasticPath uses Spring but for JPA they uses Apache Open JPA
First: There is no Spring JPA.
There is spring-orm which is one of the many artifacts published by the Spring Framework. It contains classes dealing with JPA and it's main implementations (Hibernate and EclipsLink) in order to integrate them into the rest of the framework. Most Spring users rarely deal with it directly.
You are probably thinking of Spring Data JPA which offers repositories implemented with JPA, which in turn offer many ways to declare queries: Query derivation from method names, named queries based on method names, annotated queries, query by example, specifications ... It is part of the Spring Data project, which offers similar features with many different persistence technologies (JPA, MongoDb, Couchbase, Elasticsearch, Jdbc, Redis, Ldap ...). Spring Data JPA uses spring-orm
Since it got mentioned a couple of times now it is time to explain JPA: JPA stands for Java Persistence API and is an API which can and is implemented by multiple vendors. Hibernate is the most popular implementation, EclipseLink is the reference implementation and Apache Open JPA is another one.
Spring Data JPA (and spring-orm) are (mostly) based on JPA and therefore you should be able to use Apache Open JPA with it. But development of Open JPA was so slow in recent years that the Spring Data Team dropped OpenJPA from the JPA implementations it tests against.
To get a feeling for the development speed, you might look at the releases from the last three years (2019-2021):
Hibernate: 32 (not counting alpha and beta releases)
EclipseLink: 12 (not counting Milestone and release candidates)
OpenJPA: 4
As for the benefits of Apache Open JPA, I consider that an opinion question and therefore off topic for SO. But since people in your company seem to use it, I suggest asking them why they chose Open JPA over the other implementations.

Is JPA a specification {Eclipselink and hibernate its implementation} how is it related to spring transaction management?

I am new to the ORM and till now whatever i read on the internet , it implies that JPA as just a specification and internally we need to use either eclipselink or hibernate or any other implementation .
But i got confuse when i saw Spring transaction management in one of my application. Is spring also a implementation of JPA
Can anybody explain what what is the actual difference between JPA ,
(EclipseLink.hibernate) , Spring.
JPA is an specification for object relational mapping, coming with a whole lot of interfaces and annotations that implementations must implement and support. One of the features provided by this specification is the ability to use local transactions with the JPA API.
Hibernate and EclipseLink are implementations of this specification.
Spring is a dependency injection framework that, among other things, allows you to handle transactions in a declarative way. But it doesn't come with any actual transaction manager. It just offers a common layer of abstraction over actual transaction management systems, one of them being JPA. But it can also use JDBC transactions, or JTA transactions. You just have to configure it to use the appropriate transaction management subsystem based on your requirements and technology choices.

Auditing in JPA which is similar to Hibernate envers

Does JPA provides any specification for Auditing entities.
The issue is currently we are using Hibernate envers to audit an entity in our application.
I want to move out of this and implement a solution which is generic across ORM layer. as it is just for auditing purpose I have to use Hibernate API in my application
I don't think there is anything in the specification but... if you are using the Hibernate implementation of JPA you could likely use the Envers project with your configuration. Had a look and sure enough there is a guide to do so:
Auditing JPA entities with Hibernate Envers
A useful feature in the JPA specification for auditing is Entity Listeners.
However prior to version 2.1 you could not use injection in them. As of version 2.1 CDI is supported
Hibernate supports JPA 2.1 in version 4.3

Spring Framework Saving Data to Multiple Tables

Newbie here...
I'm working on a Spring MVC app and their JDBC api for data access. How would I go about saving data to multiple tables? The insertion needs to be such that if there's an error or something goes wrong, nothing gets inserted and rolled-back. Would this be Spring's transaction support? If so, the official documentation for transaction support is very confusing to me. Does anyone have a good source for learning how to do that?
I'm using Spring 3.1, Oracle 11g, and Tomcat 6.0
Yes, spring supports transaction. You can use DataSourceTransactionManager to configure your bean.IF you find xml mapping confusing you can use annotation #Transactional. Spring's annotation support for transactions are really simple. Spring in Action book has examples for transaction management.

Resources