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

📄 jointest.java

📁 hibernate方便的操作数据库相当不错的 请各位下载看看啊
💻 JAVA
字号:
//$Id: JoinTest.java,v 1.5 2005/02/26 00:57:39 epbernard Exp $package org.hibernate.test.metadata.join;import java.util.Date;import org.hibernate.Criteria;import org.hibernate.Query;import org.hibernate.Session;import org.hibernate.Transaction;import org.hibernate.HibernateException;import org.hibernate.criterion.Expression;import org.hibernate.test.metadata.TestCase;/** * @author Emmanuel Bernard */public class JoinTest extends TestCase {	public JoinTest(String x) {		super(x);	}		public void testDefaultValue() throws Exception {		Session s = openSession();		Transaction tx = s.beginTransaction();		Life life = new Life();		life.duration = 15;		life.fullDescription = "Long long description";		s.persist(life);		tx.commit();		s.close();				s = openSession();		tx = s.beginTransaction();		Query q = s.createQuery( "from " + Life.class.getName() );		life = (Life) q.uniqueResult();		assertEquals("Long long description", life.fullDescription);		tx.commit();		s.close();	}    public void testCompositePK() throws Exception {		Session s = openSession();		Transaction tx = s.beginTransaction();		Dog dog = new Dog();        DogPk id = new DogPk();        id.name = "Thalie";        id.ownerName = "Martine";        dog.id = id;        dog.weight = 30;        dog.thoroughbredName = "Colley";		s.persist(dog);		tx.commit();		s.close();		s = openSession();		tx = s.beginTransaction();		Query q = s.createQuery( "from Dog" );		dog = (Dog) q.uniqueResult();		assertEquals("Colley", dog.thoroughbredName);		tx.commit();		s.close();	}	public void testExplicitValue() throws Exception {		Session s = openSession();		Transaction tx = s.beginTransaction();		Death death = new Death();		death.date = new Date();		death.howDoesItHappen = "Well, haven't seen it";		s.persist(death);		tx.commit();		s.close();				s = openSession();		tx = s.beginTransaction();		Query q = s.createQuery( "from " + Death.class.getName() );		death = (Death) q.uniqueResult();		assertEquals("Well, haven't seen it", death.howDoesItHappen);		tx.commit();		s.close();	}		public void testManyToOne() throws Exception {		Session s = openSession();		Transaction tx = s.beginTransaction();		Life life = new Life();		Cat cat = new Cat();		cat.setName("kitty");		life.duration = 15;		life.fullDescription = "Long long description";		life.owner = cat;		s.persist(life);		tx.commit();		s.close();				s = openSession();		tx = s.beginTransaction();		Criteria crit = s.createCriteria(Life.class);		crit.createCriteria("owner").add(Expression.eq("name", "kitty") );		life = (Life) crit.uniqueResult();		assertEquals("Long long description", life.fullDescription);		tx.commit();		s.close();	}	public void testUniqueConstaintOnSecondaryTable() throws Exception {		Cat cat = new Cat();		cat.setStoryPart2("My long story");		Cat cat2 = new Cat();		cat2.setStoryPart2("My long story");		Session s = openSession();		Transaction tx = s.beginTransaction();		try {			s.persist(cat);			s.persist(cat2);			tx.commit();			fail("unique constraints violation on secondary table");		}		catch (HibernateException e) {			//success		} finally {			s.close();		}	}	/**	 * @see org.hibernate.test.metadata.TestCase#getMappings()	 */	protected Class[] getMappings() {		return new Class[] {			Life.class,			Death.class,			Cat.class,            Dog.class		};	}}

⌨️ 快捷键说明

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