⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dependenttest.java

📁 hibernate方便的操作数据库相当不错的 请各位下载看看啊
💻 JAVA
字号:
//$Id: DependentTest.java,v 1.4 2005/02/25 12:44:43 maxcsaucdk Exp $package org.hibernate.test.metadata.dependent;import org.hibernate.test.metadata.TestCase;import org.hibernate.Transaction;import org.hibernate.Session;import java.io.Serializable;/** * @author Emmanuel Bernard */public class DependentTest extends TestCase {	public void testSimple() throws Exception {		Session s;		Transaction tx;		Person p = new Person();		Address a = new Address();		Country c = new Country();		Country bornCountry = new Country();		c.setIso2("DM");		c.setName("Matt Damon Land");		bornCountry.setIso2("US");		bornCountry.setName("United States of America");		a.address1 = "colorado street";		a.city = "Springfield";		a.country = c;		p.address = a;		p.bornIn = bornCountry;		p.name = "Homer";		s = openSession();		tx = s.beginTransaction();		s.persist(p);		tx.commit();		s.close();		s = openSession();		tx = s.beginTransaction();		p = (Person) s.get(Person.class, p.id);		assertNotNull(p);		assertNotNull(p.address);		assertEquals("Springfield", p.address.city);		assertNotNull(p.address.country);		assertEquals( "DM", p.address.country.getIso2() );		assertNotNull(p.bornIn);		assertEquals( "US", p.bornIn.getIso2() );		tx.commit();		s.close();	}	public void testCompositeId() throws Exception {		Session s;		Transaction tx;		RegionalArticlePk pk = new RegionalArticlePk();		pk.iso2 = "FR";		pk.localUniqueKey = "1234567890123";		RegionalArticle reg = new RegionalArticle();		reg.setName("Je ne veux pes rester sage - Dolly");		reg.setPk(pk);		s = openSession();		tx = s.beginTransaction();		s.persist(reg);		tx.commit();		s.close();		s = openSession();		tx = s.beginTransaction();		reg = (RegionalArticle) s.get( RegionalArticle.class, (Serializable) reg.getPk() );		assertNotNull(reg);		assertNotNull( reg.getPk() );		assertEquals( "Je ne veux pes rester sage - Dolly", reg.getName() );		assertEquals("FR", reg.getPk().iso2);		tx.commit();		s.close();	}	public DependentTest(String x) {		super(x);	}	protected Class[] getMappings() {		return new Class[] {			Person.class,			RegionalArticle.class		};	}}

⌨️ 快捷键说明

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