diff --git a/core/src/main/java/org/hibernate/tuple/entity/PojoEntityTuplizer.java b/core/src/main/java/org/hibernate/tuple/entity/PojoEntityTuplizer.java index ae1f1820a6..fdae321808 100644 --- a/core/src/main/java/org/hibernate/tuple/entity/PojoEntityTuplizer.java +++ b/core/src/main/java/org/hibernate/tuple/entity/PojoEntityTuplizer.java @@ -116,7 +116,7 @@ public PojoEntityTuplizer(EntityMetamodel entityMetamodel, PersistentClass mappe protected ProxyFactory buildProxyFactory(PersistentClass persistentClass, Getter idGetter, Setter idSetter) { // determine the id getter and setter methods from the proxy interface (if any) // determine all interfaces needed by the resulting proxy - HashSet proxyInterfaces = new HashSet(); + HashSet proxyInterfaces = new HashSet(); proxyInterfaces.add( HibernateProxy.class ); Class mappedClass = persistentClass.getMappedClass(); @@ -125,9 +125,8 @@ protected ProxyFactory buildProxyFactory(PersistentClass persistentClass, Getter if ( proxyInterface!=null && !mappedClass.equals( proxyInterface ) ) { if ( !proxyInterface.isInterface() ) { throw new MappingException( - "proxy must be either an interface, or the class itself: " + - getEntityName() - ); + "proxy must be either an interface, or the class itself: " + getEntityName() + ); } proxyInterfaces.add( proxyInterface ); } @@ -136,16 +135,15 @@ protected ProxyFactory buildProxyFactory(PersistentClass persistentClass, Getter proxyInterfaces.add( mappedClass ); } - Iterator iter = persistentClass.getSubclassIterator(); - while ( iter.hasNext() ) { - Subclass subclass = ( Subclass ) iter.next(); - Class subclassProxy = subclass.getProxyInterface(); - Class subclassClass = subclass.getMappedClass(); + Iterator subclasses = persistentClass.getSubclassIterator(); + while ( subclasses.hasNext() ) { + final Subclass subclass = ( Subclass ) subclasses.next(); + final Class subclassProxy = subclass.getProxyInterface(); + final Class subclassClass = subclass.getMappedClass(); if ( subclassProxy!=null && !subclassClass.equals( subclassProxy ) ) { - if ( !proxyInterface.isInterface() ) { + if ( !subclassProxy.isInterface() ) { throw new MappingException( - "proxy must be either an interface, or the class itself: " + - subclass.getEntityName() + "proxy must be either an interface, or the class itself: " + subclass.getEntityName() ); } proxyInterfaces.add( subclassProxy ); diff --git a/core/src/test/java/org/hibernate/subclassProxyInterface/Doctor.java b/core/src/test/java/org/hibernate/subclassProxyInterface/Doctor.java new file mode 100644 index 0000000000..e84da0e769 --- /dev/null +++ b/core/src/test/java/org/hibernate/subclassProxyInterface/Doctor.java @@ -0,0 +1,40 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2010, Red Hat Inc. or third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by Red Hat Inc. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ +package org.hibernate.subclassProxyInterface; + +/** + * @author Steve Ebersole + */ +public class Doctor extends Person implements IDoctor { + public Doctor() { + } + + public Doctor(String name) { + super( name ); + } + + public String operate() { + return "Dr. " + getName() + " is in"; + } +} diff --git a/core/src/test/java/org/hibernate/subclassProxyInterface/IDoctor.java b/core/src/test/java/org/hibernate/subclassProxyInterface/IDoctor.java new file mode 100644 index 0000000000..e66f32f1c1 --- /dev/null +++ b/core/src/test/java/org/hibernate/subclassProxyInterface/IDoctor.java @@ -0,0 +1,31 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2010, Red Hat Inc. or third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by Red Hat Inc. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ +package org.hibernate.subclassProxyInterface; + +/** + * @author Steve Ebersole + */ +public interface IDoctor { + String operate(); +} diff --git a/core/src/test/java/org/hibernate/subclassProxyInterface/Person.hbm.xml b/core/src/test/java/org/hibernate/subclassProxyInterface/Person.hbm.xml new file mode 100644 index 0000000000..3a36635278 --- /dev/null +++ b/core/src/test/java/org/hibernate/subclassProxyInterface/Person.hbm.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + diff --git a/core/src/test/java/org/hibernate/subclassProxyInterface/Person.java b/core/src/test/java/org/hibernate/subclassProxyInterface/Person.java new file mode 100644 index 0000000000..38a0476141 --- /dev/null +++ b/core/src/test/java/org/hibernate/subclassProxyInterface/Person.java @@ -0,0 +1,55 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2010, Red Hat Inc. or third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by Red Hat Inc. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ +package org.hibernate.subclassProxyInterface; + +/** + * @author Steve Ebersole + */ +public class Person { + private Long id; + private String name; + + public Person() { + } + + public Person(String name) { + this.name = name; + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +} diff --git a/core/src/test/java/org/hibernate/subclassProxyInterface/SubclassProxyInterfaceTest.java b/core/src/test/java/org/hibernate/subclassProxyInterface/SubclassProxyInterfaceTest.java new file mode 100644 index 0000000000..fa0af592a6 --- /dev/null +++ b/core/src/test/java/org/hibernate/subclassProxyInterface/SubclassProxyInterfaceTest.java @@ -0,0 +1,44 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2010, Red Hat Inc. or third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by Red Hat Inc. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ +package org.hibernate.subclassProxyInterface; + +import junit.framework.TestCase; + +import org.hibernate.cfg.Configuration; +import org.hibernate.cfg.Environment; +import org.hibernate.dialect.H2Dialect; + +/** + * TODO : javadoc + * + * @author Steve Ebersole + */ +public class SubclassProxyInterfaceTest extends TestCase { + public void testSubclassProxyInterfaces() { + final Configuration cfg = new Configuration() + .setProperty( Environment.DIALECT, H2Dialect.class.getName() ); + cfg.addClass( Person.class ); + cfg.buildSessionFactory().close(); + } +}