HHH-3164 add test

git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@18026 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
Emmanuel Bernard 2009-11-23 18:08:09 +00:00
parent deabfeb485
commit 1ca018960e
3 changed files with 191 additions and 1 deletions

View File

@ -3,11 +3,17 @@ package org.hibernate.test.annotations.cid;
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 @@ public class CompositeIdTest extends TestCase {
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 @@ public class CompositeIdTest extends TestCase {
LittleGenius.class,
A.class,
B.class,
C.class
C.class,
SomeEntity.class
};
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}