Package org.hibernate

Examples of org.hibernate.Transaction


  private Animal createAndPersistAnotherAnimal(Session session) {
    Animal animal = new Animal();
    animal.setId( "animal-2" );
    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 zoo = new Zoo();
    zoo.setId( "zoo-1" );
    zoo.setName( "Bagenhecks Tierpark" );
    zoo.getAnimals().add( animal );

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

    return zoo;
  }
View Full Code Here

      @Override
      public String call() throws Exception {
        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

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

        Animal berta = createAndPersistAnotherAnimal( session );

        Transaction transaction = session.beginTransaction();
        final Zoo zoo = (Zoo) session.get( Zoo.class, "zoo-1" );
        zoo.getAnimals().add( berta );
        transaction.commit();

        return zoo.getRevision();
      }
    } ).get();
  }
View Full Code Here

    return Executors.newSingleThreadExecutor().submit( new Callable<String>() {

      @Override
      public String call() throws Exception {
        Session session = openSession();
        Transaction transaction = session.beginTransaction();

        final Zoo zoo = (Zoo) session.get( Zoo.class, "zoo-1" );
        zoo.setName( "Hilwema" );

        transaction.commit();
        return zoo.getRevision();
      }
    } ).get();
  }
View Full Code Here

      }
    } ).get();
  }

  private Project createAndPersistProjectWithContributor() {
    Transaction transaction = session.beginTransaction();

    Project ogm = new Project();
    ogm.setId( "project-1" );
    ogm.setName( "OGM" );
    session.persist( ogm  );

    Contributor davide = new Contributor();
    davide.setId( "contributor-1" );
    davide.setName( "Davide" );
    session.persist( davide );

    ogm.getMembers().add( davide );
    davide.getProjects().add( ogm );

    transaction.commit();
    return ogm;
  }
View Full Code Here

    transaction.commit();
    return ogm;
  }

  private Project createAndPersistProjectWithUser() {
    Transaction transaction = session.beginTransaction();

    Project ogm = new Project();
    ogm.setId( "project-2" );
    ogm.setName( "Search" );
    session.persist( ogm  );

    User bob = new User();
    bob.setId( "user-1" );
    bob.setName( "Bob" );
    session.persist( bob );

    ogm.getUsers().add( bob );
    bob.getProjects().add( ogm );

    transaction.commit();
    return ogm;
  }
View Full Code Here

    transaction.commit();
    return ogm;
  }

  private Project createAndPersistProjectWithProjectGroup() {
    Transaction transaction = session.beginTransaction();

    Project validator = new Project();
    validator.setId( "project-3" );
    validator.setName( "Validator" );
    session.persist( validator  );

    ProjectGroup hibernateProjects = new ProjectGroup();
    hibernateProjects.setId( "project-group-1" );
    hibernateProjects.setName( "Hibernate" );
    session.persist( hibernateProjects );

    validator.setProjectGroup( hibernateProjects );
    hibernateProjects.getProjects().add( validator );

    transaction.commit();
    return validator;
  }
View Full Code Here

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

        Transaction transaction = session.beginTransaction();
        final Project project = (Project) session.get( Project.class, "project-1" );

        Contributor sanne = new Contributor();
        sanne.setId( "contributor-2" );
        sanne.setName( "Sanne" );

        sanne.getProjects().add( project );
        project.getMembers().add( sanne );

        session.persist( sanne );

        transaction.commit();

        return project.getRevision();
      }
    } ).get();
  }
View Full Code Here

  private final OscarWildePoem ballade = new OscarWildePoem( 3L, "Ballade De Marguerite", "Oscar Wilde", new GregorianCalendar( 1881, 3, 1 ).getTime() );

  @Before
  public void init() {
    Session session = openSession();
    Transaction transaction = session.beginTransaction();
    session.persist( portia );
    session.persist( athanasia );
    session.persist( ballade );
    transaction.commit();
    session.clear();
    session.close();
  }
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.