[hibernate-commits] Hibernate SVN: r18145 - annotations/branches/v3_3_1_GA_CP/src/test/org/hibernate/test/annotations/cid.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Sat Dec 5 10:45:52 EST 2009


Author: stliu
Date: 2009-12-05 10:45:52 -0500 (Sat, 05 Dec 2009)
New Revision: 18145

Added:
   annotations/branches/v3_3_1_GA_CP/src/test/org/hibernate/test/annotations/cid/SomeEntity.java
   annotations/branches/v3_3_1_GA_CP/src/test/org/hibernate/test/annotations/cid/SomeEntityId.java
Modified:
   annotations/branches/v3_3_1_GA_CP/src/test/org/hibernate/test/annotations/cid/CompositeIdTest.java
Log:
JBPAPP-3223 HHH-3164 id in with EmbeddedId and criteria API

Modified: annotations/branches/v3_3_1_GA_CP/src/test/org/hibernate/test/annotations/cid/CompositeIdTest.java
===================================================================
--- annotations/branches/v3_3_1_GA_CP/src/test/org/hibernate/test/annotations/cid/CompositeIdTest.java	2009-12-05 15:44:55 UTC (rev 18144)
+++ annotations/branches/v3_3_1_GA_CP/src/test/org/hibernate/test/annotations/cid/CompositeIdTest.java	2009-12-05 15:45:52 UTC (rev 18145)
@@ -1,12 +1,17 @@
 //$Id$
 package org.hibernate.test.annotations.cid;
 
+import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
 
+import org.hibernate.Criteria;
 import org.hibernate.Query;
 import org.hibernate.Session;
 import org.hibernate.Transaction;
+import org.hibernate.criterion.Disjunction;
+import org.hibernate.criterion.Restrictions;
+import org.hibernate.dialect.HSQLDialect;
 import org.hibernate.test.annotations.TestCase;
 
 /**
@@ -258,6 +263,61 @@
 		s.close();
 	}
 
+	public void testQueryInAndComposite() {
+		if( getDialect() instanceof HSQLDialect){
+			return;
+		}
+		Session s = openSession(  );
+		Transaction transaction = s.beginTransaction();
+
+		SomeEntity someEntity = new SomeEntity();
+		someEntity.setId( new SomeEntityId( ) );
+		someEntity.getId().setId( 1 );
+		someEntity.getId().setVersion( 11 );
+		someEntity.setProp( "aa" );
+		s.persist( someEntity );
+		someEntity = new SomeEntity();
+		someEntity.setId( new SomeEntityId( ) );
+		someEntity.getId().setId( 1 );
+		someEntity.getId().setVersion( 12 );
+		someEntity.setProp( "bb" );
+		s.persist( someEntity );
+		someEntity = new SomeEntity();
+		someEntity.setId( new SomeEntityId( ) );
+		someEntity.getId().setId( 10 );
+		someEntity.getId().setVersion( 21 );
+		someEntity.setProp( "cc1" );
+		s.persist( someEntity );
+		someEntity = new SomeEntity();
+		someEntity.setId( new SomeEntityId( ) );
+		someEntity.getId().setId( 10 );
+		someEntity.getId().setVersion( 22 );
+		someEntity.setProp( "cc2" );
+		s.persist( someEntity );
+		someEntity = new SomeEntity();
+		someEntity.setId( new SomeEntityId( ) );
+		someEntity.getId().setId( 10 );
+		someEntity.getId().setVersion( 23 );
+		someEntity.setProp( "cc3" );
+		s.persist( someEntity );
+
+		s.flush();
+
+        List ids = new ArrayList<SomeEntityId>(2);
+        ids.add( new SomeEntityId(1,12) );
+        ids.add( new SomeEntityId(10,23) );
+
+        Criteria criteria = s.createCriteria( SomeEntity.class );
+        Disjunction disjunction = Restrictions.disjunction();
+
+        disjunction.add( Restrictions.in( "id", ids  ) );
+        criteria.add( disjunction );
+
+        List list = criteria.list();
+        assertEquals( 2, list.size() );
+		transaction.rollback();
+		s.close();
+	}
 	protected Class[] getMappings() {
 		return new Class[] {
 				Parent.class,
@@ -274,7 +334,8 @@
 				LittleGenius.class,
 				A.class,
 				B.class,
-				C.class
+				C.class,
+				SomeEntity.class
 		};
 	}
 }

Added: annotations/branches/v3_3_1_GA_CP/src/test/org/hibernate/test/annotations/cid/SomeEntity.java
===================================================================
--- annotations/branches/v3_3_1_GA_CP/src/test/org/hibernate/test/annotations/cid/SomeEntity.java	                        (rev 0)
+++ annotations/branches/v3_3_1_GA_CP/src/test/org/hibernate/test/annotations/cid/SomeEntity.java	2009-12-05 15:45:52 UTC (rev 18145)
@@ -0,0 +1,49 @@
+package org.hibernate.test.annotations.cid;
+
+import java.io.Serializable;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.Basic;
+
+/**
+ * @author bartek
+ */
+ at Entity
+public class SomeEntity
+		implements Serializable {
+
+	@Id
+	private SomeEntityId id;
+
+	@Basic
+	private String prop;
+
+	/**
+	 * @return the id
+	 */
+	public SomeEntityId getId() {
+		return id;
+	}
+
+	/**
+	 * @param id the id to set
+	 */
+	public void setId(SomeEntityId id) {
+		this.id = id;
+	}
+
+	/**
+	 * @return the prop
+	 */
+	public String getProp() {
+		return prop;
+	}
+
+	/**
+	 * @param prop the prop to set
+	 */
+	public void setProp(String prop) {
+		this.prop = prop;
+	}
+
+}

