configurationtest.java

来自「hibernate方便的操作数据库相当不错的 请各位下载看看啊」· Java 代码 · 共 44 行

JAVA
44
字号
//$Id: ConfigurationTest.java,v 1.2 2005/01/18 00:50:16 epbernard Exp $package org.hibernate.test.metadata;import org.hibernate.cfg.AnnotationConfiguration;import org.hibernate.cfg.Environment;import org.hibernate.cfg.Configuration;import org.hibernate.SessionFactory;import org.hibernate.Session;import org.hibernate.Query;import org.hibernate.Transaction;import org.hibernate.MappingException;/** * @author Emmanuel Bernard */public class ConfigurationTest extends junit.framework.TestCase {	public void testDeclarativeMix() throws Exception {		AnnotationConfiguration cfg = new AnnotationConfiguration();		cfg.configure("org/hibernate/test/metadata/hibernate.cfg.xml");		cfg.setProperty(Environment.HBM2DDL_AUTO, "create-drop");		SessionFactory sf = cfg.buildSessionFactory();		assertNotNull(sf);		Session s = sf.openSession();		Transaction tx = s.beginTransaction();		Query q = s.createQuery("from Boat");		assertEquals(0, q.list().size());		q = s.createQuery("from Plane");		assertEquals(0, q.list().size());		tx.commit();		s.close();		sf.close();	}	public void testDeclarativeAnnWoAnnConfig() throws Exception {		Configuration cfg = new Configuration ();		try {			cfg.configure("org/hibernate/test/metadata/hibernate.cfg.xml");			fail("Configuration object should fail when finding annotated elements declarations");		} catch (MappingException e) {			//success		}	}}

⌨️ 快捷键说明

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