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

📄 basichibernateannotationstest.java

📁 hibernate方便的操作数据库相当不错的 请各位下载看看啊
💻 JAVA
字号:
//$Id: BasicHibernateAnnotationsTest.java,v 1.3 2005/02/25 12:44:44 maxcsaucdk Exp $package org.hibernate.test.metadata.entity;import org.hibernate.test.metadata.TestCase;import org.hibernate.*;import java.util.Iterator;/** * @author Emmanuel Bernard */public class BasicHibernateAnnotationsTest extends TestCase {	public void testEntity() throws Exception {		Forest forest = new Forest();		forest.setName("Fontainebleau");		Session s;		Transaction tx;		s = openSession();		tx = s.beginTransaction();		s.persist(forest);		tx.commit();		s.close();		s = openSession();		tx = s.beginTransaction();		forest = (Forest) s.get( Forest.class, forest.getId() );		assertNotNull(forest);		forest.setName("Fontainebleau");		//should not execute SQL update		tx.commit();		s.close();		s = openSession();		tx = s.beginTransaction();		forest = (Forest) s.get( Forest.class, forest.getId() );		assertNotNull(forest);		forest.setLength(23);		//should execute dynamic SQL update		tx.commit();		s.close();	}	public void testVersioning() throws Exception {		Forest forest = new Forest();		forest.setName("Fontainebleau");		forest.setLength(33);		Session s;		Transaction tx;		s = openSession();		tx = s.beginTransaction();		s.persist(forest);		tx.commit();		s.close();		Session parallelSession = openSession();		Transaction parallelTx = parallelSession.beginTransaction();		s = openSession();		tx = s.beginTransaction();		forest = (Forest) parallelSession.get(Forest.class, forest.getId() );		Forest reloadedForest = (Forest) s.get(Forest.class, forest.getId() );		reloadedForest.setLength(11);		assertNotSame(forest, reloadedForest);		tx.commit();		s.close();		forest.setLength(22);		try {			parallelTx.commit();			fail("All optimistic locking should have make it fail");		}		catch (HibernateException e) {		}		parallelSession.close();	}	public void testPolymorphism() throws Exception {		Forest forest = new Forest();		forest.setName("Fontainebleau");		forest.setLength(33);		Session s;		Transaction tx;		s = openSession();		tx = s.beginTransaction();		s.persist(forest);		tx.commit();		s.close();		s = openSession();		tx = s.beginTransaction();		Query query = s.createQuery("from java.lang.Object");		assertEquals( 0, query.list().size() );		query = s.createQuery("from Forest");		assertTrue( 0 < query.list().size() );		tx.commit();		s.close();	}	public void testType() throws Exception {		Forest f = new Forest();		f.setName("Broceliande");		String description = "C'est une enorme foret enchant閑 o

⌨️ 快捷键说明

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