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

📄 joinedsubclasstest.java

📁 hibernate方便的操作数据库相当不错的 请各位下载看看啊
💻 JAVA
字号:
//$Id: JoinedSubclassTest.java,v 1.3 2005/02/25 12:44:43 maxcsaucdk Exp $package org.hibernate.test.metadata;import org.hibernate.Session;import org.hibernate.Transaction;import org.hibernate.test.metadata.inheritance.Carrot;import org.hibernate.test.metadata.inheritance.Vegetable;import org.hibernate.test.metadata.inheritance.VegetablePk;/** * @author Emmanuel Bernard */public class JoinedSubclassTest extends TestCase {	public JoinedSubclassTest(String x) {		super(x);	}		public void testDefaultValues() {		Session s;		Transaction tx;		s = openSession();		tx = s.beginTransaction();		Ferry f = new Ferry();		f.setSize(2);		f.setSea("Channel");		s.persist(f);		tx.commit();		s.close();				s = openSession();		tx = s.beginTransaction();		f = (Ferry) s.get(Ferry.class, f.getId() );		assertNotNull(f);		assertEquals("Channel", f.getSea() );		assertEquals(2, f.getSize() );		tx.commit();		s.close();	}		public void testDeclaredValues() {		Session s;		Transaction tx;		s = openSession();		tx = s.beginTransaction();		Country c = new Country();		c.setName("France");		AmericaCupClass f = new AmericaCupClass();		f.setSize(2);		f.country = c;		s.persist(c);		s.persist(f);		tx.commit();		s.close();				s = openSession();		tx = s.beginTransaction();		f = (AmericaCupClass) s.get(AmericaCupClass.class, f.getId() );		assertNotNull(f);		assertEquals(c, f.country );		assertEquals(2, f.getSize() );		tx.commit();		s.close();	}	public void testCompositePk() throws Exception {		Session s;		Transaction tx;		s = openSession();		tx = s.beginTransaction();		Carrot c = new Carrot();		VegetablePk pk = new VegetablePk();		pk.setFarmer("Bill");		pk.setHarvestDate("2004-08-15");		c.setId(pk);		c.setLength(23);		s.persist(c);		tx.commit();		s.close();		s = openSession();		tx = s.beginTransaction();		Vegetable v = (Vegetable) s.createCriteria(Vegetable.class).uniqueResult();		assertTrue(v instanceof Carrot);		Carrot result = (Carrot) v;		assertEquals( 23, result.getLength() );		tx.commit();		s.close();	}	/**	 * @see org.hibernate.test.metadata.TestCase#getMappings()	 */	protected Class[] getMappings() {		return new Class[] {			Boat.class,			Ferry.class,			AmericaCupClass.class,			Country.class,			Vegetable.class,			Carrot.class		};	}}

⌨️ 快捷键说明

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