Package org.hibernate

Examples of org.hibernate.Transaction


      @Override
      public String call() throws Exception {
        Session session = openSession();

        Transaction transaction = session.beginTransaction();
        final Novel novel = (Novel) session.get( Novel.class, "novel-1" );
        session.delete( novel );
        transaction.commit();

        return novel.get_rev();
      }
    } ).get();
  }
View Full Code Here


    Animal animal = createAndPersistAnimal();

    String newRevision = doConcurrentUpdateToAnimal();
    assertThat( newRevision ).isNotEqualTo( animal.getRevision() );

    Transaction transaction = session.beginTransaction();
    animal.setName( "Xavier" );
    transaction.commit();
  }
View Full Code Here

  public void canUpdateObjectPropertyAfterUpdateOfAssociationStoredInEntity() {
    Animal animal1 = createAndPersistAnimal();
    Animal animal2 = createAndPersistAnotherAnimal();
    Zoo zoo = createAndPersistZoo( animal1 );

    Transaction transaction = session.beginTransaction();

    zoo.getAnimals().add( animal2 );
    zoo.setName( "Hilwelma" );

    transaction.commit();

    transaction = session.beginTransaction();

    zoo = (Zoo) session.get( Zoo.class, "zoo-1" );
    assertThat( zoo.getName() ).isEqualTo( "Hilwelma" );
    assertThat( zoo.getAnimals() ).onProperty( "name" ).containsOnly( "Bruno", "Berta" );

    transaction.commit();
  }
View Full Code Here

  @Test
  public void canUpdateEntityAfterUpdateOfAssociationStoredInEntityOnInverseSide() {
    Project project = createAndPersistProjectWithProjectGroup();

    Transaction transaction = session.beginTransaction();

    project.getProjectGroup().setName( "Fancy projects" );

    transaction.commit();

    transaction = session.beginTransaction();

    ProjectGroup projectGroup = (ProjectGroup) session.get( ProjectGroup.class, "project-group-1" );
    assertThat( projectGroup.getName() ).isEqualTo( "Fancy projects" );
    assertThat( projectGroup.getProjects() ).onProperty( "name" ).containsOnly( "Validator" );

    transaction.commit();
  }
View Full Code Here

  @Test
  public void canUpdateEntityAfterRemovalOfAssociationStoredInEntityOnInverseSide() {
    Project project = createAndPersistProjectWithProjectGroup();
    ProjectGroup projectGroup = project.getProjectGroup();

    Transaction transaction = session.beginTransaction();

    projectGroup.getProjects().remove( project );
    project.setProjectGroup( null );

    transaction.commit();

    transaction = session.beginTransaction();

    projectGroup.setName( "Fancy projects" );

    transaction.commit();

    transaction = session.beginTransaction();

    projectGroup = (ProjectGroup) session.get( ProjectGroup.class, "project-group-1" );
    assertThat( projectGroup.getName() ).isEqualTo( "Fancy projects" );
    assertThat( projectGroup.getProjects() ).isEmpty();

    transaction.commit();
  }
View Full Code Here

    // given
    Project search = createAndPersistProjectWithUser();
    Project ogm = createAndPersistProjectWithContributor();

    // when
    Transaction transaction = session.beginTransaction();
    User bob = search.getUsers().iterator().next();
    bob.getProjects().add( ogm );
    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" );
    assertThat( bob.getName() ).isEqualTo( "Alice" );
    assertThat( bob.getProjects() ).onProperty( "name" ).containsOnly( "OGM", "Search" );
    transaction.commit();
  }
View Full Code Here

    Animal animal = createAndPersistAnimal();
    Zoo zoo = createAndPersistZoo( animal );

    doConcurrentUpdateToTheZoosAnimals();

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

    Animal animal = createAndPersistAnimal();
    Zoo zoo = createAndPersistZoo( animal );

    doConcurrentUpdateToZoo();

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

  public void concurrentUpdateToObjectShouldCauseNoExceptionWithAssociationExcludedFromOptimisticLocking() throws Exception {
    Project ogm = createAndPersistProjectWithContributor();

    doConcurrentUpdateToProject();

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

    transaction = session.beginTransaction();

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

    transaction.commit();
  }
View Full Code Here

  private Animal createAndPersistAnimal() {
    Animal animal = new Animal();
    animal.setId( "animal-1" );
    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

TOP

Related Classes of org.hibernate.Transaction

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.