Package org.hibernate.test.instrument.cases

Source Code of org.hibernate.test.instrument.cases.TestFetchAllExecutable

package org.hibernate.test.instrument.cases;

import junit.framework.Assert;

import org.hibernate.Hibernate;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.test.instrument.domain.Document;
import org.hibernate.test.instrument.domain.Folder;
import org.hibernate.test.instrument.domain.Owner;

/**
* @author Steve Ebersole
*/
public class TestFetchAllExecutable extends AbstractExecutable {
  public void execute() {
    Session s = getFactory().openSession();
    Transaction t = s.beginTransaction();
    Owner o = new Owner();
    Document doc = new Document();
    Folder fol = new Folder();
    o.setName("gavin");
    doc.setName("Hibernate in Action");
    doc.setSummary("blah");
    doc.updateText("blah blah");
    fol.setName("books");
    doc.setOwner(o);
    doc.setFolder(fol);
    fol.getDocuments().add(doc);
    s.persist(o);
    s.persist(fol);
    t.commit();
    s.close();

    s = getFactory().openSession();
    t = s.beginTransaction();
    doc = (Document) s.createQuery("from Document fetch all properties").uniqueResult();
    Assert.assertTrue( Hibernate.isPropertyInitialized( doc, "summary" ) );
    Assert.assertTrue( Hibernate.isPropertyInitialized( doc, "upperCaseName" ) );
    Assert.assertTrue( Hibernate.isPropertyInitialized( doc, "owner" ) );
    Assert.assertEquals( doc.getSummary(), "blah" );
    s.delete(doc);
    s.delete( doc.getOwner() );
    s.delete( doc.getFolder() );
    t.commit();
    s.close();
  }
}
TOP

Related Classes of org.hibernate.test.instrument.cases.TestFetchAllExecutable

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.