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

📄 extendstest.java

📁 介绍了hibernate的入门有一些基本常用的事例
💻 JAVA
字号:
//$Id: ExtendsTest.java,v 1.7 2005/04/11 12:37:24 maxcsaucdk Exp $package org.hibernate.test.extendshbm;import junit.framework.Test;import junit.framework.TestSuite;import org.hibernate.HibernateException;import org.hibernate.cfg.Configuration;import org.hibernate.test.TestCase;/** * @author Gavin King */public class ExtendsTest extends TestCase {		public ExtendsTest(String str) {		super(str);	}	    public void testAllInOne() {        assertNotNull(getCfg().getClassMapping("org.hibernate.test.extendshbm.Customer"));        assertNotNull(getCfg().getClassMapping("org.hibernate.test.extendshbm.Person"));        assertNotNull(getCfg().getClassMapping("org.hibernate.test.extendshbm.Employee"));        }    	public void testOutOfOrder() {        Configuration cfg = new Configuration();                try {            cfg.addResource(getBaseForMappings() + "extendshbm/Customer.hbm.xml");            assertNull("cannot be in the configuration yet!", cfg.getClassMapping("org.hibernate.test.extendshbm.Customer"));            cfg.addResource(getBaseForMappings() + "extendshbm/Person.hbm.xml");            cfg.addResource(getBaseForMappings() + "extendshbm/Employee.hbm.xml");                        cfg.buildSessionFactory();                    assertNotNull(cfg.getClassMapping("org.hibernate.test.extendshbm.Customer"));            assertNotNull(cfg.getClassMapping("org.hibernate.test.extendshbm.Person"));            assertNotNull(cfg.getClassMapping("org.hibernate.test.extendshbm.Employee"));                    } catch(HibernateException e) {            fail("should not fail with exception! " + e);        }        	}	public void testNwaitingForSuper() {        Configuration cfg = new Configuration();                try {            cfg.addResource(getBaseForMappings() + "extendshbm/Customer.hbm.xml");            assertNull("cannot be in the configuration yet!", cfg.getClassMapping("org.hibernate.test.extendshbm.Customer"));            cfg.addResource(getBaseForMappings() + "extendshbm/Employee.hbm.xml");			assertNull("cannot be in the configuration yet!", cfg.getClassMapping("org.hibernate.test.extendshbm.Employee"));			cfg.addResource(getBaseForMappings() + "extendshbm/Person.hbm.xml");                        cfg.buildMappings();        			assertNotNull(cfg.getClassMapping("org.hibernate.test.extendshbm.Person"));            assertNotNull(cfg.getClassMapping("org.hibernate.test.extendshbm.Employee"));			assertNotNull(cfg.getClassMapping("org.hibernate.test.extendshbm.Customer"));                                } catch(HibernateException e) {			e.printStackTrace();			fail("should not fail with exception! " + e);			        }        	}	    public void testMissingSuper() {        Configuration cfg = new Configuration();                try {            cfg.addResource(getBaseForMappings() + "extendshbm/Customer.hbm.xml");            assertNull("cannot be in the configuration yet!", cfg.getClassMapping("org.hibernate.test.extendshbm.Customer"));            cfg.addResource(getBaseForMappings() + "extendshbm/Employee.hbm.xml");                        cfg.buildSessionFactory();                    fail("Should not be able to build sessionfactory without a Person");        } catch(HibernateException e) {                    }            }	    public void testAllSeparateInOne() {        Configuration cfg = new Configuration();                try {            cfg.addResource(getBaseForMappings() + "extendshbm/allseparateinone.hbm.xml");                        cfg.buildSessionFactory();                    assertNotNull(cfg.getClassMapping("org.hibernate.test.extendshbm.Customer"));            assertNotNull(cfg.getClassMapping("org.hibernate.test.extendshbm.Person"));            assertNotNull(cfg.getClassMapping("org.hibernate.test.extendshbm.Employee"));                    } catch(HibernateException e) {            fail("should not fail with exception! " + e);        }    	    }    	public void testJoinedSubclassAndEntityNamesOnly() {		        Configuration cfg = new Configuration();				try {            cfg.addResource(getBaseForMappings() + "extendshbm/entitynames.hbm.xml");                        cfg.buildMappings();                    assertNotNull(cfg.getClassMapping("EntityHasName"));            assertNotNull(cfg.getClassMapping("EntityCompany"));                                } catch(HibernateException e) {			e.printStackTrace();            fail("should not fail with exception! " + e);			        }	}   	public void testUnionSubclass() {		        Configuration cfg = new Configuration();				try {            cfg.addResource(getBaseForMappings() + "extendshbm/unionsubclass.hbm.xml");                        cfg.buildMappings();                    assertNotNull(cfg.getClassMapping("org.hibernate.test.extendshbm.Person"));            assertNotNull(cfg.getClassMapping("org.hibernate.test.extendshbm.Customer"));                                } catch(HibernateException e) {			e.printStackTrace();            fail("should not fail with exception! " + e);			        }	}	protected String[] getMappings() {		return new String[] { "extendshbm/allinone.hbm.xml" };	}	public static Test suite() {		return new TestSuite(ExtendsTest.class);	}}

⌨️ 快捷键说明

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