@SuppressWarnings("unchecked") public static void main(String[] args) { SessionFactory factory = null; Session session = null; org.hibernate.Transaction tx = null; try { factory = HibernateUtil.getSessionFactory(); session = factory.openSession(); tx = session.beginTransaction(); List<Transaction> transactions = session.createCriteria(Transaction.class).addOrder(Order.desc("title")).list(); for (Transaction t : transactions) { System.out.println(t.getTitle()); } tx.commit(); } catch (Exception e) { e.printStackTrace(); tx.rollback(); } finally { session.close(); factory.close(); } }
@SuppressWarnings("unchecked") public static void main(String[] args) { SessionFactory factory = null; Session session = null; org.hibernate.Transaction tx = null; try { factory = HibernateUtil.getSessionFactory(); session = factory.openSession(); tx = session.beginTransaction(); Query query = session.createQuery("select t from Transaction t"); List<Transaction> transactions = query.list(); for (Transaction transaction : transactions) { System.out.println(transaction.getTitle()); } tx.commit(); } catch (Exception e) { tx.rollback(); } finally { session.close(); factory.close(); } }
private static Transaction createNewBeltPurchase(Account account) { Transaction beltPurchase = new Transaction(); beltPurchase.setAccount(account); beltPurchase.setTitle("Dress Belt"); beltPurchase.setAmount(new BigDecimal("50.00")); beltPurchase.setClosingBalance(new BigDecimal("0.00")); beltPurchase.setCreatedBy("Kevin Bowersox"); beltPurchase.setCreatedDate(new Date()); beltPurchase.setInitialBalance(new BigDecimal("0.00")); beltPurchase.setLastUpdatedBy("Kevin Bowersox"); beltPurchase.setLastUpdatedDate(new Date()); beltPurchase.setNotes("New Dress Belt"); beltPurchase.setTransactionType("Debit"); return beltPurchase; }
private static Transaction createShoePurchase(Account account) { Transaction shoePurchase = new Transaction(); shoePurchase.setAccount(account); shoePurchase.setTitle("Work Shoes"); shoePurchase.setAmount(new BigDecimal("100.00")); shoePurchase.setClosingBalance(new BigDecimal("0.00")); shoePurchase.setCreatedBy("Kevin Bowersox"); shoePurchase.setCreatedDate(new Date()); shoePurchase.setInitialBalance(new BigDecimal("0.00")); shoePurchase.setLastUpdatedBy("Kevin Bowersox"); shoePurchase.setLastUpdatedDate(new Date()); shoePurchase.setNotes("Nice Pair of Shoes"); shoePurchase.setTransactionType("Debit"); return shoePurchase; }