Added: annotations/branches/v3_3_1_GA_CP/src/test/org/hibernate/test/annotations/cid/SomeEntityId.java
===================================================================
--- annotations/branches/v3_3_1_GA_CP/src/test/org/hibernate/test/annotations/cid/SomeEntityId.java	                        (rev 0)
+++ annotations/branches/v3_3_1_GA_CP/src/test/org/hibernate/test/annotations/cid/SomeEntityId.java	2009-12-05 15:45:52 UTC (rev 18145)
@@ -0,0 +1,78 @@
+package org.hibernate.test.annotations.cid;
+
+import java.io.Serializable;
+import javax.persistence.Embeddable;
+
+import org.hibernate.annotations.*;
+
+/**
+ * @author bartek
+ */
+ at Embeddable
+public class SomeEntityId implements Serializable {
+	private Integer id;
+
+	private Integer version;
+
+	@org.hibernate.annotations.Parent
+	private SomeEntity parent;
+
+	/**
+	 *
+	 */
+	public SomeEntityId() {
+		super();
+	}
+
+	/**
+	 * @param i
+	 * @param j
+	 */
+	public SomeEntityId(int id, int version) {
+		super();
+		this.id = id;
+		this.version = version;
+	}
+
+	/**
+	 * @return the id
+	 */
+	public int getId() {
+		return id;
+	}
+
+	/**
+	 * @param id the id to set
+	 */
+	public void setId(int id) {
+		this.id = id;
+	}
+
+	/**
+	 * @return the version
+	 */
+	public int getVersion() {
+		return version;
+	}
+
+	/**
+	 * @param version the version to set
+	 */
+	public void setVersion(int version) {
+		this.version = version;
+	}
+
+	/**
+	 * @return the parent
+	 */
+	public SomeEntity getParent() {
+		return parent;
+	}
+
+	/**
+	 * @param parent the parent to set
+	 */
+	public void setParent(SomeEntity parent) {
+		this.parent = parent;
+	}
+}



More information about the hibernate-commits mailing list