Author: epbernard
Date: 2009-11-23 13:08:09 -0500 (Mon, 23 Nov 2009)
New Revision: 18026
Added:
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/cid/SomeEntity.java
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/cid/SomeEntityId.java
Modified:
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/cid/CompositeIdTest.java
Log:
HHH-3164 add test
Modified:
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/cid/CompositeIdTest.java
===================================================================
---
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/cid/CompositeIdTest.java 2009-11-23
15:51:56 UTC (rev 18025)
+++
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/cid/CompositeIdTest.java 2009-11-23
18:08:09 UTC (rev 18026)
@@ -3,11 +3,17 @@
import java.util.Date;
import java.util.List;
+import java.util.ArrayList;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
+import org.hibernate.Criteria;
+import org.hibernate.dialect.HSQLDialect;
+import org.hibernate.criterion.Disjunction;
+import org.hibernate.criterion.Restrictions;
import org.hibernate.test.annotations.TestCase;
+import org.hibernate.test.annotations.SkipForDialect;
/**
* test some composite id functionalities
@@ -248,6 +254,62 @@
s.close();
}
+ @SkipForDialect(value=org.hibernate.dialect.HSQLDialect.class,
+ comment = "HSQLDB does not support ((..., ...),(..., ...))")
+ public void testQueryInAndComposite() {
+
+ 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,
@@ -264,7 +326,8 @@
LittleGenius.class,
A.class,
B.class,
- C.class
+ C.class,
+ SomeEntity.class
};
}
}
Added:
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/cid/SomeEntity.java
===================================================================
---
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/cid/SomeEntity.java
(rev 0)
+++
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/cid/SomeEntity.java 2009-11-23
18:08:09 UTC (rev 18026)
@@ -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:
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/cid/SomeEntityId.java
===================================================================
---
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/cid/SomeEntityId.java
(rev 0)
+++
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/cid/SomeEntityId.java 2009-11-23
18:08:09 UTC (rev 18026)
@@ -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;
+ }
+}