【Java开源代码栏目提醒】:网学会员,鉴于大家对Java开源代码十分关注,论文会员在此为大家搜集整理了“CompositeElementTest.java”一文,供大家参考学习!
//$Id: CompositeElementTest.java 4478 2004-09-02 02:30:28Z oneovthafew $
package org.hibernate.test.compositeelement;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.test.TestCase;
/**
* @author Gavin King
*/
public class CompositeElementTest extends TestCase {
public CompositeElementTest(String str) {
super(str);
}
public void testHandSQL() {
Session s = openSession();
Transaction t = s.beginTransaction();
Child c = new Child("Child One");
Parent p = new Parent("Parent");
p.getChildren().add(c);
c.setParent(p);
s.save(p);
s.flush();
p.getChildren().remove(c);
c.setParent(null);
s.flush();
p.getChildren().add(c);
c.setParent(p);
t.commit();
s.close();
s = openSession();
t = s.beginTransaction();
s.createQuery("select distinct p from Parent p join p.children c where c.name like 'Child%'").uniqueResult();
s.clear();
s.createQuery("select new Child(c.name) from Parent p left outer join p.children c where c.name like 'Child%'").uniqueResult();
s.clear();
//s.createQuery("select c from Parent p left outer join p.children c where c.name like 'Child%'").uniqueResult(); //we really need to be able to do this!
s.clear();
p = (Parent) s.createQuery("from Parent p left join fetch p.children").uniqueResult();
t.commit();
s.close();
}
protected String[] getMappings() {
return new String[] { "compositeelement/Parent.hbm.xml" };
}
public static Test suite() {
return new TestSuite(CompositeElementTest.class);
}
}
上一篇:
CompositeElementPropertyMapping.java
下一篇:
时间飞过,而你却不曾来过我的世界(2)