Package org.hibernate

Examples of org.hibernate.Transaction.commit()


    ogm.getUsers().add( bob );
    transaction.commit();

    transaction = session.beginTransaction();
    bob.setName( "Alice" );
    transaction.commit();
    session.clear();

    // then
    transaction = session.beginTransaction();
    bob = (User) session.get( User.class, "user-1" );
View Full Code Here


    // then
    transaction = session.beginTransaction();
    bob = (User) session.get( User.class, "user-1" );
    assertThat( bob.getName() ).isEqualTo( "Alice" );
    assertThat( bob.getProjects() ).onProperty( "name" ).containsOnly( "OGM", "Search" );
    transaction.commit();
  }

  @Test(expected = StaleObjectStateException.class)
  public void concurrentUpdateToAssociationShouldCauseException() throws Exception {
    Animal animal = createAndPersistAnimal();
View Full Code Here

    doConcurrentUpdateToTheZoosAnimals();

    Transaction transaction = session.beginTransaction();
    zoo.getAnimals().remove( zoo.getAnimals().iterator().next() );
    transaction.commit();
  }

  @Test(expected = StaleObjectStateException.class)
  public void concurrentUpdateToObjectShouldCauseExceptionWhenUpdatingAssociation() throws Exception {
    Animal animal = createAndPersistAnimal();
View Full Code Here

    doConcurrentUpdateToZoo();

    Transaction transaction = session.beginTransaction();
    zoo.getAnimals().remove( zoo.getAnimals().iterator().next() );
    transaction.commit();
  }

  @Test
  public void concurrentUpdateToObjectShouldCauseNoExceptionWithAssociationExcludedFromOptimisticLocking() throws Exception {
    Project ogm = createAndPersistProjectWithContributor();
View Full Code Here

    doConcurrentUpdateToProject();

    Transaction transaction = session.beginTransaction();
    ogm.setName( "OGM!" );
    transaction.commit();
    session.clear();

    transaction = session.beginTransaction();

    ogm = (Project) session.get( Project.class, "project-1" );
View Full Code Here

    ogm = (Project) session.get( Project.class, "project-1" );
    assertThat( ogm.getName() ).isEqualTo( "OGM!" );
    assertThat( ogm.getMembers() ).onProperty( "name" ).containsOnly( "Davide", "Sanne" );

    transaction.commit();
  }

  private Animal createAndPersistAnimal() {
    Animal animal = new Animal();
    animal.setId( "animal-1" );
View Full Code Here

    animal.setName( "Bruno" );

    Transaction transaction = session.beginTransaction();
    assertThat( animal.getRevision() ).isNull();
    session.persist( animal );
    transaction.commit();
    assertThat( animal.getRevision() ).isNotNull();

    return animal;
  }
View Full Code Here

    animal.setName( "Berta" );

    Transaction transaction = session.beginTransaction();
    assertThat( animal.getRevision() ).isNull();
    session.persist( animal );
    transaction.commit();
    assertThat( animal.getRevision() ).isNotNull();

    return animal;
  }
View Full Code Here

    zoo.setName( "Bagenhecks Tierpark" );
    zoo.getAnimals().add( animal );

    Transaction transaction = session.beginTransaction();
    session.persist( zoo );
    transaction.commit();

    return zoo;
  }

  private String doConcurrentUpdateToAnimal() throws Exception {
View Full Code Here

        Session session = openSession();

        Transaction transaction = session.beginTransaction();
        final Animal animal = (Animal) session.get( Animal.class, "animal-1" );
        animal.setName( "Xavier" );
        transaction.commit();

        return animal.getRevision();
      }
    } ).get();
  }
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.