Author: stliu
Date: 2009-12-05 10:36:35 -0500 (Sat, 05 Dec 2009)
New Revision: 18142
Added:
annotations/branches/v3_4_0_GA_CP/src/test/java/org/hibernate/test/annotations/cid/SomeEntity.java
annotations/branches/v3_4_0_GA_CP/src/test/java/org/hibernate/test/annotations/cid/SomeEntityId.java
Modified:
annotations/branches/v3_4_0_GA_CP/src/test/java/org/hibernate/test/annotations/cid/CompositeIdTest.java
Log:
JBPAPP-3223 HHH-3164 id in with EmbeddedId and criteria API
Modified:
annotations/branches/v3_4_0_GA_CP/src/test/java/org/hibernate/test/annotations/cid/CompositeIdTest.java
===================================================================
---
annotations/branches/v3_4_0_GA_CP/src/test/java/org/hibernate/test/annotations/cid/CompositeIdTest.java 2009-12-05
12:07:27 UTC (rev 18141)
+++
annotations/branches/v3_4_0_GA_CP/src/test/java/org/hibernate/test/annotations/cid/CompositeIdTest.java 2009-12-05
15:36:35 UTC (rev 18142)
@@ -1,12 +1,18 @@
//$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.Dialect;
+import org.hibernate.dialect.HSQLDialect;
import org.hibernate.test.annotations.TestCase;
/**
@@ -258,6 +264,61 @@
s.close();
}
+ public void testQueryInAndComposite() {
+ if(Dialect.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 +335,8 @@
LittleGenius.class,
A.class,
B.class,
- C.class
+ C.class,
+ SomeEntity.class
};
}
}
Added:
annotations/branches/v3_4_0_GA_CP/src/test/java/org/hibernate/test/annotations/cid/SomeEntity.java
===================================================================
---
annotations/branches/v3_4_0_GA_CP/src/test/java/org/hibernate/test/annotations/cid/SomeEntity.java
(rev 0)
+++
annotations/branches/v3_4_0_GA_CP/src/test/java/org/hibernate/test/annotations/cid/SomeEntity.java 2009-12-05
15:36:35 UTC (rev 18142)
@@ -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
+ */
+@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_4_0_GA_CP/src/test/java/org/hibernate/test/annotations/cid/SomeEntityId.java
===================================================================
---
annotations/branches/v3_4_0_GA_CP/src/test/java/org/hibernate/test/annotations/cid/SomeEntityId.java
(rev 0)
+++
annotations/branches/v3_4_0_GA_CP/src/test/java/org/hibernate/test/annotations/cid/SomeEntityId.java 2009-12-05
15:36:35 UTC (rev 18142)
@@ -0,0 +1,78 @@
+package org.hibernate.test.annotations.cid;
+
+import java.io.Serializable;
+import javax.persistence.Embeddable;
+
+import org.hibernate.annotations.*;
+
+/**
+ * @author bartek
+ */
+@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;
+ }
+}