Package org.hibernate

Examples of org.hibernate.Session.saveOrUpdate()


  public void testSaveOrUpdateManaged() {
    Session s = openSession();
    Transaction tx = s.beginTransaction();
    NumberedNode root = new NumberedNode( "root" );
    s.saveOrUpdate( root );
    tx.commit();

    tx = s.beginTransaction();
    NumberedNode child = new NumberedNode( "child" );
    root.addChild( child );
View Full Code Here


    tx.commit();

    tx = s.beginTransaction();
    NumberedNode child = new NumberedNode( "child" );
    root.addChild( child );
    s.saveOrUpdate( root );
    assertFalse( s.contains( child ) );
    s.flush();
    assertTrue( s.contains( child ) );
    tx.commit();
View Full Code Here

    SimpleJtaTransactionManagerImpl.getInstance().begin();
    Session s2 = openSession();
    try {
      s2.getTransaction().begin();
      s2.saveOrUpdate( child );
      fail();
    }
    catch ( HibernateException ex ) {
      // expected because parent is connected to s1
    }
View Full Code Here

    boolean instrumented = FieldInterceptionHelper.isInstrumented( new NumberedNode() );

    Session s = openSession();
    Transaction tx = s.beginTransaction();
    NumberedNode root = new NumberedNode( "root" );
    s.saveOrUpdate( root );
    tx.commit();
    s.close();

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

    s1.evict( child.getParent() );
    assertFalse( s1.contains( child.getParent() ) );

    SimpleJtaTransactionManagerImpl.getInstance().begin();
    s2 = openSession();
     s2.saveOrUpdate( child );
    s2 = applyNonFlushedChangesToNewSessionCloseOldSession( s2 );
    child = ( Node ) getOldToNewEntityRefMap().get( child );
    assertTrue( s2.contains( child ) );
    assertFalse( s1.contains( child ) );
    assertTrue( s2.contains( child.getParent() ) );
View Full Code Here

    assertUpdateCount( 0 );
    clearCounts();

    s = openSession();
    tx = s.beginTransaction();
    s.saveOrUpdate( root );
    tx.commit();
    s.close();

    assertInsertCount( 0 );
    assertUpdateCount( instrumented ? 0 : 1 );
View Full Code Here

    prod = (Product) SerializationHelper.clone( prod );

    session = openSession();
    t = session.beginTransaction();
    session.saveOrUpdate(prod);
    t.commit();
    session.close();

    session = openSession();
    t = session.beginTransaction();
View Full Code Here

    cv1.setText("expensive");
    ContractVariation cv2 = new ContractVariation(2, c);
    cv2.setText("more expensive");
    Session s = openSession();
    Transaction t = s.beginTransaction();
    s.saveOrUpdate(c);
    assertTrue( s.isReadOnly( c ) );
    assertTrue( s.isReadOnly( cv1 ) );
    assertTrue( s.isReadOnly( cv2 ) );
    t.commit();
    s.close();
View Full Code Here

    ContractVariation cv2 = new ContractVariation(2, c);
    cv2.setText("more expensive");

    Session s = openSession();
    Transaction t = s.beginTransaction();
    s.saveOrUpdate( c );
    assertTrue( s.isReadOnly( c ) );
    assertTrue( s.isReadOnly( cv1 ) );
    assertTrue( s.isReadOnly( cv2 ) );
    t.commit();
    s.close();
View Full Code Here

    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" );
    }
    catch( NonUniqueObjectException expected ) {
      // expected behavior
    }
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.