Package org.hibernate

Examples of org.hibernate.Session.merge()


    // make sure we get an update as a result...
    mergedParent.setName( "new name" );
    mergedParent.getChildren().add( new VersionedEntity( "child2", "new child" ) );
    s = openSession();
    s.beginTransaction();
    parent = ( VersionedEntity ) s.merge( mergedParent );
    s.getTransaction().commit();
    s.close();
    assertUpdateCount( 1 );
    assertInsertCount( 1 );
    ///////////////////////////////////////////////////////////////////////
View Full Code Here


    clearCounts();

    p.getAddress().setStreetAddress( "321 Main" );
    SimpleJtaTransactionManagerImpl.getInstance().begin();
    s = openSession();
    p = ( Person ) s.merge( p );
    s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
    SimpleJtaTransactionManagerImpl.getInstance().commit();

    assertInsertCount( 0 );
    assertUpdateCount( 0 ); // no cascade
View Full Code Here

    s.beginTransaction();
    // load parent so that merge will follow entityIsPersistent path
    VersionedEntity persistentParent = ( VersionedEntity ) s.get( VersionedEntity.class, parent.getId() );
    // load children
    VersionedEntity persistentChild = ( VersionedEntity ) persistentParent.getChildren().iterator().next();
    VersionedEntity mergedParent = ( VersionedEntity ) s.merge( persistentParent ); // <-- This merge leads to failure
    s.getTransaction().commit();
    s.close();

    assertUpdateCount( 0 );
    assertInsertCount( 0 );
View Full Code Here

    // node is now detached, but we have made no changes.  so attempt to merge it
    // into this new session; this should cause no updates...
    SimpleJtaTransactionManagerImpl.getInstance().begin();
    s = openSession();
    node = ( Node ) s.merge( node );
    s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
    SimpleJtaTransactionManagerImpl.getInstance().commit();

    assertUpdateCount( 0 );
    assertInsertCount( 0 );
View Full Code Here

    // as a control measure, now update the node while it is detached and
    // make sure we get an update as a result...
    node.setDescription( "new description" );
    SimpleJtaTransactionManagerImpl.getInstance().begin();
    s = openSession();
    node = ( Node ) s.merge( node );
    s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
    SimpleJtaTransactionManagerImpl.getInstance().commit();
    assertUpdateCount( 1 );
    assertInsertCount( 0 );
    ///////////////////////////////////////////////////////////////////////
View Full Code Here

    s = openSession();
    s.beginTransaction();
    persistentParent = ( VersionedEntity ) s.get( VersionedEntity.class, parent.getId() );
    persistentParent.setName( "new name" );
    persistentParent.getChildren().add( new VersionedEntity( "child2", "new child" ) );
    persistentParent = ( VersionedEntity ) s.merge( persistentParent );
    s.getTransaction().commit();
    s.close();
    assertUpdateCount( 1 );
    assertInsertCount( 1 );
    ///////////////////////////////////////////////////////////////////////
View Full Code Here

    // parent is now detached, but we have made no changes.  so attempt to merge it
    // into this new session; this should cause no updates...
    SimpleJtaTransactionManagerImpl.getInstance().begin();
    s = openSession();
    parent = ( Node ) s.merge( parent );
    s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
    SimpleJtaTransactionManagerImpl.getInstance().commit();

    assertUpdateCount( 0 );
    assertInsertCount( 0 );
View Full Code Here

    // make sure we get an update as a result...
    ( ( Node ) parent.getChildren().iterator().next() ).setDescription( "child's new description" );
    parent.addChild( new Node( "second child" ) );
    SimpleJtaTransactionManagerImpl.getInstance().begin();
    s = openSession();
    parent = ( Node ) s.merge( parent );
    s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
    SimpleJtaTransactionManagerImpl.getInstance().commit();
    assertUpdateCount( 1 );
    assertInsertCount( 1 );
    ///////////////////////////////////////////////////////////////////////
View Full Code Here

  public void testPersistThenMergeInSameTxnWithVersion() {
    Session s = openSession();
    Transaction tx = s.beginTransaction();
    VersionedEntity entity = new VersionedEntity( "test", "test" );
    s.persist( entity );
    s.merge( new VersionedEntity( "test", "test-2" ) );

    try {
      // control operation...
      s.saveOrUpdate( new VersionedEntity( "test", "test-3" ) );
      fail( "saveOrUpdate() should fail here" );
View Full Code Here

    // entity is now detached, but we have made no changes.  so attempt to merge it
    // into this new session; this should cause no updates...
    SimpleJtaTransactionManagerImpl.getInstance().begin();
    s = openSession();
    VersionedEntity mergedEntity = ( VersionedEntity ) s.merge( entity );
    s = applyNonFlushedChangesToNewSessionCloseOldSession( s );
    mergedEntity = ( VersionedEntity ) getOldToNewEntityRefMap().get( mergedEntity );
    SimpleJtaTransactionManagerImpl.getInstance().commit();

    assertUpdateCount( 0 );
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. 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.