package sample;

import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class SampleController {

	private SessionFactory sessionFactory;

	public SampleController(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}

	@RequestMapping("/")
	@Transactional
	public List<SampleEntity> home() {
		return this.sessionFactory.getCurrentSession()
				.createQuery("from SampleEntity se")
				.list();
	}

}

package sample;

import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class SampleController {

	private SessionFactory sessionFactory;

	public SampleController(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}

	@RequestMapping("/")
	@Transactional(readOnly = true)
	public List<SampleEntity> home() {
		return this.sessionFactory.getCurrentSession()
				.createQuery("from SampleEntity se")
				.list();
	}

}

Use readonly transactions where possible
Use readonly transactions where possible
