Слайд 6POJO - Plain Old Java Object
Слайд 7POJO - Plain Old Java Object
Слайд 8POJO - Plain Old Java Object
@Entity
@Table
public class Person implements Serializable {
private
static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Integer id;
@Column
private Integer age;
@Column
private String name;
@Column
private String surname;
public Person() {
}
Слайд 9POJO - Plain Old Java Object
Слайд 11DAO Architect
POJO OBJECTS
Jdbc/Hibernate
Persistence
Слайд 13СОХРАНЕНИЕ ДАННЫХ В СУБД С ПОМОЩЬЮ HIBERNATE
Слайд 16Файл настройки Hibernate (hibernate.cfg.xml)
Слайд 21Операция сохранения сущности
public class BaseDao implements Dao {
private static Logger log
= Logger.getLogger(BaseDao.class);
private Transaction transaction = null;
public BaseDao() { }
public void saveOrUpdate(T t) throws DaoException{
try {
Session session = util.getSession();
transaction = session.beginTransaction();
session.saveOrUpdate(t);
log.info("saveOrUpdate(t):" + t);
transaction.commit();
log.info("Save or update (commit):" + t);
} catch (HibernateException e) {
log.error("Error save or update PERSON in Dao" + e);
transaction.rollback();
throw new DaoException(e);
}
}