Reputation: 12416
I am trying to find out tiny differences in Hibernate update queries and I have come to two interesting possibilities:
@Transactional
.`
Connection connection = entityManager.getDataSource().getConnection();
connection.prepareStatement(...);
affectedRows = ps.executeUpdate();
The second doesn't create transactions, so I guess it could be faster? Consider very simple update queries, for which I don't really need transaction. What is the real difference?
Upvotes: 2
Views: 763
Reputation: 8786
Hibernate is an object-relational mapping tool for the Java programming language. It provides a framework for mapping an object-oriented domain model to a relational database. Most importantly hibernate is quite faster in performance when there's a huge load.
Transaction is an interface that defines the unit of work It maintains abstraction from the transaction implementation (JTA,JDBC). A transaction is associated with Session. So to get maximum out of hibernate you need transaction. If not there's no point of using hibernate at all.
The main advantage of hibernate is that it can handle many requests at once and it's easy to use, but if you have less than 50 requests per minute don't use hibernate it's just a waste of RAM.
Read more,
Upvotes: 1