idtest.java

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

JAVA
87
字号
//$Id: IdTest.java,v 1.4 2005/02/25 12:44:44 maxcsaucdk Exp $package org.hibernate.test.metadata.id;import org.hibernate.Session;import org.hibernate.Transaction;import org.hibernate.test.metadata.TestCase;/** * @author Emmanuel Bernard */public class IdTest extends TestCase {	public IdTest(String x) {		super(x);	}		public void testTableGenerator() throws Exception {		Session s = openSession();		Transaction tx = s.beginTransaction();		Ball b = new Ball();		Dog d = new Dog();		Computer c = new Computer();		s.persist(b);		s.persist(d);		s.persist(c);		tx.commit();		s.close();		assertEquals( "table id not generated", new Long(1), b.getId() );		assertEquals( "generator should not be shared", new Integer(1), d.getId() );		assertEquals( "default value should work", new Long(1), c.getId() );	}		public void testSequenceGenerator() throws Exception {		Session s = openSession();		Transaction tx = s.beginTransaction();		Shoe b = new Shoe();		s.persist(b);		tx.commit();		s.close();		assertNotNull( b.getId() );	}		public void testClassLevelGenerator() throws Exception {		Session s = openSession();		Transaction tx = s.beginTransaction();		Store b = new Store();		s.persist(b);		tx.commit();		s.close();		assertNotNull( b.getId() );	}		public void testMethodLevelGenerator() throws Exception {		Session s = openSession();		Transaction tx = s.beginTransaction();		Department b = new Department();		s.persist(b);		tx.commit();		s.close();		assertNotNull( b.getId() );	}	/**	 * @see org.hibernate.test.metadata.TestCase#getMappings()	 */	protected Class[] getMappings() {		return new Class[] {			Ball.class,			Shoe.class,			Store.class,			Department.class,			Dog.class,			Computer.class		};	}	/**	 * @see org.hibernate.test.metadata.TestCase#getAnnotatedPackages()	 */	protected String[] getAnnotatedPackages() {		return new String[] {			"org.hibernate.test.metadata"		};	}}

⌨️ 快捷键说明

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