I need to create DB log events for every DB insert but the the sessionfactory is null in my Hibernate interceptor. What's the simplest way for getting a hibernate session in your interception when you are using spring boot.
public class Interceptor extends EmptyInterceptor {
@Autowired
SessionFactory session; //this is null not in the spring scope
public boolean onSave(Object entity, Serializable id, Object[] state, String[] propertyNames, Type[] types) {
sessionFactory.getCurrentSession()......
You can get hibernate session by injecting @PersistenceContext private EntityManager entityManager;
and then calling entityManager.unwrap(Session.class)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.