Author: stliu
Date: 2010-01-27 18:06:38 -0500 (Wed, 27 Jan 2010)
New Revision: 18658
Added:
core/trunk/testsuite/src/test/java/org/hibernate/test/criteria/AbstractFoo.java
core/trunk/testsuite/src/test/java/org/hibernate/test/criteria/Bar.java
core/trunk/testsuite/src/test/java/org/hibernate/test/criteria/Foo.hbm.xml
core/trunk/testsuite/src/test/java/org/hibernate/test/criteria/GreatFoo.java
Modified:
core/trunk/core/src/main/java/org/hibernate/loader/criteria/CriteriaQueryTranslator.java
core/trunk/testsuite/src/test/java/org/hibernate/test/criteria/CriteriaQueryTest.java
Log:
HHH-3828 Criteria: Restriction whith class does not work
Modified:
core/trunk/core/src/main/java/org/hibernate/loader/criteria/CriteriaQueryTranslator.java
===================================================================
---
core/trunk/core/src/main/java/org/hibernate/loader/criteria/CriteriaQueryTranslator.java 2010-01-27
19:16:39 UTC (rev 18657)
+++
core/trunk/core/src/main/java/org/hibernate/loader/criteria/CriteriaQueryTranslator.java 2010-01-27
23:06:38 UTC (rev 18658)
@@ -531,6 +531,14 @@
if ( q != null ) {
Type type = q.getDiscriminatorType();
String stringValue = q.getDiscriminatorSQLValue();
+ if (stringValue != null && stringValue.length() > 2
+ && stringValue.startsWith("'")
+ && stringValue.endsWith("'")) { // remove the single
+ // quotes
+ stringValue = stringValue.substring(1,
+ stringValue.length() - 1);
+ }
+
// Convert the string value into the proper type.
if ( type instanceof NullableType ) {
NullableType nullableType = ( NullableType ) type;
Added: core/trunk/testsuite/src/test/java/org/hibernate/test/criteria/AbstractFoo.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/criteria/AbstractFoo.java
(rev 0)
+++
core/trunk/testsuite/src/test/java/org/hibernate/test/criteria/AbstractFoo.java 2010-01-27
23:06:38 UTC (rev 18658)
@@ -0,0 +1,39 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2008, Red Hat Middleware LLC 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 Middleware LLC.
+ *
+ * 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.criteria;
+
+
+public abstract class AbstractFoo {
+
+ private Integer id;
+
+ public Integer getId() {
+ return id;
+ }
+
+ public void setId(Integer id) {
+ this.id = id;
+ }
+}
Added: core/trunk/testsuite/src/test/java/org/hibernate/test/criteria/Bar.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/criteria/Bar.java
(rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/criteria/Bar.java 2010-01-27
23:06:38 UTC (rev 18658)
@@ -0,0 +1,47 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2008, Red Hat Middleware LLC 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 Middleware LLC.
+ *
+ * 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.criteria;
+
+public class Bar {
+ private Integer id;
+
+ AbstractFoo myFoo;
+
+ public Integer getId() {
+ return id;
+ }
+
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ public AbstractFoo getMyFoo() {
+ return myFoo;
+ }
+
+ public void setMyFoo(AbstractFoo myFoo) {
+ this.myFoo = myFoo;
+ }
+}
Modified:
core/trunk/testsuite/src/test/java/org/hibernate/test/criteria/CriteriaQueryTest.java
===================================================================
---
core/trunk/testsuite/src/test/java/org/hibernate/test/criteria/CriteriaQueryTest.java 2010-01-27
19:16:39 UTC (rev 18657)
+++
core/trunk/testsuite/src/test/java/org/hibernate/test/criteria/CriteriaQueryTest.java 2010-01-27
23:06:38 UTC (rev 18658)
@@ -41,7 +41,7 @@
}
public String[] getMappings() {
- return new String[] { "criteria/Enrolment.hbm.xml",
"hql/Animal.hbm.xml" };
+ return new String[] {
"criteria/Enrolment.hbm.xml","criteria/Foo.hbm.xml",
"hql/Animal.hbm.xml" };
}
public void configure(Configuration cfg) {
@@ -707,6 +707,32 @@
s.close();
}
+ public void testClassProperty2() {
+ Session session = openSession();
+ Transaction t = session.beginTransaction();
+ GreatFoo foo = new GreatFoo();
+ Bar b = new Bar();
+ b.setMyFoo(foo);
+ foo.setId(1);
+ b.setId(1);
+ session.persist(b);
+ session.flush();
+ t.commit();
+ session=openSession();
+ t=session.beginTransaction();
+ // OK, one BAR in DB
+ assertEquals(1, session.createCriteria(Bar.class).list().size());
+ Criteria crit = session.createCriteria(Bar.class, "b").createAlias(
+ "myFoo", "m").add(
+ Property.forName("m.class").eq(GreatFoo.class));
+ assertEquals(1, crit.list().size());
+ crit = session.createCriteria(Bar.class, "b").createAlias("myFoo",
"m")
+ .add(Restrictions.eq("m.class", GreatFoo.class));
+ assertEquals(1, crit.list().size());
+ t.commit();
+ session.close();
+ }
+
public void testProjectedId() {
Session s = openSession();
Transaction t = s.beginTransaction();
Added: core/trunk/testsuite/src/test/java/org/hibernate/test/criteria/Foo.hbm.xml
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/criteria/Foo.hbm.xml
(rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/criteria/Foo.hbm.xml 2010-01-27
23:06:38 UTC (rev 18658)
@@ -0,0 +1,22 @@
+<?xml version="1.0"?>
+<!DOCTYPE hibernate-mapping PUBLIC
+ "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
+ "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
+
+<hibernate-mapping package="org.hibernate.test.criteria">
+
+ <class name="AbstractFoo">
+ <id name="id">
+ </id>
+ <discriminator type="string" column="subtype" />
+ <subclass name="GreatFoo" discriminator-value="KAPUT">
+ </subclass>
+ </class>
+
+ <class name="Bar">
+ <id name="id">
+ </id>
+
+ <one-to-one name="myFoo" cascade="all" />
+ </class>
+</hibernate-mapping>
Property changes on:
core/trunk/testsuite/src/test/java/org/hibernate/test/criteria/Foo.hbm.xml
___________________________________________________________________
Name: svn:executable
+ *
Added: core/trunk/testsuite/src/test/java/org/hibernate/test/criteria/GreatFoo.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/criteria/GreatFoo.java
(rev 0)
+++
core/trunk/testsuite/src/test/java/org/hibernate/test/criteria/GreatFoo.java 2010-01-27
23:06:38 UTC (rev 18658)
@@ -0,0 +1,29 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2008, Red Hat Middleware LLC 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 Middleware LLC.
+ *
+ * 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.criteria;
+
+public class GreatFoo extends AbstractFoo {
+
+}