Last active
September 21, 2019 10:03
-
-
Save AppLoidx/04bb8e6ea0582f32cc20ff4bfd3da9f5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ...HibernateSessionFactoryUtil; | |
import org.hibernate.Session; | |
import org.hibernate.Transaction; | |
/** | |
* | |
* Базовые операции для DAO (CRUD без R) | |
* Необходимо настроить HibernateSessionFactoryUtil который может возвращать SessionFactory | |
* | |
* @author Arthur Kupriyanov | |
*/ | |
public class DAOBasicOperations<T> { | |
public void save(T obj) { | |
Session session = HibernateSessionFactoryUtil.getSessionFactory().openSession(); | |
Transaction tx1 = session.beginTransaction(); | |
session.save(obj); | |
tx1.commit(); | |
session.close(); | |
} | |
public void update(T obj) { | |
Session session = HibernateSessionFactoryUtil.getSessionFactory().openSession(); | |
Transaction tx1 = session.beginTransaction(); | |
session.update(obj); | |
tx1.commit(); | |
session.close(); | |
} | |
public void delete(T obj) { | |
Session session = HibernateSessionFactoryUtil.getSessionFactory().openSession(); | |
Transaction tx1 = session.beginTransaction(); | |
session.delete(obj); | |
tx1.commit(); | |
session.close(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment