Examples of Cat


Examples of org.hibernate.ejb.test.Cat

*/
public class CallbacksTest extends TestCase {

  public void testCallbackMethod() throws Exception {
    EntityManager em = factory.createEntityManager();
    Cat c = new Cat();
    c.setName( "Kitty" );
    c.setDateOfBirth( new Date( 90, 11, 15 ) );
    em.getTransaction().begin();
    em.persist( c );
    em.getTransaction().commit();
    em.clear();
    em.getTransaction().begin();
    c = em.find( Cat.class, c.getId() );
    assertFalse( c.getAge() == 0 );
    c.setName( "Tomcat" ); //update this entity
    em.getTransaction().commit();
    em.clear();
    em.getTransaction().begin();
    c = em.find( Cat.class, c.getId() );
    assertEquals( "Tomcat", c.getName() );
    em.getTransaction().commit();
    em.close();
  }
View Full Code Here

Examples of org.hibernate.ejb.test.Cat

    em.close();
  }

  public void testEntityListener() throws Exception {
    EntityManager em = factory.createEntityManager();
    Cat c = new Cat();
    c.setName( "Kitty" );
    c.setLength( 12 );
    c.setDateOfBirth( new Date( 90, 11, 15 ) );
    em.getTransaction().begin();
    int previousVersion = c.getManualVersion();
    em.persist( c );
    em.getTransaction().commit();
    em.getTransaction().begin();
    c = em.find( Cat.class, c.getId() );
    assertNotNull( c.getLastUpdate() );
    assertTrue( previousVersion < c.getManualVersion() );
    assertEquals( 12, c.getLength() );
    previousVersion = c.getManualVersion();
    c.setName( "new name" );
    em.getTransaction().commit();
    em.getTransaction().begin();
    c = em.find( Cat.class, c.getId() );
    assertTrue( previousVersion < c.getManualVersion() );
    em.getTransaction().commit();

    em.close();
  }
View Full Code Here

Examples of org.hibernate.ejb.test.Cat

  }


  public void testPostPersist() throws Exception {
    EntityManager em = factory.createEntityManager();
    Cat c = new Cat();
    em.getTransaction().begin();
    c.setLength( 23 );
    c.setAge( 2 );
    c.setName( "Beetle" );
    c.setDateOfBirth( new Date() );
    em.persist( c );
    em.getTransaction().commit();
    em.close();
    List ids = c.getIdList();
    Object id = c.getIdList().get( ids.size() - 1 );
    assertNotNull( id );
  }
View Full Code Here

Examples of org.hibernate.ejb.test.Cat

    in.close();
    byteIn.close();
    EntityManager em = seriallizedFactory.createEntityManager();
    //em.getTransaction().begin();
    //em.setFlushMode( FlushModeType.NEVER );
    Cat cat = new Cat();
    cat.setAge( 3 );
    cat.setDateOfBirth( new Date() );
    cat.setLength( 22 );
    cat.setName( "Kitty" );
    em.persist( cat );
    Item item = new Item();
    item.setName( "Train Ticket" );
    item.setDescr( "Paris-London" );
    em.persist( item );
    //em.getTransaction().commit();
    //em.getTransaction().begin();
    item.setDescr( "Paris-Bruxelles" );
    //em.getTransaction().commit();

    //fake the in container work
    ( (HibernateEntityManager) em ).getSession().disconnect();
    stream = new ByteArrayOutputStream();
    out = new ObjectOutputStream( stream );
    out.writeObject( em );
    out.close();
    serialized = stream.toByteArray();
    stream.close();
    byteIn = new ByteArrayInputStream( serialized );
    in = new ObjectInputStream( byteIn );
    em = (EntityManager) in.readObject();
    in.close();
    byteIn.close();
    //fake the in container work
    em.getTransaction().begin();
    item = em.find( Item.class, item.getName() );
    item.setDescr( item.getDescr() + "-Amsterdam" );
    cat = (Cat) em.createQuery( "select c from " + Cat.class.getName() + " c" ).getSingleResult();
    cat.setLength( 34 );
    em.flush();
    em.remove( item );
    em.remove( cat );
    em.flush();
    em.getTransaction().commit();
View Full Code Here

