[hibernate-commits] Hibernate SVN: r18316 - in entitymanager/branches/v3_4_0_GA_CP/src: test/java/org/hibernate/ejb/test and 1 other directories.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Tue Dec 22 09:43:20 EST 2009


Author: stliu
Date: 2009-12-22 09:43:19 -0500 (Tue, 22 Dec 2009)
New Revision: 18316

Added:
   entitymanager/branches/v3_4_0_GA_CP/src/test/java/org/hibernate/ejb/test/query/
   entitymanager/branches/v3_4_0_GA_CP/src/test/java/org/hibernate/ejb/test/query/NamedNativeQueryTest.java
   entitymanager/branches/v3_4_0_GA_CP/src/test/java/org/hibernate/ejb/test/query/SpaceShip.java
Modified:
   entitymanager/branches/v3_4_0_GA_CP/src/main/java/org/hibernate/ejb/QueryImpl.java
Log:
JBPAPP-2858 HHH-4463 Native queries should not be automatically paginated in getSingleResult() as it fails for some DB and or queries

Modified: entitymanager/branches/v3_4_0_GA_CP/src/main/java/org/hibernate/ejb/QueryImpl.java
===================================================================
--- entitymanager/branches/v3_4_0_GA_CP/src/main/java/org/hibernate/ejb/QueryImpl.java	2009-12-22 13:27:13 UTC (rev 18315)
+++ entitymanager/branches/v3_4_0_GA_CP/src/main/java/org/hibernate/ejb/QueryImpl.java	2009-12-22 14:43:19 UTC (rev 18316)
@@ -40,6 +40,7 @@
 import org.hibernate.FlushMode;
 import org.hibernate.HibernateException;
 import org.hibernate.QueryParameterException;
+import org.hibernate.SQLQuery;
 import org.hibernate.TypeMismatchException;
 import org.hibernate.impl.AbstractQueryImpl;
 import org.hibernate.ejb.util.ConfigurationHelper;
@@ -106,7 +107,8 @@
 			/* Avoid OOME if the list() is huge (user faulty query) by limiting the query to 2 elements max */
 			//FIXME: get rid of this impl binding (HHH-3432)
 			if ( query instanceof AbstractQueryImpl ) {
-				if (maxResults != 1) query.setMaxResults( 2 ); //avoid OOME if the list is huge
+				if (maxResults != 1 && ! ( SQLQuery.class.isAssignableFrom( query.getClass() ) ) ) 
+					query.setMaxResults( 2 ); //avoid OOME if the list is huge
 				result = query.list();
 				if ( maxResults != -1 ) {
 					query.setMaxResults( maxResults ); //put back the original value

Added: entitymanager/branches/v3_4_0_GA_CP/src/test/java/org/hibernate/ejb/test/query/NamedNativeQueryTest.java
===================================================================
--- entitymanager/branches/v3_4_0_GA_CP/src/test/java/org/hibernate/ejb/test/query/NamedNativeQueryTest.java	                        (rev 0)
+++ entitymanager/branches/v3_4_0_GA_CP/src/test/java/org/hibernate/ejb/test/query/NamedNativeQueryTest.java	2009-12-22 14:43:19 UTC (rev 18316)
@@ -0,0 +1,63 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009 by Red Hat Inc and/or its affiliates or by
+ * third-party contributors as indicated by either @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.ejb.test.query;
+
+import javax.persistence.EntityManager;
+import javax.persistence.Query;
+
+import org.hibernate.ejb.test.TestCase;
+
+/**
+ * https://jira.jboss.org/jira/browse/JBPAPP-2858
+ * Native queries should not be automatically paginated in getSingleResult() as it fails for some DB and or queries
+ * 
+ * @author Strong Liu
+ */
+public class NamedNativeQueryTest extends TestCase {
+
+	@Override
+	public Class[] getAnnotatedClasses() {
+		return new Class[] { SpaceShip.class };
+	}
+
+	public void testNativeQuerys() {
+		EntityManager em = getOrCreateEntityManager();
+		em.getTransaction().begin();
+
+		SpaceShip ship = new SpaceShip();
+		ship.setModel("X-Wing");
+		ship.setName("YuBlue");
+		em.persist(ship);
+
+		em.getTransaction().commit();
+		em.clear();
+		em.getTransaction().begin();
+		Query q = em.createNamedQuery("implicitSample");
+
+		Object obj = q.getSingleResult();
+		assertNotNull(obj);
+		em.getTransaction().commit();
+		em.close();
+	}
+}

Added: entitymanager/branches/v3_4_0_GA_CP/src/test/java/org/hibernate/ejb/test/query/SpaceShip.java
===================================================================
--- entitymanager/branches/v3_4_0_GA_CP/src/test/java/org/hibernate/ejb/test/query/SpaceShip.java	                        (rev 0)
+++ entitymanager/branches/v3_4_0_GA_CP/src/test/java/org/hibernate/ejb/test/query/SpaceShip.java	2009-12-22 14:43:19 UTC (rev 18316)
@@ -0,0 +1,47 @@
+//$Id: SpaceShip.java 14736 2008-06-04 14:23:42Z hardy.ferentschik $
+package org.hibernate.ejb.test.query;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.NamedNativeQueries;
+import javax.persistence.NamedNativeQuery;
+
+/**
+ * @author Emmanuel Bernard
+ */
+ at Entity
+ at NamedNativeQueries( { @NamedNativeQuery(name = "implicitSample", query = "select * from SpaceShip s where s.name='YuBlue' ", 
+		resultClass = org.hibernate.ejb.test.query.SpaceShip.class) })
+public class SpaceShip {
+	private String name;
+	private String model;
+	private Long id;
+
+	@Id
+	@GeneratedValue
+	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;
+	}
+
+	public String getModel() {
+		return model;
+	}
+
+	public void setModel( String model ) {
+		this.model = model;
+	}
+
+}



More information about the hibernate-commits mailing list