How to flush data into db inside active spring transaction?

Finally I stuck to the following solution: First, my @Test methods are not running within spring @Transactional support. See this article to know how dangerous it may be. Next, instead of using @Repository beans inside @Test methods I autowire @Service beans which use @Transactional annotation. The miracle is that @Test method like this @Test @Transactional(propagation … Read more

Spring Transactions and hibernate.current_session_context_class

When using spring and spring managed transactions never mess around with the hibernate.current_session_context_class property UNLESS you are using JTA. Spring will by default set its own CurrentSessionContext implementation (the SpringSessionContext), however if you set it yourself this will not be the case. Basically breaking proper transaction integration. The only reason for changing this setting is … Read more

Hibernate: Difference between session.get and session.load

From the Hibernate forum: This from the book Hibernate in Action. Good one read this.. Retrieving objects by identifier The following Hibernate code snippet retrieves a User object from the database: User user = (User) session.get(User.class, userID); The get() method is special because the identifier uniquely identifies a single instance of a class. Hence it’s … Read more