Package org.hibernate

Examples of org.hibernate.Transaction


  @Test
  @TestForIssue(jiraKey = "OGM-612")
  public void canUseObjectIdAssignedUponInsertWithEmbeddable() {
    OgmSession session = openSession();
    Transaction tx = session.beginTransaction();

    // given
    EntityWithObjectIdAndEmbeddable entity = new EntityWithObjectIdAndEmbeddable();
    AnEmbeddable anEmbeddable = new AnEmbeddable( "a very nice string", null );
    entity.setAnEmbeddable( anEmbeddable );

    // when
    session.persist( entity );

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

    EntityWithObjectIdAndEmbeddable loaded = (EntityWithObjectIdAndEmbeddable) session.load( EntityWithObjectIdAndEmbeddable.class, entity.getId() );

    // then
    assertThat( loaded.getId() ).isEqualTo( entity.getId() );
    assertThat( loaded.getAnEmbeddable().getEmbeddedString() ).isEqualTo( entity.getAnEmbeddable().getEmbeddedString() );
    assertThat( loaded.getAnEmbeddable().getAnotherEmbeddable() ).isEqualTo( entity.getAnEmbeddable().getAnotherEmbeddable() );

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


  @Test
  @TestForIssue(jiraKey = "OGM-612")
  public void canUseObjectIdAssignedUponInsertWithNestedEmbeddable() {
    OgmSession session = openSession();
    Transaction tx = session.beginTransaction();

    // given
    EntityWithObjectIdAndEmbeddable entity = new EntityWithObjectIdAndEmbeddable();
    AnotherEmbeddable anotherEmbeddable = new AnotherEmbeddable( "Another nice string ... nested" );
    AnEmbeddable anEmbeddable = new AnEmbeddable( "a very nice string", anotherEmbeddable );
    entity.setAnEmbeddable( anEmbeddable );

    // when
    session.persist( entity );

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

    EntityWithObjectIdAndEmbeddable loaded = (EntityWithObjectIdAndEmbeddable) session.load( EntityWithObjectIdAndEmbeddable.class, entity.getId() );

    // then
    assertThat( loaded.getId() ).isEqualTo( entity.getId() );
    assertThat( loaded.getAnEmbeddable().getEmbeddedString() ).isEqualTo( entity.getAnEmbeddable().getEmbeddedString() );
    assertThat( loaded.getAnEmbeddable().getAnotherEmbeddable().getEmbeddedString() ).isEqualTo(
        entity.getAnEmbeddable().getAnotherEmbeddable().getEmbeddedString() );

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

  private Transaction transaction;

  @BeforeClass
  public static void addTestEntities() {
    Session session = sessions.openSession();
    Transaction transaction = session.getTransaction();
    transaction.begin();

    Hypothesis hypothesis = new Hypothesis();
    hypothesis.setId( "1" );
    hypothesis.setPosition( 1 );
    hypothesis.setDescription( "Alea iacta est." );
    session.persist( hypothesis );

    hypothesis = new Hypothesis();
    hypothesis.setId( "2" );
    hypothesis.setPosition( 2 );
    hypothesis.setDescription( "Ne vadis..." );
    session.persist( hypothesis );

    hypothesis = new Hypothesis();
    hypothesis.setId( "3" );
    hypothesis.setPosition( 3 );
    hypothesis.setDescription( "Omne initium difficile est." );
    session.persist( hypothesis );

    hypothesis = new Hypothesis();
    hypothesis.setId( "4" );
    hypothesis.setPosition( 4 );
    hypothesis.setDescription( "Nomen est omen." );
    session.persist( hypothesis );

    hypothesis = new Hypothesis();
    hypothesis.setId( "5" );
    hypothesis.setPosition( 5 );
    hypothesis.setDescription( "Quo vadis?" );
    session.persist( hypothesis );

    hypothesis = new Hypothesis();
    hypothesis.setId( "6" );
    hypothesis.setPosition( 6 );
    hypothesis.setDescription( "Ne vadis." );
    session.persist( hypothesis );

    hypothesis = new Hypothesis();
    hypothesis.setId( "7" );
    hypothesis.setPosition( 7 );
    hypothesis.setDescription( "100% scientia" );
    session.persist( hypothesis );

    hypothesis = new Hypothesis();
    hypothesis.setId( "8" );
    hypothesis.setPosition( 8 );
    hypothesis.setDescription( "100\nscientiae" );
    session.persist( hypothesis );

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

  }

  @AfterClass
  public static void deleteTestEntities() throws Exception {
    Session session = sessions.openSession();
    Transaction transaction = session.getTransaction();
    transaction.begin();

    session.delete( new Hypothesis( "1" ) );
    session.delete( new Hypothesis( "2" ) );
    session.delete( new Hypothesis( "3" ) );
    session.delete( new Hypothesis( "4" ) );
    session.delete( new Hypothesis( "5" ) );
    session.delete( new Hypothesis( "6" ) );
    session.delete( new Hypothesis( "7" ) );
    session.delete( new Hypothesis( "8" ) );

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

  }

  @Test
  public void testLoadSelectedAssociationColumns() {
    Session session = openSession();
    final Transaction transaction = session.getTransaction();
    transaction.begin();

    Module mongodb = new Module();
    mongodb.setName( "MongoDB" );
    session.persist( mongodb );

    Module infinispan = new Module();
    infinispan.setName( "Infinispan" );
    session.persist( infinispan );

    List<Module> modules = new ArrayList<Module>();
    modules.add( mongodb );
    modules.add( infinispan );

    Project hibernateOGM = new Project();
    hibernateOGM.setId( "projectID" );
    hibernateOGM.setName( "HibernateOGM" );
    hibernateOGM.setModules( modules );

    session.persist( hibernateOGM );
    transaction.commit();

    this.addExtraColumn();
    AssociationKeyMetadata metadata = new AssociationKeyMetadata.Builder()
        .table( "Project_Module" )
        .columnNames( new String[] { "Project_id" } )
View Full Code Here

    // given an empty database
    MockMongoClient mockClient = mockClient().build();
    setupSessionFactory( new MongoDBDatastoreProvider( mockClient.getClient() ) );

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

    // when getting a golf player
    session.get( GolfPlayer.class, 1L );

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

    // then expect a findOne() call with the configured read preference
    verify( mockClient.getCollection( "GolfPlayer" ) ).findOne( any( DBObject.class ), any( DBObject.class ), eq( ReadPreference.secondaryPreferred() ) );
  }
View Full Code Here

        .build();

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

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

    // when getting the golf player
    GolfPlayer ben = (GolfPlayer) session.get( GolfPlayer.class, 1L );
    List<GolfCourse> playedCourses = ben.getPlayedCourses();
    assertThat( playedCourses ).onProperty( "id" ).containsExactly( 1L );

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

    // then expect a findOne() call for the entity and the embedded association with the configured read preference
    verify( mockClient.getCollection( "GolfPlayer" ) ).findOne( any( DBObject.class ), any( DBObject.class ), eq( ReadPreference.secondaryPreferred() ) );
  }
View Full Code Here

        .build();

    setupSessionFactory( new MongoDBDatastoreProvider( mockClient.getClient() ), AssociationStorageType.ASSOCIATION_DOCUMENT );

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

    // when getting the golf player
    GolfPlayer ben = (GolfPlayer) session.get( GolfPlayer.class, 1L );
    List<GolfCourse> playedCourses = ben.getPlayedCourses();
    assertThat( playedCourses ).onProperty( "id" ).containsExactly( 1L );

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

    // then expect a findOne() call for the entity and one for the association  with the configured read preference
    verify( mockClient.getCollection( "GolfPlayer" ) ).findOne( any( DBObject.class ), any( DBObject.class ), eq( ReadPreference.secondaryPreferred() ) );
    verify( mockClient.getCollection( "Associations" ) ).findOne( any( DBObject.class ), any( DBObject.class ), eq( ReadPreference.primaryPreferred() ) );
View Full Code Here

public class ObjectIdTest extends OgmTestCase {

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

    // given
    BarKeeper brian = new BarKeeper( new ObjectId(), "Brian" );

    // when
    session.persist( brian );

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

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

    // then
    assertThat( brianLoaded.getId() ).isEqualTo( brian.getId() );
    assertThat( brianLoaded.getName() ).isEqualTo( "Brian" );

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

    // given an empty database
    MockMongoClient mockClient = mockClient().build();
    setupSessionFactory( new MongoDBDatastoreProvider( mockClient.getClient() ) );

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

    // when inserting a golf player
    GolfPlayer ben = new GolfPlayer( 1L, "Ben", 0.1 );
    session.persist( ben );

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

    // then expect one (batched) insert with the configured write concern
    verify( mockClient.getCollection( "GolfPlayer" ) ).insert( any( List.class ), eq( WriteConcern.MAJORITY ) );
  }
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.