Package org.hibernate

Examples of org.hibernate.Transaction


  }

  @Test
  public void canUseManuallyAssignedObjectIdInAssociation() {
    OgmSession session = openSession();
    Transaction tx = session.beginTransaction();

    // given
    BarKeeper brian = new BarKeeper( new ObjectId(), "Brian" );
    Drink cubaLibre = new Drink( new ObjectId(), "Cuba Libre" );
    brian.setFavoriteDrink( cubaLibre );

    // when
    session.persist( brian );
    session.persist( cubaLibre );

    tx.commit();
    session.clear();
    tx = session.beginTransaction();

    BarKeeper brianLoaded = (BarKeeper) session.load( BarKeeper.class, brian.getId() );

    // then
    assertThat( brianLoaded.getName() ).isEqualTo( "Brian" );
    assertThat( brianLoaded.getFavoriteDrink() ).isNotNull();
    assertThat( brianLoaded.getFavoriteDrink().getName() ).isEqualTo( "Cuba Libre" );

    tx.commit();
    session.close();
  }
View Full Code Here


        .insert( "GolfPlayer", getPlayer() )
        .build();
    setupSessionFactory( new MongoDBDatastoreProvider( mockClient.getClient() ) );

    final Session session = sessions.openSession();
    Transaction transaction = session.beginTransaction();

    // when updating the golf player
    GolfPlayer ben = new GolfPlayer( 1L, "Ben", 0.2 );
    session.merge( ben );

    transaction.commit();
    session.close();

    // then expect one (batched) insert with the configured write concern
    verify( mockClient.getCollection( "GolfPlayer" ) ).update( any( DBObject.class ), any( DBObject.class ), anyBoolean(), anyBoolean(), eq( WriteConcern.MAJORITY ) );
  }
View Full Code Here

        .build();

    setupSessionFactory( new MongoDBDatastoreProvider( mockClient.getClient() ) );

    final Session session = sessions.openSession();
    Transaction transaction = session.beginTransaction();

    // when removing the golf player
    GolfPlayer ben = new GolfPlayer( 1L, "Ben", 0.1 );
    session.delete( ben );

    transaction.commit();
    session.close();

    // then expect a call to remove with the configured write concern
    verify( mockClient.getCollection( "GolfPlayer" ) ).remove( any( DBObject.class ), eq( WriteConcern.MAJORITY ) );
  }
View Full Code Here

  }

  @Test
  public void canUseObjectIdAssignedUponInsert() {
    OgmSession session = openSession();
    Transaction tx = session.beginTransaction();

    // given
    Bar goldFishBar = new Bar( "Goldfisch Bar" );

    // when
    session.persist( goldFishBar );

    tx.commit();
    assertThat( goldFishBar.getId() ).isNotNull();
    session.clear();
    tx = session.beginTransaction();

    Bar barLoaded = (Bar) session.load( Bar.class, goldFishBar.getId() );

    // then
    assertThat( barLoaded.getName() ).isEqualTo( "Goldfisch Bar" );

    tx.commit();
    session.close();
  }
View Full Code Here

        .build();

    setupSessionFactory( new MongoDBDatastoreProvider( mockClient.getClient() ) );

    Session session = sessions.openSession();
    Transaction transaction = session.beginTransaction();

    // when associating the golf course to the player
    GolfPlayer ben = new GolfPlayer( 1L, "Ben", 0.1, new GolfCourse( 1L, "Bepple Peach" ) );
    session.merge( ben );

    transaction.commit();
    session.close();

    // then expect one update using the configured write concern for adding the row
    verify( mockClient.getCollection( "GolfPlayer" ), times( 1 ) ).update( any( DBObject.class ), any( DBObject.class ), anyBoolean(), anyBoolean(), eq( WriteConcern.MAJORITY ) );
  }
View Full Code Here

  }

  @Test
  public void testHibernateSearchJPAAPIUsage() throws Exception {
    final Session session = openSession();
    Transaction transaction = session.beginTransaction();
    final FullTextSession fts = Search.getFullTextSession( session );
    final Insurance insurance = new Insurance();
    insurance.setName( "Macif" );
    fts.persist( insurance );
    transaction.commit();

    fts.clear();

    transaction = fts.beginTransaction();
    final QueryBuilder b = fts.getSearchFactory()
        .buildQueryBuilder()
        .forEntity( Insurance.class )
        .get();
    final Query lq = b.keyword().onField( "name" ).matching( "Macif" ).createQuery();
    final FullTextQuery ftQuery = fts.createFullTextQuery( lq, Insurance.class );
    ftQuery.initializeObjectsWith( ObjectLookupMethod.SKIP, DatabaseRetrievalMethod.FIND_BY_ID );
    final List<Insurance> resultList = ftQuery.list();
    assertThat( resultList ).hasSize( 1 );
    for ( Object e : resultList ) {
      fts.delete( e );
    }
    transaction.commit();
    fts.close();
  }
View Full Code Here

public class QueryUpdateTest extends OgmTestCase {

  @Before
  public void insertTestEntities() throws Exception {
    Session session = sessions.openSession();
    Transaction transaction = session.beginTransaction();

    Helicopter helicopter = new Helicopter();
    helicopter.setMake( "Lama" );
    helicopter.setName( "Sergio" );
    session.persist( helicopter );

    transaction.commit();
    session.close();
  }
View Full Code Here

  }

  @Test
  public void canUpdateEntityReturnedByQuery() {
    Session session = sessions.openSession();
    Transaction transaction = session.beginTransaction();

    Query query = session.createQuery( "from Helicopter h where name = 'Sergio'" );
    Helicopter helicopter = (Helicopter) query.uniqueResult();
    assertThat( helicopter ).isNotNull();
    helicopter.setName( "Leonie" );

    transaction.commit();
    session.clear();
    transaction = session.beginTransaction();

    query = session.createQuery( "from Helicopter h where name = 'Leonie'" );
    helicopter = (Helicopter) query.uniqueResult();
    assertThat( helicopter ).isNotNull();

    transaction.commit();
    session.close();
  }
View Full Code Here

  }

  @After
  public void removeCloudAndSnowflakes() {
    Session session = sessions.openSession();
    Transaction transaction = session.beginTransaction();

    if ( cloud != null ) {
      Cloud cloudToDelete = (Cloud) session.get( Cloud.class, cloud.getId() );
      for ( SnowFlake current : cloudToDelete.getProducedSnowFlakes() ) {
        session.delete( current );
      }
      for ( SnowFlake current : cloudToDelete.getBackupSnowFlakes() ) {
        session.delete( current );
      }
      session.delete( cloudToDelete );
    }

    transaction.commit();
    session.close();

    assertThat( TestHelper.getNumberOfEntities( sessions ) ).isEqualTo( 0 );
    assertThat( TestHelper.getNumberOfAssociations( sessions ) ).isEqualTo( 0 );
View Full Code Here

      return this;
    }

    public Cloud createAndSave() {
      Session session = sessions.openSession();
      Transaction transaction = session.beginTransaction();

      Cloud cloud = new Cloud();
      cloud.setLength( length );

      for ( String description : producedSnowflakes ) {
        SnowFlake sf = new SnowFlake();
        sf.setDescription( description );
        session.save( sf );
        cloud.getProducedSnowFlakes().add( sf );
      }

      for ( String description : backupSnowflakes ) {
        SnowFlake sf = new SnowFlake();
        sf.setDescription( description );
        session.save( sf );
        cloud.getBackupSnowFlakes().add( sf );
      }

      session.persist( cloud );

      transaction.commit();
      session.close();

      return cloud;
    }
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.