Frage

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?

War es hilfreich?

Lösung

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.

Andere Tipps

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

You might be looking for MyBatis, which is a bit more direct. For an annotation-based example, see here although there are others. You can also just use pure JDBC, or via Spring if you're using Spring.

I don't understand the "not liking caching" thing.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top