diff --git a/annotations/src/test/java/org/hibernate/test/annotations/quote/resultsetmappings/ExplicitSqlResultSetMappingTest.java b/annotations/src/test/java/org/hibernate/test/annotations/quote/resultsetmappings/ExplicitSqlResultSetMappingTest.java new file mode 100644 index 0000000000..85fcdbe5c1 --- /dev/null +++ b/annotations/src/test/java/org/hibernate/test/annotations/quote/resultsetmappings/ExplicitSqlResultSetMappingTest.java @@ -0,0 +1,60 @@ +/* + * 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.test.annotations.quote.resultsetmappings; + +import org.hibernate.Session; +import org.hibernate.test.annotations.TestCase; + +/** + * TODO : javadoc + * + * @author Steve Ebersole + */ +public class ExplicitSqlResultSetMappingTest extends TestCase { + private String queryString = "select t.\"NAME\" as \"QuotEd_nAMe\" from \"MY_ENTITY_TABLE_NAME\" t"; + + @Override + protected Class[] getAnnotatedClasses() { + return new Class[] { MyEntity.class }; + } + + public void testCompleteAutoDiscovery() { + Session s = openSession(); + s.beginTransaction(); + s.createSQLQuery( queryString ) + .list(); + s.getTransaction().commit(); + s.close(); + } + + public void testPartialAutoDiscovery() { + Session s = openSession(); + s.beginTransaction(); + s.createSQLQuery( queryString ) + .setResultSetMapping( "explicitResultSetMapping" ) + .list(); + s.getTransaction().commit(); + s.close(); + } +} diff --git a/annotations/src/test/java/org/hibernate/test/annotations/quote/resultsetmappings/MyEntity.java b/annotations/src/test/java/org/hibernate/test/annotations/quote/resultsetmappings/MyEntity.java new file mode 100644 index 0000000000..6925fb19bf --- /dev/null +++ b/annotations/src/test/java/org/hibernate/test/annotations/quote/resultsetmappings/MyEntity.java @@ -0,0 +1,67 @@ +/* + * 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.test.annotations.quote.resultsetmappings; + +import javax.persistence.Column; +import javax.persistence.ColumnResult; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.SqlResultSetMapping; +import javax.persistence.Table; + +/** + * TODO : javadoc + * + * @author Steve Ebersole + */ +@SqlResultSetMapping( + name="explicitResultSetMapping", + columns={ @ColumnResult(name="`QuotEd_nAMe`") } +) +@Entity +@Table( name = "MY_ENTITY_TABLE_NAME" ) +public class MyEntity { + private Long id; + private String name; + + @Id + @GeneratedValue + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + @Column( name = "NAME" ) + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +} diff --git a/core/src/main/java/org/hibernate/loader/custom/CustomLoader.java b/core/src/main/java/org/hibernate/loader/custom/CustomLoader.java index 26cb0f666e..90ef328c57 100755 --- a/core/src/main/java/org/hibernate/loader/custom/CustomLoader.java +++ b/core/src/main/java/org/hibernate/loader/custom/CustomLoader.java @@ -56,6 +56,7 @@ import org.hibernate.type.TypeFactory; import org.hibernate.type.EntityType; import org.hibernate.type.CollectionType; import org.hibernate.util.ArrayHelper; +import org.hibernate.util.StringHelper; /** * Extension point for loaders which use a SQL result set with "unexpected" column aliases. @@ -125,7 +126,7 @@ public class CustomLoader extends Loader { specifiedAliases.add( scalarRtn.getColumnAlias() ); resultColumnProcessors.add( new ScalarResultColumnProcessor( - scalarRtn.getColumnAlias(), + StringHelper.unquote( scalarRtn.getColumnAlias() ), scalarRtn.getType() ) );