Examples of org.hibernate.ejb.test.Cat

  public void testEventOverriding() throws Exception {
    EventListeners eventListeners = configuration.getEventListeners();
    assertEquals( 2, eventListeners.getPreInsertEventListeners().length );
    eventListeners.setPreInsertEventListeners( new PreInsertEventListener[]{} );
    Cat cat = new Cat();
    cat.setLength( 3 );
    cat.setAge( 34 );
    cat.setName( "Did" ); //should raise a validation exception
    EntityManager em = configuration.createEntityManagerFactory().createEntityManager();
    em.getTransaction().begin();
    try {
      em.persist( cat );
    }
View Full Code Here

Examples of org.hibernate.ejb.test.Cat

  public void testEventPerProperties() throws Exception {
    EntityManagerFactory emf = Persistence.createEntityManagerFactory( "manager1", new HashMap() );
    EntityManager em = emf.createEntityManager();
    em.getTransaction().begin();
    Cat cat = new Cat();
    cat.setLength( 3 );
    cat.setAge( 34 );
    cat.setName( "Did" ); //should raise a validation exception
    try {
      em.persist( cat );
    }
    catch (Exception e) {
      fail( "The validation framework is still activated" );
View Full Code Here

Examples of org.hibernate.ejb.test.Cat

    Ejb3Configuration conf = new Ejb3Configuration();
    conf.addAnnotatedClass( Cat.class );
    conf.addProperties(getProperties());
    EntityManagerFactory emf = conf.buildEntityManagerFactory();
    EntityManager em = emf.createEntityManager();
    Cat cat = new Cat();
    cat.setAge( 23 );
    cat.setDateOfBirth( new Date() );
    cat.setLength( 32 );
    cat.setName( "Tomy" );
    em.getTransaction().begin();
    em.persist( cat );
    em.flush();
    assertNotNull( em.find(Cat.class, cat.getId() ) );
    em.getTransaction().rollback();
    emf.close();
  }
View Full Code Here

Examples of org.hibernate.ejb.test.Cat

    Ejb3Configuration conf = new Ejb3Configuration();
    conf.configure( "org/hibernate/ejb/test/ejb3configuration/hibernate.cfg.xml" );
    conf.addProperties(getProperties());
    EntityManagerFactory emf = conf.buildEntityManagerFactory();
    EntityManager em = emf.createEntityManager();
    Cat cat = new Cat();
    cat.setAge( 23 );
    cat.setDateOfBirth( new Date() );
    cat.setLength( 32 );
    cat.setName( "Tomy" );
    em.getTransaction().begin();
    em.persist( cat );
    em.flush();
    assertNotNull( em.find(Cat.class, cat.getId() ) );
    em.getTransaction().rollback();
    emf.close();
  }
View Full Code Here

Examples of org.hibernate.ejb.test.Cat

*/
public class CallbacksTest extends TestCase {

  public void testCallbackMethod() throws Exception {
    EntityManager em = getOrCreateEntityManager();
    Cat c = new Cat();
    c.setName( "Kitty" );
    c.setDateOfBirth( new Date( 90, 11, 15 ) );
    em.getTransaction().begin();
    em.persist( c );
    em.getTransaction().commit();
    em.clear();
    em.getTransaction().begin();
    c = em.find( Cat.class, c.getId() );
    assertFalse( c.getAge() == 0 );
    c.setName( "Tomcat" ); //update this entity
    em.getTransaction().commit();
    em.clear();
    em.getTransaction().begin();
    c = em.find( Cat.class, c.getId() );
    assertEquals( "Tomcat", c.getName() );
    em.getTransaction().commit();
    em.close();
  }
View Full Code Here

Examples of org.hibernate.ejb.test.Cat

    em.close();
  }

  public void testEntityListener() throws Exception {
    EntityManager em = getOrCreateEntityManager();
    Cat c = new Cat();
    c.setName( "Kitty" );
    c.setLength( 12 );
    c.setDateOfBirth( new Date( 90, 11, 15 ) );
    em.getTransaction().begin();
    int previousVersion = c.getManualVersion();
    em.persist( c );
    em.getTransaction().commit();
    em.getTransaction().begin();
    c = em.find( Cat.class, c.getId() );
    assertNotNull( c.getLastUpdate() );
    assertTrue( previousVersion < c.getManualVersion() );
    assertEquals( 12, c.getLength() );
    previousVersion = c.getManualVersion();
    c.setName( "new name" );
    em.getTransaction().commit();
    em.getTransaction().begin();
    c = em.find( Cat.class, c.getId() );
    assertTrue( previousVersion < c.getManualVersion() );
    em.getTransaction().commit();

    em.close();
  }
View Full Code Here
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.