Are there any frameworks like Hibernate but no cache and do directly execute SQL?
-
08-12-2019 - |
Question
I have been trying to use Hibernate for a while. I like hibernate that it has annotation mapping ability (such as @Entity, @Column)
But I don't like it caching idea ( How to disable hibernate caching said that it also cannot be disabled).
Also, I totally don't like its 'commits vs flush' idea which not directly run SQL to database when do insert/delete/update some data in database.
So, as my title, are there any frameworks like Hibernate with annotation but no cache and do directly execute SQL? It would be good if such frameworks can use in Spring.
Or, actually, Can Hibernate just disable cache or just have some configuration that can do direct SQL for every insert/delete/update?
Solution
These features are on by default, because you usually need them (even though you don't realize initially).
But if you really want to disable cache and flush everything immediately:
- use
sessionFactory.openStatelessSession()
- this session does not store anything in the 1st level cache (and the 2nd level cache is off by default). Note that you can't operate collection mappings with this session. - use
session.setFlushMode(..)
to set it to flush automatically before very query (rather discouraged).
Note that the flush mode is available only for stateful sessions - the stateless session is flushed immediately.
OTHER TIPS
Hibernate is a great framework, but for more lightweight implementations I tend to use Spring JDBC:
http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/jdbc.html