Author: stliu
Date: 2010-03-31 03:52:25 -0400 (Wed, 31 Mar 2010)
New Revision: 19145
Modified:
core/branches/hibernate-3.3.2.GA_JBPAPP-4038/core/src/main/java/org/hibernate/hql/ast/tree/BinaryLogicOperatorNode.java
core/branches/hibernate-3.3.2.GA_JBPAPP-4038/testsuite/src/test/java/org/hibernate/test/hql/ASTParserLoadingTest.java
Log:
JBPAPP-4038 HHH-2088 TypeMismatchException on object equality expression from one-to-one
relationship
Modified:
core/branches/hibernate-3.3.2.GA_JBPAPP-4038/core/src/main/java/org/hibernate/hql/ast/tree/BinaryLogicOperatorNode.java
===================================================================
---
core/branches/hibernate-3.3.2.GA_JBPAPP-4038/core/src/main/java/org/hibernate/hql/ast/tree/BinaryLogicOperatorNode.java 2010-03-31
07:34:02 UTC (rev 19144)
+++
core/branches/hibernate-3.3.2.GA_JBPAPP-4038/core/src/main/java/org/hibernate/hql/ast/tree/BinaryLogicOperatorNode.java 2010-03-31
07:52:25 UTC (rev 19145)
@@ -23,6 +23,7 @@
*/
package org.hibernate.hql.ast.tree;
+import org.hibernate.type.OneToOneType;
import org.hibernate.type.Type;
import org.hibernate.Hibernate;
import org.hibernate.TypeMismatchException;
@@ -80,8 +81,8 @@
// resolve an expected type
SessionFactoryImplementor sessionFactory = getSessionFactoryHelper().getFactory();
if ( lhsType != null && rhsType != null ) {
- int lhsColumnSpan = lhsType.getColumnSpan( sessionFactory );
- if ( lhsColumnSpan != rhsType.getColumnSpan( sessionFactory ) ) {
+ int lhsColumnSpan = getColumnSpan( lhsType, sessionFactory );
+ if ( lhsColumnSpan != getColumnSpan( rhsType, sessionFactory ) ) {
throw new TypeMismatchException(
"left and right hand sides of a binary logic operator were incompatibile
[" +
lhsType.getName() + " : "+ rhsType.getName() + "]"
@@ -97,6 +98,15 @@
}
}
+ private int getColumnSpan( Type type, SessionFactoryImplementor sfi ) {
+ int columnSpan = type.getColumnSpan( sfi );
+ if ( columnSpan == 0 && type instanceof OneToOneType ) {
+ columnSpan = ( (OneToOneType) type ).getIdentifierOrUniqueKeyType( sfi
).getColumnSpan(
+ sfi );
+ }
+ return columnSpan;
+ }
+
/**
* Mutate the subtree relating to a row-value-constructor to instead use
* a series of ANDed predicates. This allows multi-column type comparisons
Modified:
core/branches/hibernate-3.3.2.GA_JBPAPP-4038/testsuite/src/test/java/org/hibernate/test/hql/ASTParserLoadingTest.java
===================================================================
---
core/branches/hibernate-3.3.2.GA_JBPAPP-4038/testsuite/src/test/java/org/hibernate/test/hql/ASTParserLoadingTest.java 2010-03-31
07:34:02 UTC (rev 19144)
+++
core/branches/hibernate-3.3.2.GA_JBPAPP-4038/testsuite/src/test/java/org/hibernate/test/hql/ASTParserLoadingTest.java 2010-03-31
07:52:25 UTC (rev 19145)
@@ -391,6 +391,31 @@
return count;
}
+ public void testEntityAndOneToOneReturnedByQuery() {
+ Session s = openSession();
+ s.beginTransaction();
+ Human h = new Human();
+ h.setName( new Name( "Gail", null, "Badner" ) );
+ s.save( h );
+ User u = new User();
+ u.setUserName( "gbadner" );
+ u.setHuman( h );
+ s.save( u );
+ s.getTransaction().commit();
+ s.close();
+
+ s = openSession();
+ s.beginTransaction();
+ Object [] result = ( Object [] ) s.createQuery( "from User u, Human h where
u.human = h" ).uniqueResult();
+ assertNotNull( result );
+ assertEquals( u.getUserName(), ( ( User ) result[ 0 ] ).getUserName() );
+ assertEquals( h.getName().getFirst(), ( ( Human ) result[ 1 ] ).getName().getFirst()
);
+ assertSame( ( ( User ) result[ 0 ] ).getHuman(), result[ 1 ] );
+ s.createQuery( "delete User" ).executeUpdate();
+ s.createQuery( "delete Human" ).executeUpdate();
+ s.getTransaction().commit();
+ s.close();
+ }
public void testNestedComponentIsNull() {
// (1) From MapTest originally...
// (2) Was then moved into HQLTest...