account for more failures on h2 (only 1 more!)
git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@19574 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
parent
78c8c6fb6a
commit
c0361d566b
|
@ -9,7 +9,8 @@ public class Child {
|
|||
private String bio;
|
||||
private Parent parent;
|
||||
private int bioLength;
|
||||
private double heightInches;
|
||||
private int position;
|
||||
|
||||
Child() {}
|
||||
public Child(String name) {
|
||||
this.name = name;
|
||||
|
@ -44,12 +45,15 @@ public class Child {
|
|||
public void setBio(String bio) {
|
||||
this.bio = bio;
|
||||
}
|
||||
public double getHeightInches() {
|
||||
return heightInches;
|
||||
|
||||
public int getPosition() {
|
||||
return position;
|
||||
}
|
||||
public void setHeightInches(double heightInches) {
|
||||
this.heightInches = heightInches;
|
||||
}
|
||||
|
||||
public void setPosition(int position) {
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return name.hashCode();
|
||||
}
|
||||
|
|
|
@ -88,47 +88,37 @@ public class CompositeElementTest extends FunctionalTestCase {
|
|||
}
|
||||
|
||||
public void testCustomColumnReadAndWrite() {
|
||||
final double HEIGHT_INCHES = 49;
|
||||
final double HEIGHT_CENTIMETERS = HEIGHT_INCHES * 2.54d;
|
||||
|
||||
Session s = openSession();
|
||||
Transaction t = s.beginTransaction();
|
||||
Child c = new Child( "Child One" );
|
||||
c.setHeightInches(HEIGHT_INCHES);
|
||||
c.setPosition( 1 );
|
||||
Parent p = new Parent( "Parent" );
|
||||
p.getChildren().add( c );
|
||||
c.setParent( p );
|
||||
s.save( p );
|
||||
s.flush();
|
||||
|
||||
// Test value conversion during insert
|
||||
Double heightViaSql = (Double)s.createSQLQuery("select height_centimeters from parentchild c where c.name='Child One'")
|
||||
.uniqueResult();
|
||||
assertEquals(HEIGHT_CENTIMETERS, heightViaSql, 0.01d);
|
||||
|
||||
// Test projection
|
||||
Double heightViaHql = (Double)s.createQuery("select c.heightInches from Parent p join p.children c where p.name='Parent'")
|
||||
.uniqueResult();
|
||||
assertEquals(HEIGHT_INCHES, heightViaHql, 0.01d);
|
||||
|
||||
// Test entity load via criteria
|
||||
Integer sqlValue = (Integer) s.createSQLQuery("select child_position from parentchild c where c.name='Child One'")
|
||||
.uniqueResult();
|
||||
assertEquals( 0, sqlValue.intValue() );
|
||||
|
||||
Integer hqlValue = (Integer)s.createQuery("select c.position from Parent p join p.children c where p.name='Parent'")
|
||||
.uniqueResult();
|
||||
assertEquals( 1, hqlValue.intValue() );
|
||||
|
||||
p = (Parent)s.createCriteria(Parent.class).add(Restrictions.eq("name", "Parent")).uniqueResult();
|
||||
c = (Child)p.getChildren().iterator().next();
|
||||
assertEquals(HEIGHT_INCHES, c.getHeightInches(), 0.01d);
|
||||
|
||||
// Test predicate and entity load via HQL
|
||||
p = (Parent)s.createQuery("from Parent p join p.children c where c.heightInches between ? and ?")
|
||||
.setDouble(0, HEIGHT_INCHES - 0.01d)
|
||||
.setDouble(1, HEIGHT_INCHES + 0.01d)
|
||||
.uniqueResult();
|
||||
assertEquals( 1, c.getPosition() );
|
||||
|
||||
p = (Parent)s.createQuery("from Parent p join p.children c where c.position = 1").uniqueResult();
|
||||
c = (Child)p.getChildren().iterator().next();
|
||||
assertEquals(HEIGHT_INCHES, c.getHeightInches(), 0.01d);
|
||||
|
||||
// Test update
|
||||
c.setHeightInches(1);
|
||||
assertEquals( 1, c.getPosition() );
|
||||
|
||||
c.setPosition( 2 );
|
||||
s.flush();
|
||||
heightViaSql = (Double)s.createSQLQuery("select height_centimeters from parentchild c where c.name='Child One'").uniqueResult();
|
||||
assertEquals(2.54d, heightViaSql, 0.01d);
|
||||
sqlValue = (Integer) s.createSQLQuery("select child_position from parentchild c where c.name='Child One'")
|
||||
.uniqueResult();
|
||||
assertEquals( 1, sqlValue.intValue() );
|
||||
s.delete( p );
|
||||
t.commit();
|
||||
s.close();
|
||||
|
|
|
@ -28,11 +28,11 @@
|
|||
<property name="name" not-null="true"/>
|
||||
<property name="bio"/>
|
||||
<property name="bioLength" formula="length(bio)"/>
|
||||
<property name="heightInches">
|
||||
<column name="height_centimeters"
|
||||
not-null="true"
|
||||
read="height_centimeters / 2.54"
|
||||
write="? * 2.54"/>
|
||||
<property name="position">
|
||||
<column name="child_position"
|
||||
not-null="true"
|
||||
read="child_position + 1"
|
||||
write="? - 1"/>
|
||||
</property>
|
||||
</composite-element>
|
||||
</set>
|
||||
|
|
|
@ -26,6 +26,7 @@ import org.hibernate.TypeMismatchException;
|
|||
import org.hibernate.cfg.Configuration;
|
||||
import org.hibernate.cfg.Environment;
|
||||
import org.hibernate.dialect.DB2Dialect;
|
||||
import org.hibernate.dialect.H2Dialect;
|
||||
import org.hibernate.dialect.HSQLDialect;
|
||||
import org.hibernate.dialect.IngresDialect;
|
||||
import org.hibernate.dialect.MySQLDialect;
|
||||
|
@ -1370,9 +1371,11 @@ public class ASTParserLoadingTest extends FunctionalTestCase {
|
|||
Object bodyWeight = s.createQuery("select cast(bodyWeight as integer) from Animal").uniqueResult();
|
||||
assertTrue( Integer.class.isInstance( bodyWeight ) );
|
||||
assertEquals( 12, bodyWeight );
|
||||
|
||||
bodyWeight = s.createQuery("select cast(bodyWeight as big_decimal) from Animal").uniqueResult();
|
||||
assertTrue( BigDecimal.class.isInstance( bodyWeight ) );
|
||||
assertEquals( BigDecimal.valueOf( a.getBodyWeight() ), bodyWeight );
|
||||
assertEquals( a.getBodyWeight(), ( (BigDecimal) bodyWeight ).floatValue() );
|
||||
|
||||
Object literal = s.createQuery("select cast(10000000 as big_integer) from Animal").uniqueResult();
|
||||
assertTrue( BigInteger.class.isInstance( literal ) );
|
||||
assertEquals( BigInteger.valueOf( 10000000 ), literal );
|
||||
|
|
|
@ -15,6 +15,7 @@ import org.hibernate.HibernateException;
|
|||
import org.hibernate.Query;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.hibernate.dialect.H2Dialect;
|
||||
import org.hibernate.util.ArrayHelper;
|
||||
import org.hibernate.test.sql.hand.Organization;
|
||||
import org.hibernate.test.sql.hand.Person;
|
||||
|
@ -112,6 +113,11 @@ public class NativeSQLQueriesTest extends FunctionalTestCase {
|
|||
// there is actually an exception thrown, but it is the database
|
||||
// throwing a sql exception because the SQL gets passed
|
||||
// "un-processed"...
|
||||
//
|
||||
// Oddly, H2 accepts this query.
|
||||
if ( H2Dialect.class.isInstance( getDialect() ) ) {
|
||||
return;
|
||||
}
|
||||
Session s = openSession();
|
||||
s.beginTransaction();
|
||||
try {
|
||||
|
|
Loading…
Reference in New Issue