Package org.hibernate

Examples of org.hibernate.Transaction


  }

  @After
  public void tearDown() {
    Session session = openSession();
    Transaction tx = session.beginTransaction();
    delete( session, portia );
    delete( session, athanasia );
    delete( session, ballade);
    tx.commit();
    session.clear();
    session.close();
  }
View Full Code Here


  }

  @Test
  public void testUniqueResultQuery() throws Exception {
    OgmSession session = openSession();
    Transaction transaction = session.beginTransaction();

    String nativeQuery = "MATCH ( n:" + TABLE_NAME + " { name:'Portia', author:'Oscar Wilde' } ) RETURN n";
    OscarWildePoem poem = (OscarWildePoem) session.createNativeQuery( nativeQuery )
        .addEntity( OscarWildePoem.TABLE_NAME, OscarWildePoem.class )
        .uniqueResult();

    assertThat( poem ).isEqualTo( portia );

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

  }

  @Test
  public void testListMultipleResultQuery() throws Exception {
    OgmSession session = openSession();
    Transaction transaction = session.beginTransaction();

    String nativeQuery = "MATCH ( n:" + TABLE_NAME + " ) RETURN n ORDER BY n.name";
    @SuppressWarnings("unchecked")
    List<OscarWildePoem> result = session.createNativeQuery( nativeQuery )
        .addEntity( OscarWildePoem.TABLE_NAME, OscarWildePoem.class )
        .list();

    assertThat( result ).as( "Unexpected number of results" ).containsExactly( athanasia, ballade, portia );

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

  }

  @Test
  public void testListMultipleResultQueryWithoutReturnedType() throws Exception {
    OgmSession session = openSession();
    Transaction transaction = session.beginTransaction();

    String nativeQuery = "MATCH ( n:" + TABLE_NAME + " ) RETURN n.name, n.author ORDER BY n.name";
    @SuppressWarnings("unchecked")
    List<Object[]> result = session.createNativeQuery( nativeQuery ).list();

    assertThat( result ).as( "Unexpected number of results" ).hasSize( 3 );

    Object[] athanasiaRow = result.get( 0 );
    assertThat( athanasiaRow[0] ).isEqualTo( athanasia.getName() );
    assertThat( athanasiaRow[1] ).isEqualTo( athanasia.getAuthor() );

    Object[] balladeRow = result.get( 1 );
    assertThat( balladeRow[0] ).isEqualTo( ballade.getName() );
    assertThat( balladeRow[1] ).isEqualTo( ballade.getAuthor() );

    Object[] portiaRow = result.get( 2 );
    assertThat( portiaRow[0] ).isEqualTo( portia.getName() );
    assertThat( portiaRow[1] ).isEqualTo( portia.getAuthor() );

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

  }

  @Test
  public void testUniqueResultNamedNativeQuery() throws Exception {
    OgmSession session = openSession();
    Transaction transaction = session.beginTransaction();

    try {
      OscarWildePoem uniqueResult = (OscarWildePoem) session.getNamedQuery( "AthanasiaQuery" )
          .uniqueResult();
      assertThat( uniqueResult ).isEqualTo( athanasia );
      transaction.commit();
    }
    finally {
      session.clear();
      session.close();
    }
View Full Code Here

  }

  @Test
  public void testUniqueResultFromNativeQueryWithParameter() throws Exception {
    OgmSession session = openSession();
    Transaction transaction = session.beginTransaction();

    try {
      String nativeQuery = "MATCH ( n:" + TABLE_NAME + " { name:{name}, author:'Oscar Wilde' } ) RETURN n";
      SQLQuery query = session.createNativeQuery( nativeQuery ).addEntity( OscarWildePoem.class );
      query.setParameter( "name", "Portia" );

      OscarWildePoem uniqueResult = (OscarWildePoem) query.uniqueResult();
      assertThat( uniqueResult ).isEqualTo( portia );
      transaction.commit();
    }
    finally {
      session.clear();
      session.close();
    }
View Full Code Here

  }

  @Test
  public void testNativeQueryWithFirstResult() throws Exception {
    OgmSession session = (OgmSession) openSession();
    Transaction transaction = session.beginTransaction();

    String nativeQuery = "MATCH ( n:" + TABLE_NAME + " { author:'Oscar Wilde' } ) RETURN n ORDER BY n.name";
    Query query = session.createNativeQuery( nativeQuery )
        .addEntity( OscarWildePoem.class )
        .setFirstResult( 1 );
    @SuppressWarnings("unchecked")
    List<OscarWildePoem> result = query.list();

    assertThat( result ).containsExactly( ballade, portia );

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

  }
View Full Code Here

  }

  @Test
  public void testNativeQueryWithMaxRows() throws Exception {
    OgmSession session = (OgmSession) openSession();
    Transaction transaction = session.beginTransaction();

    String nativeQuery = "MATCH ( n:" + TABLE_NAME + " { author:'Oscar Wilde' } ) RETURN n ORDER BY n.name";
    Query query = session.createNativeQuery( nativeQuery )
        .addEntity( OscarWildePoem.class )
        .setMaxResults( 2 );
    @SuppressWarnings("unchecked")
    List<OscarWildePoem> result = query.list();

    assertThat( result ).containsExactly( athanasia, ballade );

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

  }

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

    Flower flower = new Flower();
    flower.setId( "1" );
    flower.setName( "Caltha palustris" );

    session.persist( flower );
    transaction.commit();
    session.clear();

    transaction = session.beginTransaction();

    Flower loadedFlower = (Flower) session.get( Flower.class, flower.getId() );
    assertNotNull( loadedFlower );
    assertEquals( flower.getName(), loadedFlower.getName() );

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

  }

  @Test
  public void testListMultipleResultQueryWithFirstResultAndMaxRows() throws Exception {
    Session session = openSession();
    Transaction transaction = session.beginTransaction();

    String nativeQuery = "MATCH ( n:" + TABLE_NAME + " { author:'Oscar Wilde' } ) RETURN n ORDER BY n.name DESC";
    @SuppressWarnings("unchecked")
    List<OscarWildePoem> result = session.createSQLQuery( nativeQuery )
        .addEntity( OscarWildePoem.TABLE_NAME, OscarWildePoem.class )
        .setFirstResult( 1 )
        .setMaxResults( 1 )
        .list();

    assertThat( result ).containsExactly( 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.