[hibernate-commits] Hibernate SVN: r11640 - trunk/HibernateExt/annotations/src/test/org/hibernate/test/annotations/cid.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Wed Jun 6 10:25:29 EDT 2007


Author: anthonyHib
Date: 2007-06-06 10:25:29 -0400 (Wed, 06 Jun 2007)
New Revision: 11640

Added:
   trunk/HibernateExt/annotations/src/test/org/hibernate/test/annotations/cid/LittleGenius.java
Modified:
   trunk/HibernateExt/annotations/src/test/org/hibernate/test/annotations/cid/Child.java
   trunk/HibernateExt/annotations/src/test/org/hibernate/test/annotations/cid/CompositeIdTest.java
Log:
new unit test, goal is to test a hierarchy with cid containing a many to one

Modified: trunk/HibernateExt/annotations/src/test/org/hibernate/test/annotations/cid/Child.java
===================================================================
--- trunk/HibernateExt/annotations/src/test/org/hibernate/test/annotations/cid/Child.java	2007-06-06 00:45:49 UTC (rev 11639)
+++ trunk/HibernateExt/annotations/src/test/org/hibernate/test/annotations/cid/Child.java	2007-06-06 14:25:29 UTC (rev 11640)
@@ -5,6 +5,8 @@
 import javax.persistence.Column;
 import javax.persistence.EmbeddedId;
 import javax.persistence.Entity;
+import javax.persistence.Inheritance;
+import javax.persistence.InheritanceType;
 
 /**
  * Entity having a many to one in its pk
@@ -12,6 +14,7 @@
  * @author Emmanuel Bernard
  */
 @Entity
+ at Inheritance(strategy = InheritanceType.JOINED)
 public class Child {
 	@EmbeddedId
 	@AttributeOverride(name = "nthChild", column = @Column(name = "nth"))

Modified: trunk/HibernateExt/annotations/src/test/org/hibernate/test/annotations/cid/CompositeIdTest.java
===================================================================
--- trunk/HibernateExt/annotations/src/test/org/hibernate/test/annotations/cid/CompositeIdTest.java	2007-06-06 00:45:49 UTC (rev 11639)
+++ trunk/HibernateExt/annotations/src/test/org/hibernate/test/annotations/cid/CompositeIdTest.java	2007-06-06 14:25:29 UTC (rev 11640)
@@ -24,10 +24,50 @@
 	}
 
 	/**
+		 * This feature is not supported by the EJB3
+		 * this is an hibernate extension
+		 */
+		public void testManyToOneInCompositePk() throws Exception {
+			Session s;
+			Transaction tx;
+			s = openSession();
+			tx = s.beginTransaction();
+			ParentPk ppk = new ParentPk();
+			ppk.setFirstName( "Emmanuel" );
+			ppk.setLastName( "Bernard" );
+			Parent p = new Parent();
+			p.id = ppk;
+			s.persist( p );
+			ChildPk cpk = new ChildPk();
+			cpk.parent = p;
+			cpk.nthChild = 1;
+			Child c = new Child();
+			c.id = cpk;
+			s.persist( c );
+			tx.commit();
+			s.close();
+	
+			s = openSession();
+			tx = s.beginTransaction();
+			Query q = s.createQuery( "select c from Child c where c.id.nthChild = :nth" );
+			q.setInteger( "nth", 1 );
+			List results = q.list();
+			assertEquals( 1, results.size() );
+			c = (Child) results.get( 0 );
+			assertNotNull( c );
+			assertNotNull( c.id.parent );
+			//FIXME mke it work in unambigious cases
+	//		assertNotNull(c.id.parent.id);
+	//		assertEquals(p.id.getFirstName(), c.id.parent.id.getFirstName());
+			tx.commit();
+			s.close();
+		}
+
+	/**
 	 * This feature is not supported by the EJB3
 	 * this is an hibernate extension
 	 */
-	public void testManyToOneInCompositePk() throws Exception {
+	public void testManyToOneInCompositePkAndSubclass() throws Exception {
 		Session s;
 		Transaction tx;
 		s = openSession();
@@ -41,7 +81,8 @@
 		ChildPk cpk = new ChildPk();
 		cpk.parent = p;
 		cpk.nthChild = 1;
-		Child c = new Child();
+		LittleGenius c = new LittleGenius();
+		c.particularSkill = "Human Annotation parser";
 		c.id = cpk;
 		s.persist( c );
 		tx.commit();
@@ -53,7 +94,7 @@
 		q.setInteger( "nth", 1 );
 		List results = q.list();
 		assertEquals( 1, results.size() );
-		c = (Child) results.get( 0 );
+		c = (LittleGenius) results.get( 0 );
 		assertNotNull( c );
 		assertNotNull( c.id.parent );
 		//FIXME mke it work in unambigious cases
@@ -133,7 +174,8 @@
                 Order.class,
                 Product.class,
                 OrderLine.class,
-                OrderLinePk.class
+                OrderLinePk.class,
+                LittleGenius.class
         };
 	}
 }

Added: trunk/HibernateExt/annotations/src/test/org/hibernate/test/annotations/cid/LittleGenius.java
===================================================================
--- trunk/HibernateExt/annotations/src/test/org/hibernate/test/annotations/cid/LittleGenius.java	                        (rev 0)
+++ trunk/HibernateExt/annotations/src/test/org/hibernate/test/annotations/cid/LittleGenius.java	2007-06-06 14:25:29 UTC (rev 11640)
@@ -0,0 +1,19 @@
+package org.hibernate.test.annotations.cid;
+
+import javax.persistence.Entity;
+import javax.persistence.PrimaryKeyJoinColumn;
+import javax.persistence.PrimaryKeyJoinColumns;
+
+/**
+ * Hierarchy with cid + many to one
+ * @author Anthony
+ *
+ */
+ at Entity
+ at PrimaryKeyJoinColumns({
+ at PrimaryKeyJoinColumn(name = "nthChild"),
+ at PrimaryKeyJoinColumn(name = "parentLastName"),
+ at PrimaryKeyJoinColumn(name = "parentFirstName")})
+public class LittleGenius extends Child {
+	public String particularSkill;
+}




More information about the hibernate-commits mailing list