testispropertyinitializedexecutable.java

来自「hibernate 开源框架的代码 jar包希望大家能喜欢」· Java 代码 · 共 49 行

JAVA
49
字号
//$Id: $
package org.hibernate.test.instrument.cases;

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

/**
 * @author Steve Ebersole
 */
public class TestIsPropertyInitializedExecutable 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);
		Assert.assertTrue( Hibernate.isPropertyInitialized( doc, "summary" ) );
		s.persist(o);
		s.persist(fol);
		t.commit();
		s.close();

		s = getFactory().openSession();
		t = s.beginTransaction();
		doc = (Document) s.get( Document.class, doc.getId() );
		Assert.assertFalse( Hibernate.isPropertyInitialized( doc, "summary" ) );
		Assert.assertFalse( Hibernate.isPropertyInitialized( doc, "upperCaseName" ) );
		Assert.assertFalse( Hibernate.isPropertyInitialized( doc, "owner" ) );
		s.delete(doc);
		s.delete( doc.getOwner() );
		s.delete( doc.getFolder() );
		t.commit();
		s.close();
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?