Java tutorial
package com.matel.pg.dao.impl; import com.matel.domain.Product; import com.matel.pg.dao.ProductDAO; import com.matel.pg.domain.Company; import java.util.List; import java.util.Set; import org.hibernate.Criteria; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.criterion.Order; import org.hibernate.criterion.Restrictions; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.springframework.stereotype.Repository; import org.springframework.transaction.annotation.Transactional; /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ @Transactional @Repository @Component("productDAO") public class ProductDAOImpl implements ProductDAO { @Autowired SessionFactory sessionFactory; @Override public void save(Set<Product> productsToSave) { for (Product product : productsToSave) { System.out.println(".............. QBOID: " + product.getQboProduct().getQboId()); try { Session session = sessionFactory.getCurrentSession(); session.saveOrUpdate(product.getQboProduct()); } catch (Exception e) { e.printStackTrace(); } } // throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } @Override public List<Product> findAll() { List<Product> products = null; try { Session session = sessionFactory.getCurrentSession(); Criteria criteria = session.createCriteria(Product.class); criteria.addOrder(Order.desc("productId")); products = criteria.list(); } catch (Exception e) { e.printStackTrace(); } return products; } }