HHH-4895 - query against derived id doesn't return expected result

git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@18754 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
Steve Ebersole 2010-02-09 21:45:15 +00:00
parent c833f33812
commit 0255bb79fc
6 changed files with 86 additions and 11 deletions

View File

@ -1,5 +1,6 @@
package org.hibernate.test.annotations.derivedidentities.e1.a;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.test.annotations.TestCase;
import org.hibernate.test.util.SchemaUtil;
@ -50,14 +51,11 @@ public class DerivedIdentitySimpleParentIdClassDepTest extends TestCase {
// List depList = s.createQuery("Select d from Dependent d where d.name='LittleP'").list();
// the following query is not finding the entity 'd' added above
List depList = s.createQuery("Select d from Dependent d where d.name='LittleP' and d.emp.name='Paula'").list();
Object newDependent = null;
if (depList.size() > 0) {
newDependent = (Dependent) depList.get(0);
}
if (newDependent != d) {
fail("PC entity instance (" + d +") does not match returned query result value (" + newDependent);
}
Query query = s.createQuery("Select d from Dependent d where d.name='LittleP' and d.emp.empName='Paula'");
List depList = query.list();
assertEquals( 1, depList.size() );
Object newDependent = (Dependent) depList.get(0);
assertSame( d, newDependent );
s.getTransaction().rollback();
s.close();
}

View File

@ -30,7 +30,7 @@ log4j.logger.org.hibernate.SQL=debug
#log4j.logger.org.hibernate.engine.CascadingAction=debug
### log JDBC bind parameters ###
log4j.logger.org.hibernate.type=debug
log4j.logger.org.hibernate.type=trace
### log schema export/update ###
log4j.logger.org.hibernate.tool.hbm2ddl=debug

View File

@ -27,6 +27,9 @@ package org.hibernate.persister.entity;
import java.util.HashMap;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.hibernate.MappingException;
import org.hibernate.QueryException;
import org.hibernate.engine.Mapping;
@ -44,6 +47,7 @@ import org.hibernate.util.StringHelper;
* @author Gavin King
*/
public abstract class AbstractPropertyMapping implements PropertyMapping {
private static final Logger log = LoggerFactory.getLogger( AbstractPropertyMapping.class );
private final Map typesByPropertyPath = new HashMap();
private final Map columnsByPropertyPath = new HashMap();
@ -124,9 +128,24 @@ public abstract class AbstractPropertyMapping implements PropertyMapping {
return result;
}
protected void addPropertyPath(String path, Type type, String[] columns,
String[] columnReaders, String[] columnReaderTemplates,
protected void addPropertyPath(
String path,
Type type,
String[] columns,
String[] columnReaders,
String[] columnReaderTemplates,
String[] formulaTemplates) {
// TODO : not quite sure yet of the difference, but this is only needed from annotations for @Id @ManyToOne support
if ( typesByPropertyPath.containsKey( path ) ) {
if ( log.isTraceEnabled() ) {
log.trace(
"Skipping duplicate registration of path [" + path
+ "], existing type = [" + typesByPropertyPath.get(path)
+ "], incoming type = [" + type + "]"
);
}
return;
}
typesByPropertyPath.put(path, type);
columnsByPropertyPath.put(path, columns);
columnReadersByPropertyPath.put(path, columnReaders);

View File

@ -1,5 +1,7 @@
package org.hibernate.test.keymanytoone.bidir.component;
import java.util.List;
import junit.framework.Test;
import org.hibernate.HibernateException;

View File

@ -1,5 +1,7 @@
package org.hibernate.test.keymanytoone.bidir.component;
import java.util.List;
import junit.framework.Test;
import org.hibernate.Session;
@ -29,6 +31,32 @@ public class LazyKeyManyToOneTest extends FunctionalTestCase {
cfg.setProperty( Environment.GENERATE_STATISTICS, "true" );
}
public void testQueryingOnMany2One() {
Session s = openSession();
s.beginTransaction();
Customer cust = new Customer( "Acme, Inc." );
Order order = new Order( new Order.Id( cust, 1 ) );
cust.getOrders().add( order );
s.save( cust );
s.getTransaction().commit();
s.close();
s = openSession();
s.beginTransaction();
List results = s.createQuery( "from Order o where o.id.customer.name = :name" )
.setParameter( "name", cust.getName() )
.list();
assertEquals( 1, results.size() );
s.getTransaction().commit();
s.close();
s = openSession();
s.beginTransaction();
s.delete( cust );
s.getTransaction().commit();
s.close();
}
public void testSaveCascadedToKeyManyToOne() {
// test cascading a save to an association with a key-many-to-one which refers to a
// just saved entity

View File

@ -1,5 +1,7 @@
package org.hibernate.test.keymanytoone.bidir.embedded;
import java.util.List;
import junit.framework.Test;
import org.hibernate.Session;
@ -45,6 +47,32 @@ public class KeyManyToOneTest extends FunctionalTestCase {
s.close();
}
public void testQueryingOnMany2One() {
Session s = openSession();
s.beginTransaction();
Customer cust = new Customer( "Acme, Inc." );
Order order = new Order( cust, 1 );
cust.getOrders().add( order );
s.save( cust );
s.getTransaction().commit();
s.close();
s = openSession();
s.beginTransaction();
List results = s.createQuery( "from Order o where o.customer.name = :name" )
.setParameter( "name", cust.getName() )
.list();
assertEquals( 1, results.size() );
s.getTransaction().commit();
s.close();
s = openSession();
s.beginTransaction();
s.delete( cust );
s.getTransaction().commit();
s.close();
}
public void testLoadingStrategies() {
Session s = openSession();
s.beginTransaction();