[hibernate-commits] Hibernate SVN: r18662 - in core/trunk: annotations/src/test/java/org/hibernate/test/annotations/quote/resultsetmappings and 1 other directories.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Wed Jan 27 20:31:45 EST 2010


Author: steve.ebersole at jboss.com
Date: 2010-01-27 20:31:45 -0500 (Wed, 27 Jan 2010)
New Revision: 18662

Added:
   core/trunk/annotations/src/test/java/org/hibernate/test/annotations/quote/resultsetmappings/
   core/trunk/annotations/src/test/java/org/hibernate/test/annotations/quote/resultsetmappings/ExplicitSqlResultSetMappingTest.java
   core/trunk/annotations/src/test/java/org/hibernate/test/annotations/quote/resultsetmappings/MyEntity.java
Modified:
   core/trunk/core/src/main/java/org/hibernate/loader/custom/CustomLoader.java
Log:
HHH-4862 - column name quoting not properly handled for javax.persistence.ColumnResult


Added: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/quote/resultsetmappings/ExplicitSqlResultSetMappingTest.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/quote/resultsetmappings/ExplicitSqlResultSetMappingTest.java	                        (rev 0)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/quote/resultsetmappings/ExplicitSqlResultSetMappingTest.java	2010-01-28 01:31:45 UTC (rev 18662)
@@ -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();
+	}
+}

Added: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/quote/resultsetmappings/MyEntity.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/quote/resultsetmappings/MyEntity.java	                        (rev 0)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/quote/resultsetmappings/MyEntity.java	2010-01-28 01:31:45 UTC (rev 18662)
@@ -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
+ */
+ at SqlResultSetMapping(
+		name="explicitResultSetMapping",
+        columns={ @ColumnResult(name="`QuotEd_nAMe`") }
+)
+ at Entity
+ at 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;
+	}
+}

Modified: core/trunk/core/src/main/java/org/hibernate/loader/custom/CustomLoader.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/loader/custom/CustomLoader.java	2010-01-28 00:00:50 UTC (rev 18661)
+++ core/trunk/core/src/main/java/org/hibernate/loader/custom/CustomLoader.java	2010-01-28 01:31:45 UTC (rev 18662)
@@ -56,6 +56,7 @@
 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 @@
 				specifiedAliases.add( scalarRtn.getColumnAlias() );
 				resultColumnProcessors.add(
 						new ScalarResultColumnProcessor(
-								scalarRtn.getColumnAlias(),
+								StringHelper.unquote( scalarRtn.getColumnAlias() ),
 								scalarRtn.getType()
 						)
 				);



More information about the hibernate-commits mailing list