我下面就Hibernate的教程,看到下面的代碼:休眠堅持不交易
package com.websystique.spring.dao;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
public abstract class AbstractDao {
@Autowired
private SessionFactory sessionFactory;
protected Session getSession() {
return sessionFactory.getCurrentSession();
}
public void persist(Object entity) {
getSession().persist(entity);
}
public void delete(Object entity) {
getSession().delete(entity);
}
}
我在想,如果persist()
(或save()
或delete()
)而不事務中使用?在這裏似乎是這種情況。
我會通過,這是爲各種各樣的原因非常差代碼注意。理想情況下,使用Spring Data JPA(並使用構造函數注入)。 – chrylis
感謝,將調查那些 – Liumx31