Package org.hibernate.test.jpa

Examples of org.hibernate.test.jpa.Item


    final String initialName = "lock test";
    // set up some test data
    Session s1 = getSessions().openSession();
    Transaction t1 = s1.beginTransaction();
    Item item = new Item();
    item.setName( initialName );
    s1.save( item );
    t1.commit();
    s1.close();

    Long itemId = item.getId();

    // perform the isolated update
    s1 = getSessions().openSession();
    t1 = s1.beginTransaction();
    item = ( Item ) s1.get( Item.class, itemId );
    s1.lock( item, LockMode.UPGRADE );
    item.setName( "updated" );
    s1.flush();

    Session s2 = getSessions().openSession();
    Transaction t2 = s2.beginTransaction();
    Item item2 = ( Item ) s2.get( Item.class, itemId );
    assertEquals( "isolation not maintained", initialName, item2.getName() );

    t1.commit();
    s1.close();

    item2 = ( Item ) s2.get( Item.class, itemId );
    assertEquals( "repeatable read not maintained", initialName, item2.getName() );
    t2.commit();
    s2.close();

    s1 = getSessions().openSession();
    t1 = s1.beginTransaction();
View Full Code Here


    final String initialName = "lock test";
    // set up some test data
    Session s1 = getSessions().openSession();
    Transaction t1 = s1.beginTransaction();
    Item item = new Item();
    item.setName( initialName );
    s1.save( item );
    MyEntity myEntity = new MyEntity();
    myEntity.setName( "Test" );
    s1.save( myEntity );
    t1.commit();
    s1.close();

    Long itemId = item.getId();
    long initialVersion = item.getVersion();

    s1 = getSessions().openSession();
    t1 = s1.beginTransaction();
    item = ( Item ) s1.get( Item.class, itemId );
    s1.lock( item, LockMode.FORCE );
    assertEquals( "no forced version increment", initialVersion + 1, item.getVersion() );

    myEntity = (MyEntity) s1.get( MyEntity.class, myEntity.getId() );
    s1.lock( myEntity, LockMode.FORCE );
    assertTrue( "LockMode.FORCE on a unversioned entity should degrade nicely to UPGRADE", true );


    s1.lock( item, LockMode.FORCE );
    assertEquals( "subsequent LockMode.FORCE did not no-op", initialVersion + 1, item.getVersion() );

    Session s2 = getSessions().openSession();
    Transaction t2 = s2.beginTransaction();
    Item item2 = ( Item ) s2.get( Item.class, itemId );
    assertEquals( "isolation not maintained", initialName, item2.getName() );

    item.setName( "updated-1" );
    s1.flush();
    // currently an unfortunate side effect...
    assertEquals( initialVersion + 2, item.getVersion() );

    t1.commit();
    s1.close();

    item2.setName( "updated" );
    try {
      t2.commit();
      fail( "optimisitc lock should have failed" );
    }
    catch( Throwable ignore ) {
View Full Code Here

  }

  public void testRemoveThenContains() {
    Session s = openSession();
    s.beginTransaction();
    Item item = new Item();
    item.setName( "dummy" );
    s.persist( item );
    s.getTransaction().commit();
    s.close();

    s = openSession();
View Full Code Here

  }

  public void testRemoveThenGet() {
    Session s = openSession();
    s.beginTransaction();
    Item item = new Item();
    item.setName( "dummy" );
    s.persist( item );
    s.getTransaction().commit();
    s.close();

    Long id = item.getId();

    s = openSession();
    s.beginTransaction();
    s.delete( item );
    item = ( Item ) s.get( Item.class, id );
View Full Code Here

  public void testEjb3ProxyUsage() {
    Session s = openSession();
    Transaction txn = s.beginTransaction();

    Item item = ( Item ) s.load( Item.class, new Long(-1) );
    assertFalse( Hibernate.isInitialized( item ) );
    try {
      Hibernate.initialize( item );
      fail( "proxy access did not fail on non-existent proxy" );
    }
    catch ( EntityNotFoundException e ) {
      // expected behavior
    }
    catch ( Throwable t ) {
      fail( "unexpected exception type on non-existent proxy access : " + t );
    }

    s.clear();

    Item item2 = ( Item ) s.load( Item.class, new Long(-1) );
    assertFalse( Hibernate.isInitialized( item2 ) );
    assertFalse( item == item2 );
    try {
      item2.getName();
      fail( "proxy access did not fail on non-existent proxy" );
    }
    catch ( EntityNotFoundException e ) {
      // expected behavior
    }
View Full Code Here

   */
  public void testGetSemantics() {
    Long nonExistentId = new Long( -1 );
    Session s = openSession();
    Transaction txn = s.beginTransaction();
    Item item = ( Item ) s.get( Item.class, nonExistentId );
    assertNull( "get() of non-existent entity did not return null", item );
    txn.commit();
    s.close();

    s = openSession();
View Full Code Here

TOP

Related Classes of org.hibernate.test.jpa.Item

Copyright © 2018 www.massapicom. 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.