Package net.fp.rp.hibernate

Source Code of net.fp.rp.hibernate.HibernateDBTest

/**
*
*/
package net.fp.rp.hibernate;

import java.util.List;

import junit.framework.TestCase;

import org.hibernate.Session;
import org.hibernate.Transaction;


/**
* Test the manipulation of the Hypersonic DB using Hibernate
* @author Paul Browne
* Copyright @link www.firstpartners.net/red
*/
public class HibernateDBTest extends TestCase {

  public void testReadHibernate() throws Exception {

    Session session = HibernateHelper.currentSession();
    session.beginTransaction();
    List result = session.createQuery("from Test").list();
    for (int i = 0; i < result.size(); i++) {
      Test tst = (Test) result.get(i);
      System.out.println(tst.getFirstname() + " " + tst.getName());
    }
    session.getTransaction().commit();
    System.out.println("testReadHibernate Done");
  }

  public void testUpdateHibernate() throws Exception {

    Session session = HibernateHelper.currentSession();
    session.beginTransaction();
    List result = session.createQuery("from Test").list();
    for (int i = 0; i < result.size(); i++) {
      Test tst = (Test) result.get(i);
      tst.setZip(new Integer((int) System.currentTimeMillis()));
    }
    session.getTransaction().commit();
    System.out.println("testUpdateHibernate Done");
  }

  public void testWriteHibernate() throws Exception {

    Session session = HibernateHelper.currentSession();

    Transaction tx = session.beginTransaction();

    Test princess = new Test();
    princess.setName("Princess");
    princess.setFirstname("Fiona");
    princess.setId(new Integer(11));
    princess.setZip(new Integer(00001));
    princess.setName("shrek");

    session.save(princess);
    tx.commit();
    session.getTransaction().commit();

    HibernateHelper.closeSession();

    System.out.println("testWriteHibernate Done");
  }

}
TOP

Related Classes of net.fp.rp.hibernate.HibernateDBTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.