Hibernate SVN: r16540 - in beanvalidation/trunk/validation-api/src: test/resources and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2009-05-12 05:07:18 -0400 (Tue, 12 May 2009)
New Revision: 16540
Added:
beanvalidation/trunk/validation-api/src/test/resources/validation-configuration-1.0.xsd
beanvalidation/trunk/validation-api/src/test/resources/validation-mapping-1.0.xsd
Removed:
beanvalidation/trunk/validation-api/src/main/resources/validation-configuration-1.0.xsd
beanvalidation/trunk/validation-api/src/main/resources/validation-mapping-1.0.xsd
Log:
moved xsd files so that they are no longer part of the jar file
Deleted: beanvalidation/trunk/validation-api/src/main/resources/validation-configuration-1.0.xsd
===================================================================
--- beanvalidation/trunk/validation-api/src/main/resources/validation-configuration-1.0.xsd 2009-05-11 21:21:29 UTC (rev 16539)
+++ beanvalidation/trunk/validation-api/src/main/resources/validation-configuration-1.0.xsd 2009-05-12 09:07:18 UTC (rev 16540)
@@ -1,25 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<xs:schema attributeFormDefault="unqualified"
- elementFormDefault="qualified"
- targetNamespace="http://jboss.org/xml/ns/javax/validation/configuration"
- xmlns:xs="http://www.w3.org/2001/XMLSchema"
- version="1.0">
- <xs:element name="validation-config" type="validation-configType"/>
- <xs:complexType name="validation-configType">
- <xs:sequence>
- <xs:element type="xs:string" name="default-provider" minOccurs="0"/>
- <xs:element type="xs:string" name="message-interpolator" minOccurs="0"/>
- <xs:element type="xs:string" name="traversable-resolver" minOccurs="0"/>
- <xs:element type="xs:string" name="constraint-validator-factory" minOccurs="0"/>
- <xs:element type="xs:string" name="constraint-mapping" maxOccurs="unbounded" minOccurs="0"/>
- <xs:element type="propertyType" name="property" maxOccurs="unbounded" minOccurs="0"/>
- </xs:sequence>
- </xs:complexType>
- <xs:complexType name="propertyType">
- <xs:simpleContent>
- <xs:extension base="xs:string">
- <xs:attribute name="name" use="required" type="xs:string"/>
- </xs:extension>
- </xs:simpleContent>
- </xs:complexType>
-</xs:schema>
\ No newline at end of file
Deleted: beanvalidation/trunk/validation-api/src/main/resources/validation-mapping-1.0.xsd
===================================================================
--- beanvalidation/trunk/validation-api/src/main/resources/validation-mapping-1.0.xsd 2009-05-11 21:21:29 UTC (rev 16539)
+++ beanvalidation/trunk/validation-api/src/main/resources/validation-mapping-1.0.xsd 2009-05-12 09:07:18 UTC (rev 16540)
@@ -1,141 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<xs:schema attributeFormDefault="unqualified"
- elementFormDefault="qualified"
- targetNamespace="http://jboss.org/xml/ns/javax/validation/mapping"
- xmlns:xs="http://www.w3.org/2001/XMLSchema"
- version="1.0">
- <xs:element name="constraint-mappings"
- type="map:constraint-mappingsType"
- xmlns:map="http://jboss.org/xml/ns/javax/validation/mapping"/>
-
- <xs:complexType name="groupsType">
- <xs:sequence>
- <xs:element type="xs:string" name="value" maxOccurs="unbounded" minOccurs="0"/>
- </xs:sequence>
- </xs:complexType>
- <xs:complexType name="groupSequenceType">
- <xs:sequence>
- <xs:element type="xs:string" name="value" maxOccurs="unbounded" minOccurs="0"/>
- </xs:sequence>
- </xs:complexType>
- <xs:complexType name="constraint-mappingsType">
- <xs:sequence>
- <xs:element type="xs:string" name="default-package" minOccurs="0"/>
- <xs:element type="map:beanType"
- name="bean"
- maxOccurs="unbounded"
- minOccurs="0"
- xmlns:map="http://jboss.org/xml/ns/javax/validation/mapping"/>
- <xs:element type="map:constraint-definitionType"
- name="constraint-definition"
- maxOccurs="unbounded"
- minOccurs="0"
- xmlns:map="http://jboss.org/xml/ns/javax/validation/mapping"/>
- </xs:sequence>
- </xs:complexType>
- <xs:complexType name="validated-byType">
- <xs:sequence>
- <xs:element type="xs:string" name="value" maxOccurs="unbounded" minOccurs="0"/>
- </xs:sequence>
- <xs:attribute type="xs:boolean" name="include-existing-validators" use="optional"/>
- </xs:complexType>
- <xs:complexType name="constraintType">
- <xs:sequence>
- <xs:element type="xs:string" name="message" minOccurs="0"/>
- <xs:element type="map:groupsType"
- name="groups"
- minOccurs="0"
- xmlns:map="http://jboss.org/xml/ns/javax/validation/mapping"/>
- <xs:element type="map:elementType"
- name="element"
- maxOccurs="unbounded"
- minOccurs="0"
- xmlns:map="http://jboss.org/xml/ns/javax/validation/mapping"/>
- </xs:sequence>
- <xs:attribute type="xs:string" name="annotation" use="required"/>
- </xs:complexType>
- <xs:complexType name="elementType" mixed="true">
- <xs:sequence>
- <xs:element type="xs:string" name="value" maxOccurs="unbounded" minOccurs="0"/>
- <xs:element type="map:annotationType"
- name="annotation"
- maxOccurs="unbounded"
- minOccurs="0"
- xmlns:map="http://jboss.org/xml/ns/javax/validation/mapping"/>
- </xs:sequence>
- <xs:attribute type="xs:string" name="name" use="required"/>
- </xs:complexType>
- <xs:complexType name="classType">
- <xs:sequence>
- <xs:element type="groupSequenceType" name="group-sequence" minOccurs="0"/>
- <xs:element type="map:constraintType"
- name="constraint"
- maxOccurs="unbounded"
- minOccurs="0"
- xmlns:map="http://jboss.org/xml/ns/javax/validation/mapping"/>
- </xs:sequence>
- <xs:attribute type="xs:boolean" name="ignore-annotations" use="optional"/>
- </xs:complexType>
- <xs:complexType name="beanType">
- <xs:sequence>
- <xs:element type="map:classType"
- name="class"
- minOccurs="0"
- xmlns:map="http://jboss.org/xml/ns/javax/validation/mapping">
- </xs:element>
- <xs:element type="map:fieldType"
- name="field"
- minOccurs="0"
- maxOccurs="unbounded"
- xmlns:map="http://jboss.org/xml/ns/javax/validation/mapping"/>
- <xs:element type="map:getterType"
- name="getter"
- minOccurs="0"
- maxOccurs="unbounded"
- xmlns:map="http://jboss.org/xml/ns/javax/validation/mapping"/>
- </xs:sequence>
- <xs:attribute type="xs:string" name="class" use="required"/>
- <xs:attribute type="xs:boolean" name="ignore-annotations" use="optional"/>
- </xs:complexType>
- <xs:complexType name="annotationType">
- <xs:sequence>
- <xs:element type="map:elementType"
- name="element"
- maxOccurs="unbounded"
- minOccurs="0"
- xmlns:map="http://jboss.org/xml/ns/javax/validation/mapping"/>
- </xs:sequence>
- </xs:complexType>
- <xs:complexType name="getterType">
- <xs:sequence>
- <xs:element type="xs:string" name="valid" minOccurs="0" fixed=""/>
- <xs:element type="map:constraintType"
- name="constraint"
- minOccurs="0"
- maxOccurs="unbounded"
- xmlns:map="http://jboss.org/xml/ns/javax/validation/mapping"/>
- </xs:sequence>
- <xs:attribute type="xs:string" name="name" use="required"/>
- <xs:attribute type="xs:boolean" name="ignore-annotations" use="optional"/>
- </xs:complexType>
- <xs:complexType name="constraint-definitionType">
- <xs:sequence>
- <xs:element type="map:validated-byType"
- name="validated-by"
- xmlns:map="http://jboss.org/xml/ns/javax/validation/mapping"/>
- </xs:sequence>
- <xs:attribute type="xs:string" name="annotation" use="required"/>
- </xs:complexType>
- <xs:complexType name="fieldType">
- <xs:sequence>
- <xs:element type="xs:string" name="valid" minOccurs="0" fixed=""/>
- <xs:element type="map:constraintType"
- name="constraint"
- minOccurs="0"
- maxOccurs="unbounded"
- xmlns:map="http://jboss.org/xml/ns/javax/validation/mapping"/>
- </xs:sequence>
- <xs:attribute type="xs:string" name="name" use="required"/>
- <xs:attribute type="xs:boolean" name="ignore-annotations" use="optional"/>
- </xs:complexType>
-</xs:schema>
\ No newline at end of file
Copied: beanvalidation/trunk/validation-api/src/test/resources/validation-configuration-1.0.xsd (from rev 16400, beanvalidation/trunk/validation-api/src/main/resources/validation-configuration-1.0.xsd)
===================================================================
--- beanvalidation/trunk/validation-api/src/test/resources/validation-configuration-1.0.xsd (rev 0)
+++ beanvalidation/trunk/validation-api/src/test/resources/validation-configuration-1.0.xsd 2009-05-12 09:07:18 UTC (rev 16540)
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xs:schema attributeFormDefault="unqualified"
+ elementFormDefault="qualified"
+ targetNamespace="http://jboss.org/xml/ns/javax/validation/configuration"
+ xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ version="1.0">
+ <xs:element name="validation-config" type="validation-configType"/>
+ <xs:complexType name="validation-configType">
+ <xs:sequence>
+ <xs:element type="xs:string" name="default-provider" minOccurs="0"/>
+ <xs:element type="xs:string" name="message-interpolator" minOccurs="0"/>
+ <xs:element type="xs:string" name="traversable-resolver" minOccurs="0"/>
+ <xs:element type="xs:string" name="constraint-validator-factory" minOccurs="0"/>
+ <xs:element type="xs:string" name="constraint-mapping" maxOccurs="unbounded" minOccurs="0"/>
+ <xs:element type="propertyType" name="property" maxOccurs="unbounded" minOccurs="0"/>
+ </xs:sequence>
+ </xs:complexType>
+ <xs:complexType name="propertyType">
+ <xs:simpleContent>
+ <xs:extension base="xs:string">
+ <xs:attribute name="name" use="required" type="xs:string"/>
+ </xs:extension>
+ </xs:simpleContent>
+ </xs:complexType>
+</xs:schema>
\ No newline at end of file
Copied: beanvalidation/trunk/validation-api/src/test/resources/validation-mapping-1.0.xsd (from rev 16400, beanvalidation/trunk/validation-api/src/main/resources/validation-mapping-1.0.xsd)
===================================================================
--- beanvalidation/trunk/validation-api/src/test/resources/validation-mapping-1.0.xsd (rev 0)
+++ beanvalidation/trunk/validation-api/src/test/resources/validation-mapping-1.0.xsd 2009-05-12 09:07:18 UTC (rev 16540)
@@ -0,0 +1,141 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xs:schema attributeFormDefault="unqualified"
+ elementFormDefault="qualified"
+ targetNamespace="http://jboss.org/xml/ns/javax/validation/mapping"
+ xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ version="1.0">
+ <xs:element name="constraint-mappings"
+ type="map:constraint-mappingsType"
+ xmlns:map="http://jboss.org/xml/ns/javax/validation/mapping"/>
+
+ <xs:complexType name="groupsType">
+ <xs:sequence>
+ <xs:element type="xs:string" name="value" maxOccurs="unbounded" minOccurs="0"/>
+ </xs:sequence>
+ </xs:complexType>
+ <xs:complexType name="groupSequenceType">
+ <xs:sequence>
+ <xs:element type="xs:string" name="value" maxOccurs="unbounded" minOccurs="0"/>
+ </xs:sequence>
+ </xs:complexType>
+ <xs:complexType name="constraint-mappingsType">
+ <xs:sequence>
+ <xs:element type="xs:string" name="default-package" minOccurs="0"/>
+ <xs:element type="map:beanType"
+ name="bean"
+ maxOccurs="unbounded"
+ minOccurs="0"
+ xmlns:map="http://jboss.org/xml/ns/javax/validation/mapping"/>
+ <xs:element type="map:constraint-definitionType"
+ name="constraint-definition"
+ maxOccurs="unbounded"
+ minOccurs="0"
+ xmlns:map="http://jboss.org/xml/ns/javax/validation/mapping"/>
+ </xs:sequence>
+ </xs:complexType>
+ <xs:complexType name="validated-byType">
+ <xs:sequence>
+ <xs:element type="xs:string" name="value" maxOccurs="unbounded" minOccurs="0"/>
+ </xs:sequence>
+ <xs:attribute type="xs:boolean" name="include-existing-validators" use="optional"/>
+ </xs:complexType>
+ <xs:complexType name="constraintType">
+ <xs:sequence>
+ <xs:element type="xs:string" name="message" minOccurs="0"/>
+ <xs:element type="map:groupsType"
+ name="groups"
+ minOccurs="0"
+ xmlns:map="http://jboss.org/xml/ns/javax/validation/mapping"/>
+ <xs:element type="map:elementType"
+ name="element"
+ maxOccurs="unbounded"
+ minOccurs="0"
+ xmlns:map="http://jboss.org/xml/ns/javax/validation/mapping"/>
+ </xs:sequence>
+ <xs:attribute type="xs:string" name="annotation" use="required"/>
+ </xs:complexType>
+ <xs:complexType name="elementType" mixed="true">
+ <xs:sequence>
+ <xs:element type="xs:string" name="value" maxOccurs="unbounded" minOccurs="0"/>
+ <xs:element type="map:annotationType"
+ name="annotation"
+ maxOccurs="unbounded"
+ minOccurs="0"
+ xmlns:map="http://jboss.org/xml/ns/javax/validation/mapping"/>
+ </xs:sequence>
+ <xs:attribute type="xs:string" name="name" use="required"/>
+ </xs:complexType>
+ <xs:complexType name="classType">
+ <xs:sequence>
+ <xs:element type="groupSequenceType" name="group-sequence" minOccurs="0"/>
+ <xs:element type="map:constraintType"
+ name="constraint"
+ maxOccurs="unbounded"
+ minOccurs="0"
+ xmlns:map="http://jboss.org/xml/ns/javax/validation/mapping"/>
+ </xs:sequence>
+ <xs:attribute type="xs:boolean" name="ignore-annotations" use="optional"/>
+ </xs:complexType>
+ <xs:complexType name="beanType">
+ <xs:sequence>
+ <xs:element type="map:classType"
+ name="class"
+ minOccurs="0"
+ xmlns:map="http://jboss.org/xml/ns/javax/validation/mapping">
+ </xs:element>
+ <xs:element type="map:fieldType"
+ name="field"
+ minOccurs="0"
+ maxOccurs="unbounded"
+ xmlns:map="http://jboss.org/xml/ns/javax/validation/mapping"/>
+ <xs:element type="map:getterType"
+ name="getter"
+ minOccurs="0"
+ maxOccurs="unbounded"
+ xmlns:map="http://jboss.org/xml/ns/javax/validation/mapping"/>
+ </xs:sequence>
+ <xs:attribute type="xs:string" name="class" use="required"/>
+ <xs:attribute type="xs:boolean" name="ignore-annotations" use="optional"/>
+ </xs:complexType>
+ <xs:complexType name="annotationType">
+ <xs:sequence>
+ <xs:element type="map:elementType"
+ name="element"
+ maxOccurs="unbounded"
+ minOccurs="0"
+ xmlns:map="http://jboss.org/xml/ns/javax/validation/mapping"/>
+ </xs:sequence>
+ </xs:complexType>
+ <xs:complexType name="getterType">
+ <xs:sequence>
+ <xs:element type="xs:string" name="valid" minOccurs="0" fixed=""/>
+ <xs:element type="map:constraintType"
+ name="constraint"
+ minOccurs="0"
+ maxOccurs="unbounded"
+ xmlns:map="http://jboss.org/xml/ns/javax/validation/mapping"/>
+ </xs:sequence>
+ <xs:attribute type="xs:string" name="name" use="required"/>
+ <xs:attribute type="xs:boolean" name="ignore-annotations" use="optional"/>
+ </xs:complexType>
+ <xs:complexType name="constraint-definitionType">
+ <xs:sequence>
+ <xs:element type="map:validated-byType"
+ name="validated-by"
+ xmlns:map="http://jboss.org/xml/ns/javax/validation/mapping"/>
+ </xs:sequence>
+ <xs:attribute type="xs:string" name="annotation" use="required"/>
+ </xs:complexType>
+ <xs:complexType name="fieldType">
+ <xs:sequence>
+ <xs:element type="xs:string" name="valid" minOccurs="0" fixed=""/>
+ <xs:element type="map:constraintType"
+ name="constraint"
+ minOccurs="0"
+ maxOccurs="unbounded"
+ xmlns:map="http://jboss.org/xml/ns/javax/validation/mapping"/>
+ </xs:sequence>
+ <xs:attribute type="xs:string" name="name" use="required"/>
+ <xs:attribute type="xs:boolean" name="ignore-annotations" use="optional"/>
+ </xs:complexType>
+</xs:schema>
\ No newline at end of file
15 years, 6 months
Hibernate SVN: r16539 - in core/branches/Branch_3_3: testsuite/src/test/java/org/hibernate/test/sql/hand and 1 other directories.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2009-05-11 17:21:29 -0400 (Mon, 11 May 2009)
New Revision: 16539
Added:
core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/sql/hand/Group.java
Modified:
core/branches/Branch_3_3/core/src/main/java/org/hibernate/loader/custom/sql/SQLQueryReturnProcessor.java
core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/sql/hand/Person.java
core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/sql/hand/query/NativeSQLQueries.hbm.xml
core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/sql/hand/query/NativeSQLQueriesTest.java
Log:
HHH-2745 - NullPointerException when eager fetching joined many-to-many with native SQL query
Modified: core/branches/Branch_3_3/core/src/main/java/org/hibernate/loader/custom/sql/SQLQueryReturnProcessor.java
===================================================================
--- core/branches/Branch_3_3/core/src/main/java/org/hibernate/loader/custom/sql/SQLQueryReturnProcessor.java 2009-05-11 21:18:53 UTC (rev 16538)
+++ core/branches/Branch_3_3/core/src/main/java/org/hibernate/loader/custom/sql/SQLQueryReturnProcessor.java 2009-05-11 21:21:29 UTC (rev 16539)
@@ -397,7 +397,7 @@
alias2CollectionSuffix.put( alias, suffix );
collectionPropertyResultMaps.put( alias, propertyResults );
- if ( collectionPersister.isOneToMany() ) {
+ if ( collectionPersister.isOneToMany() || collectionPersister.isManyToMany() ) {
SQLLoadable persister = ( SQLLoadable ) collectionPersister.getElementPersister();
addPersister( alias, filter( propertyResults ), persister );
}
Added: core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/sql/hand/Group.java
===================================================================
--- core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/sql/hand/Group.java (rev 0)
+++ core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/sql/hand/Group.java 2009-05-11 21:21:29 UTC (rev 16539)
@@ -0,0 +1,67 @@
+/*
+ * Copyright (c) 2009, 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.sql.hand;
+
+import java.util.List;
+import java.util.ArrayList;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+public class Group {
+ private Long id;
+ private List persons = new ArrayList();
+ private String name;
+
+ public Group() {
+ }
+
+ public Group(String name) {
+ this.name = name;
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public List getPersons() {
+ return persons;
+ }
+
+ public void setPersons(List persons) {
+ this.persons = persons;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+}
Modified: core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/sql/hand/Person.java
===================================================================
--- core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/sql/hand/Person.java 2009-05-11 21:18:53 UTC (rev 16538)
+++ core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/sql/hand/Person.java 2009-05-11 21:21:29 UTC (rev 16539)
@@ -1,37 +1,41 @@
-//$Id: Person.java 11486 2007-05-08 21:57:24Z steve.ebersole(a)jboss.com $
+//$Id: Person.java 4316 2004-08-14 13:12:03Z oneovthafew $
package org.hibernate.test.sql.hand;
/**
* @author Gavin King
*/
public class Person {
- private long id;
+ private Long id;
private String name;
public Person(String name) {
this.name = name;
}
-
- public Person() {}
-
-/**
+
+ public Person() {
+ }
+
+ /**
* @return Returns the id.
*/
- public long getId() {
+ public Long getId() {
return id;
}
+
/**
* @param id The id to set.
*/
- public void setId(long id) {
+ public void setId(Long id) {
this.id = id;
}
+
/**
* @return Returns the name.
*/
public String getName() {
return name;
}
+
/**
* @param name The name to set.
*/
Modified: core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/sql/hand/query/NativeSQLQueries.hbm.xml
===================================================================
--- core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/sql/hand/query/NativeSQLQueries.hbm.xml 2009-05-11 21:18:53 UTC (rev 16538)
+++ core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/sql/hand/query/NativeSQLQueries.hbm.xml 2009-05-11 21:21:29 UTC (rev 16539)
@@ -28,8 +28,19 @@
<generator class="increment"/>
</id>
<property name="name" column="NAME" not-null="true"/>
-
</class>
+
+ <class name="Group" table="GROUPP">
+ <id name="id" unsaved-value="0" column="ID">
+ <generator class="increment"/>
+ </id>
+ <property name="name" column="NAME" not-null="true"/>
+ <list name="persons" table="GROUP_PERSON" cascade="none" inverse="false" lazy="true">
+ <key column="GROUP_ID" />
+ <list-index column="POS" />
+ <many-to-many class="Person" column="PERSON_ID" />
+ </list>
+ </class>
<class name="Employment" table="EMPLOYMENT">
<id name="employmentId" unsaved-value="0" column="EMPID">
@@ -259,4 +270,32 @@
LEFT OUTER JOIN EMPLOYMENT emp ON org.ORGID = emp.EMPLOYER
</sql-query>
+ <sql-query name="manyToManyFetch">
+ <![CDATA[
+ SELECT groupp.ID as group_id,
+ groupp.NAME as group_name,
+ group_person.PERSON_ID as group_person_personId,
+ group_person.GROUP_ID as group_person_groupId,
+ group_person.POS as group_person_pos,
+ person.PERID as person_id,
+ person.NAME as person_name
+ FROM GROUPP groupp,
+ GROUP_PERSON group_person,
+ PERSON person
+ WHERE groupp.ID = group_person.GROUP_ID
+ and person.PERID = group_person.PERSON_ID
+ ]]>
+ <return alias="groupp" class="Group">
+ <return-property name="id" column="group_id" />
+ <return-property name="name" column="group_name" />
+ </return>
+ <return-join alias="group_person" property="groupp.persons">
+ <return-property name="key" column="group_person_groupId" />
+ <return-property name="index" column="group_person_pos" />
+ <return-property name="element" column="person_id" />
+ <return-property name="element.id" column="person_id" />
+ <return-property name="element.name" column="person_name" />
+ </return-join>
+ </sql-query>
+
</hibernate-mapping>
\ No newline at end of file
Modified: core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/sql/hand/query/NativeSQLQueriesTest.java
===================================================================
--- core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/sql/hand/query/NativeSQLQueriesTest.java 2009-05-11 21:18:53 UTC (rev 16538)
+++ core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/sql/hand/query/NativeSQLQueriesTest.java 2009-05-11 21:21:29 UTC (rev 16539)
@@ -23,6 +23,7 @@
import org.hibernate.test.sql.hand.Dimension;
import org.hibernate.test.sql.hand.SpaceShip;
import org.hibernate.test.sql.hand.Speech;
+import org.hibernate.test.sql.hand.Group;
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment;
import org.hibernate.junit.functional.FunctionalTestCase;
@@ -609,6 +610,63 @@
}
}
+ public void testAddJoinForManyToMany() {
+ Session s = openSession();
+ Transaction t = s.beginTransaction();
+ Person gavin = new Person( "Gavin" );
+ Person max = new Person( "Max" );
+ Person pete = new Person( "Pete" );
+
+ Group hibernate = new Group( "Hibernate" );
+ Group seam = new Group( "Seam" );
+
+ s.persist( gavin );
+ s.persist( max );
+ s.persist( pete );
+ s.persist( seam );
+ s.persist( hibernate );
+
+ hibernate.getPersons().add( gavin );
+ hibernate.getPersons().add( max );
+ seam.getPersons().add( gavin );
+ seam.getPersons().add( pete );
+
+ s.flush();
+ s.clear();
+
+ // todo : see http://opensource.atlassian.com/projects/hibernate/browse/HHH-3908
+// String sqlStr = "SELECT {groupp.*} , {gp.*} " +
+// "FROM GROUPP groupp, GROUP_PERSON gp, PERSON person WHERE groupp.ID = gp.GROUP_ID and person.PERID = gp.PERSON_ID";
+//
+// List l = s.createSQLQuery( sqlStr )
+// .addEntity("groupp", Group.class)
+// .addJoin("gp","groupp.persons")
+// .list();
+ List l = s.getNamedQuery( "manyToManyFetch" ).list();
+ //assertEquals( 2, l.size() );
+
+ t.commit();
+ s.close();
+
+ s = openSession();
+ t = s.beginTransaction();
+
+ seam.getPersons().remove( gavin );
+ seam.getPersons().remove( pete );
+
+ hibernate.getPersons().remove( gavin );
+ hibernate.getPersons().remove( max );
+
+ s.delete( seam );
+ s.delete( hibernate );
+ s.delete( gavin );
+ s.delete( max );
+ s.delete( pete );
+
+ t.commit();
+ s.close();
+ }
+
private static class UpperCasedAliasToEntityMapResultTransformer extends BasicTransformerAdapter implements Serializable {
public Object transformTuple(Object[] tuple, String[] aliases) {
Map result = new HashMap( tuple.length );
15 years, 6 months
Hibernate SVN: r16538 - core/branches/Branch_3_2.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2009-05-11 17:18:53 -0400 (Mon, 11 May 2009)
New Revision: 16538
Modified:
core/branches/Branch_3_2/
Log:
updated svn:ignore properties
Property changes on: core/branches/Branch_3_2
___________________________________________________________________
Name: svn:ignore
- build
target
local
*.ipr
*.iws
*.iml
.classpath
.project
.nbattrs
*.log
*.properties
.clover
+ build
target
local
*.ipr
*.iws
*.iml
atlassian-ide-plugin.xml
.classpath
.project
.settings
.nbattrs
*.log
*.properties
.clover
15 years, 6 months
Hibernate SVN: r16537 - in core/branches/Branch_3_2: test/org/hibernate/test/sql/hand and 1 other directories.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2009-05-11 17:15:24 -0400 (Mon, 11 May 2009)
New Revision: 16537
Added:
core/branches/Branch_3_2/test/org/hibernate/test/sql/hand/Group.java
Modified:
core/branches/Branch_3_2/src/org/hibernate/loader/custom/sql/SQLQueryReturnProcessor.java
core/branches/Branch_3_2/test/org/hibernate/test/sql/hand/Person.java
core/branches/Branch_3_2/test/org/hibernate/test/sql/hand/query/NativeSQLQueries.hbm.xml
core/branches/Branch_3_2/test/org/hibernate/test/sql/hand/query/NativeSQLQueriesTest.java
Log:
HHH-2745 - NullPointerException when eager fetching joined many-to-many with native SQL query
Modified: core/branches/Branch_3_2/src/org/hibernate/loader/custom/sql/SQLQueryReturnProcessor.java
===================================================================
--- core/branches/Branch_3_2/src/org/hibernate/loader/custom/sql/SQLQueryReturnProcessor.java 2009-05-11 21:13:36 UTC (rev 16536)
+++ core/branches/Branch_3_2/src/org/hibernate/loader/custom/sql/SQLQueryReturnProcessor.java 2009-05-11 21:15:24 UTC (rev 16537)
@@ -374,7 +374,7 @@
alias2CollectionSuffix.put( alias, suffix );
collectionPropertyResultMaps.put( alias, propertyResults );
- if ( collectionPersister.isOneToMany() ) {
+ if ( collectionPersister.isOneToMany() || collectionPersister.isManyToMany() ) {
SQLLoadable persister = ( SQLLoadable ) collectionPersister.getElementPersister();
addPersister( alias, filter( propertyResults ), persister );
}
Added: core/branches/Branch_3_2/test/org/hibernate/test/sql/hand/Group.java
===================================================================
--- core/branches/Branch_3_2/test/org/hibernate/test/sql/hand/Group.java (rev 0)
+++ core/branches/Branch_3_2/test/org/hibernate/test/sql/hand/Group.java 2009-05-11 21:15:24 UTC (rev 16537)
@@ -0,0 +1,42 @@
+package org.hibernate.test.sql.hand;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class Group {
+ private Long id;
+ private List persons = new ArrayList();
+ private String name;
+
+ public Group() {
+ }
+
+ public Group(String name) {
+ this.name = name;
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public List getPersons() {
+ return persons;
+ }
+
+ public void setPersons(List persons) {
+ this.persons = persons;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+}
Modified: core/branches/Branch_3_2/test/org/hibernate/test/sql/hand/Person.java
===================================================================
--- core/branches/Branch_3_2/test/org/hibernate/test/sql/hand/Person.java 2009-05-11 21:13:36 UTC (rev 16536)
+++ core/branches/Branch_3_2/test/org/hibernate/test/sql/hand/Person.java 2009-05-11 21:15:24 UTC (rev 16537)
@@ -1,37 +1,61 @@
-//$Id: Person.java 4316 2004-08-14 13:12:03Z oneovthafew $
+/*
+ * Copyright (c) 2009, 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.sql.hand;
/**
* @author Gavin King
*/
public class Person {
- private long id;
+ private Long id;
private String name;
public Person(String name) {
this.name = name;
}
-
- public Person() {}
-
-/**
+
+ public Person() {
+ }
+
+ /**
* @return Returns the id.
*/
- public long getId() {
+ public Long getId() {
return id;
}
+
/**
* @param id The id to set.
*/
- public void setId(long id) {
+ public void setId(Long id) {
this.id = id;
}
+
/**
* @return Returns the name.
*/
public String getName() {
return name;
}
+
/**
* @param name The name to set.
*/
Modified: core/branches/Branch_3_2/test/org/hibernate/test/sql/hand/query/NativeSQLQueries.hbm.xml
===================================================================
--- core/branches/Branch_3_2/test/org/hibernate/test/sql/hand/query/NativeSQLQueries.hbm.xml 2009-05-11 21:13:36 UTC (rev 16536)
+++ core/branches/Branch_3_2/test/org/hibernate/test/sql/hand/query/NativeSQLQueries.hbm.xml 2009-05-11 21:15:24 UTC (rev 16537)
@@ -31,6 +31,19 @@
</class>
+ <class name="Group" table="GROUPP">
+ <id name="id" unsaved-value="0" column="ID">
+ <generator class="increment"/>
+ </id>
+ <property name="name" column="NAME" not-null="true"/>
+ <list name="persons" table="GROUP_PERSON"
+ cascade="none" inverse="false" lazy="true">
+ <key column="GROUP_ID" />
+ <list-index column="POS" />
+ <many-to-many class="Person" column="PERSON_ID" />
+ </list>
+ </class>
+
<class name="Employment" table="EMPLOYMENT">
<id name="employmentId" unsaved-value="0" column="EMPID">
<generator class="increment"/>
@@ -259,4 +272,31 @@
LEFT OUTER JOIN EMPLOYMENT emp ON org.ORGID = emp.EMPLOYER
</sql-query>
+ <sql-query name="manyToManyFetch">
+ <![CDATA[
+ SELECT groupp.ID as group_id,
+ groupp.NAME as group_name,
+ group_person.PERSON_ID as group_person_personId,
+ group_person.GROUP_ID as group_person_groupId,
+ group_person.POS as group_person_pos,
+ person.PERID as person_id,
+ person.NAME as person_name
+ FROM GROUPP groupp,
+ GROUP_PERSON group_person,
+ PERSON person
+ WHERE groupp.ID = group_person.GROUP_ID
+ and person.PERID = group_person.PERSON_ID
+ ]]>
+ <return alias="groupp" class="Group">
+ <return-property name="id" column="group_id" />
+ <return-property name="name" column="group_name" />
+ </return>
+ <return-join alias="group_person" property="groupp.persons">
+ <return-property name="key" column="group_person_groupId" />
+ <return-property name="index" column="group_person_pos" />
+ <return-property name="element" column="person_id" />
+ <return-property name="element.id" column="person_id" />
+ <return-property name="element.name" column="person_name" />
+ </return-join>
+ </sql-query>
</hibernate-mapping>
\ No newline at end of file
Modified: core/branches/Branch_3_2/test/org/hibernate/test/sql/hand/query/NativeSQLQueriesTest.java
===================================================================
--- core/branches/Branch_3_2/test/org/hibernate/test/sql/hand/query/NativeSQLQueriesTest.java 2009-05-11 21:13:36 UTC (rev 16536)
+++ core/branches/Branch_3_2/test/org/hibernate/test/sql/hand/query/NativeSQLQueriesTest.java 2009-05-11 21:15:24 UTC (rev 16537)
@@ -14,21 +14,22 @@
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.cfg.Environment;
+import org.hibernate.junit.functional.FunctionalTestCase;
+import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
+import org.hibernate.test.sql.hand.Dimension;
+import org.hibernate.test.sql.hand.Employment;
+import org.hibernate.test.sql.hand.Group;
+import org.hibernate.test.sql.hand.Order;
import org.hibernate.test.sql.hand.Organization;
import org.hibernate.test.sql.hand.Person;
-import org.hibernate.test.sql.hand.Employment;
import org.hibernate.test.sql.hand.Product;
-import org.hibernate.test.sql.hand.Order;
-import org.hibernate.test.sql.hand.Dimension;
import org.hibernate.test.sql.hand.SpaceShip;
import org.hibernate.test.sql.hand.Speech;
-import org.hibernate.cfg.Configuration;
-import org.hibernate.cfg.Environment;
-import org.hibernate.junit.functional.FunctionalTestCase;
-import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
+import org.hibernate.transform.AliasToEntityMapResultTransformer;
import org.hibernate.transform.DistinctRootEntityResultTransformer;
import org.hibernate.transform.Transformers;
-import org.hibernate.transform.AliasToEntityMapResultTransformer;
/**
* Tests of various features of native SQL queries.
@@ -608,6 +609,63 @@
}
}
+ public void testAddJoinForManyToMany() {
+ Session s = openSession();
+ Transaction t = s.beginTransaction();
+ Person gavin = new Person( "Gavin" );
+ Person max = new Person( "Max" );
+ Person pete = new Person( "Pete" );
+
+ Group hibernate = new Group( "Hibernate" );
+ Group seam = new Group( "Seam" );
+
+ s.persist( gavin );
+ s.persist( max );
+ s.persist( pete );
+ s.persist( seam );
+ s.persist( hibernate );
+
+ hibernate.getPersons().add( gavin );
+ hibernate.getPersons().add( max );
+ seam.getPersons().add( gavin );
+ seam.getPersons().add( pete );
+
+ s.flush();
+ s.clear();
+
+ // todo : see http://opensource.atlassian.com/projects/hibernate/browse/HHH-3908
+// String sqlStr = "SELECT {groupp.*} , {gp.*} " +
+// "FROM GROUPP groupp, GROUP_PERSON gp, PERSON person WHERE groupp.ID = gp.GROUP_ID and person.PERID = gp.PERSON_ID";
+//
+// List l = s.createSQLQuery( sqlStr )
+// .addEntity("groupp", Group.class)
+// .addJoin("gp","groupp.persons")
+// .list();
+ List l = s.getNamedQuery( "manyToManyFetch" ).list();
+ //assertEquals( 2, l.size() );
+
+ t.commit();
+ s.close();
+
+ s = openSession();
+ t = s.beginTransaction();
+
+ seam.getPersons().remove( gavin );
+ seam.getPersons().remove( pete );
+
+ hibernate.getPersons().remove( gavin );
+ hibernate.getPersons().remove( max );
+
+ s.delete( seam );
+ s.delete( hibernate );
+ s.delete( gavin );
+ s.delete( max );
+ s.delete( pete );
+
+ t.commit();
+ s.close();
+ }
+
private static class UpperCasedAliasToEntityMapResultTransformer extends AliasToEntityMapResultTransformer {
public Object transformTuple(Object[] tuple, String[] aliases) {
String[] ucAliases = new String[aliases.length];
15 years, 6 months
Hibernate SVN: r16536 - in core/trunk: testsuite/src/test/java/org/hibernate/test/dialect/functional/cache and 4 other directories.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2009-05-11 17:13:36 -0400 (Mon, 11 May 2009)
New Revision: 16536
Modified:
core/trunk/documentation/manual/pom.xml
core/trunk/testsuite/src/test/java/org/hibernate/test/dialect/functional/cache/SQLFunctionsInterSystemsTest.java
core/trunk/testsuite/src/test/java/org/hibernate/test/filter/DynamicFilterTest.java
core/trunk/testsuite/src/test/java/org/hibernate/test/hql/ASTParserLoadingTest.java
core/trunk/testsuite/src/test/java/org/hibernate/test/legacy/ABCProxyTest.java
core/trunk/testsuite/src/test/java/org/hibernate/test/legacy/ABCTest.java
core/trunk/testsuite/src/test/java/org/hibernate/test/legacy/CustomSQLTest.java
core/trunk/testsuite/src/test/java/org/hibernate/test/legacy/FooBarTest.java
core/trunk/testsuite/src/test/java/org/hibernate/test/legacy/FumTest.java
core/trunk/testsuite/src/test/java/org/hibernate/test/legacy/IJ2Test.java
core/trunk/testsuite/src/test/java/org/hibernate/test/legacy/IJTest.java
core/trunk/testsuite/src/test/java/org/hibernate/test/legacy/LegacyTestCase.java
core/trunk/testsuite/src/test/java/org/hibernate/test/legacy/MasterDetailTest.java
core/trunk/testsuite/src/test/java/org/hibernate/test/legacy/MultiTableTest.java
core/trunk/testsuite/src/test/java/org/hibernate/test/legacy/ParentChildTest.java
core/trunk/testsuite/src/test/java/org/hibernate/test/legacy/SQLFunctionsTest.java
core/trunk/testsuite/src/test/java/org/hibernate/test/stateless/fetching/StatelessSessionFetchingTest.java
Log:
HHH-3804 - Cleanup usage of deprecated APIs in testsuite (Session#find, etc)
Modified: core/trunk/documentation/manual/pom.xml
===================================================================
--- core/trunk/documentation/manual/pom.xml 2009-05-11 21:12:30 UTC (rev 16535)
+++ core/trunk/documentation/manual/pom.xml 2009-05-11 21:13:36 UTC (rev 16536)
@@ -23,6 +23,7 @@
<artifactId>maven-jdocbook-plugin</artifactId>
<version>2.1.2</version>
<extensions>true</extensions>
+
<executions>
<execution>
<!--
@@ -36,6 +37,7 @@
</goals>
</execution>
</executions>
+<!--
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
@@ -44,6 +46,27 @@
<type>jdocbook-style</type>
</dependency>
</dependencies>
+-->
+ <dependencies>
+ <dependency>
+ <groupId>org.jboss</groupId>
+ <artifactId>jbossorg-docbook-xslt</artifactId>
+ <version>1.1.0</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss</groupId>
+ <artifactId>jbossorg-jdocbook-style</artifactId>
+ <version>1.1.0</version>
+ <type>jdocbook-style</type>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.tools</groupId>
+ <artifactId>jbosstools-docbook-xslt</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ </dependency>
+ </dependencies>
+
+
<configuration>
<sourceDocumentName>Hibernate_Reference.xml</sourceDocumentName>
<masterTranslation>en-US</masterTranslation>
Modified: core/trunk/testsuite/src/test/java/org/hibernate/test/dialect/functional/cache/SQLFunctionsInterSystemsTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/dialect/functional/cache/SQLFunctionsInterSystemsTest.java 2009-05-11 21:12:30 UTC (rev 16535)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/dialect/functional/cache/SQLFunctionsInterSystemsTest.java 2009-05-11 21:13:36 UTC (rev 16536)
@@ -73,7 +73,7 @@
Session s = openSession();
Transaction t = s.beginTransaction();
- Iterator iter = s.iterate("select max(s.count) from Simple s");
+ Iterator iter = s.createQuery( "select max(s.count) from Simple s" ).iterate();
if ( getDialect() instanceof MySQLDialect ) assertTrue( iter.hasNext() && iter.next()==null );
@@ -86,20 +86,20 @@
// Test to make sure allocating an specified object operates correctly.
assertTrue(
- s.find("select new org.hibernate.test.legacy.S(s.count, s.address) from Simple s").size() == 1
+ s.createQuery( "select new org.hibernate.test.legacy.S(s.count, s.address) from Simple s" ).list().size() == 1
);
// Quick check the base dialect functions operate correctly
assertTrue(
- s.find("select max(s.count) from Simple s").size() == 1
+ s.createQuery( "select max(s.count) from Simple s" ).list().size() == 1
);
assertTrue(
- s.find("select count(*) from Simple s").size() == 1
+ s.createQuery( "select count(*) from Simple s" ).list().size() == 1
);
if ( getDialect() instanceof Cache71Dialect) {
// Check Oracle Dialect mix of dialect functions - no args (no parenthesis and single arg functions
- java.util.List rset = s.find("select s.name, sysdate, floor(s.pay), round(s.pay,0) from Simple s");
+ List rset = s.createQuery( "select s.name, sysdate, floor(s.pay), round(s.pay,0) from Simple s" ).list();
assertNotNull("Name string should have been returned",(((Object[])rset.get(0))[0]));
assertNotNull("Todays Date should have been returned",(((Object[])rset.get(0))[1]));
assertEquals("floor(45.8) result was incorrect ", new Integer(45), ( (Object[]) rset.get(0) )[2] );
@@ -109,12 +109,12 @@
s.update(simple);
// Test type conversions while using nested functions (Float to Int).
- rset = s.find("select abs(round(s.pay,0)) from Simple s");
+ rset = s.createQuery( "select abs(round(s.pay,0)) from Simple s" ).list();
assertEquals("abs(round(-45.8)) result was incorrect ", new Float(46), rset.get(0));
// Test a larger depth 3 function example - Not a useful combo other than for testing
assertTrue(
- s.find("select floor(round(sysdate,1)) from Simple s").size() == 1
+ s.createQuery( "select floor(round(sysdate,1)) from Simple s" ).list().size() == 1
);
// Test the oracle standard NVL funtion as a test of multi-param functions...
@@ -126,7 +126,9 @@
if ( (getDialect() instanceof Cache71Dialect) ) {
// Test the hsql standard MOD funtion as a test of multi-param functions...
- Double value = (Double) s.find("select MOD(s.count, 2) from Simple as s where s.id = 10" ).get(0);
+ Double value = (Double) s.createQuery( "select MOD(s.count, 2) from Simple as s where s.id = 10" )
+ .list()
+ .get(0);
assertTrue( 0 == value.intValue() );
}
@@ -349,22 +351,25 @@
s.save(simple, new Long(10) );
if ( getDialect() instanceof Cache71Dialect) {
- s.find("from Simple s where repeat('foo', 3) = 'foofoofoo'");
- s.find("from Simple s where repeat(s.name, 3) = 'foofoofoo'");
- s.find("from Simple s where repeat( lower(s.name), (3 + (1-1)) / 2) = 'foofoofoo'");
+ s.createQuery( "from Simple s where repeat('foo', 3) = 'foofoofoo'" ).list();
+ s.createQuery( "from Simple s where repeat(s.name, 3) = 'foofoofoo'" ).list();
+ s.createQuery( "from Simple s where repeat( lower(s.name), (3 + (1-1)) / 2) = 'foofoofoo'" ).list();
}
assertTrue(
- s.find("from Simple s where upper( s.name ) ='SIMPLE 1'").size()==1
+ s.createQuery( "from Simple s where upper( s.name ) ='SIMPLE 1'" ).list().size()==1
);
if ( !(getDialect() instanceof HSQLDialect) ) {
assertTrue(
- s.find("from Simple s where not( upper( s.name ) ='yada' or 1=2 or 'foo'='bar' or not('foo'='foo') or 'foo' like 'bar' )").size()==1
+ s.createQuery(
+ "from Simple s where not( upper( s.name ) ='yada' or 1=2 or 'foo'='bar' or not('foo'='foo') or 'foo' like 'bar' )"
+ ).list()
+ .size()==1
);
}
if ( !(getDialect() instanceof MySQLDialect) && !(getDialect() instanceof SybaseDialect) && !(getDialect() instanceof MckoiDialect) && !(getDialect() instanceof InterbaseDialect) && !(getDialect() instanceof TimesTenDialect) ) { //My SQL has a funny concatenation operator
assertTrue(
- s.find("from Simple s where lower( s.name || ' foo' ) ='simple 1 foo'").size()==1
+ s.createQuery( "from Simple s where lower( s.name || ' foo' ) ='simple 1 foo'" ).list().size()==1
);
}
/* + is not concat in Cache
@@ -376,7 +381,7 @@
*/
if ( (getDialect() instanceof Cache71Dialect) ) {
assertTrue(
- s.find("from Simple s where lower( concat(s.name, ' foo') ) ='simple 1 foo'").size()==1
+ s.createQuery( "from Simple s where lower( concat(s.name, ' foo') ) ='simple 1 foo'" ).list().size()==1
);
}
@@ -387,44 +392,61 @@
s.save( other, new Long(20) );
//s.find("from Simple s where s.name ## 'cat|rat|bag'");
assertTrue(
- s.find("from Simple s where upper( s.other.name ) ='SIMPLE 2'").size()==1
+ s.createQuery( "from Simple s where upper( s.other.name ) ='SIMPLE 2'" ).list().size()==1
);
assertTrue(
- s.find("from Simple s where not ( upper( s.other.name ) ='SIMPLE 2' )").size()==0
+ s.createQuery( "from Simple s where not ( upper( s.other.name ) ='SIMPLE 2' )" ).list().size()==0
);
assertTrue(
- s.find("select distinct s from Simple s where ( ( s.other.count + 3 ) = (15*2)/2 and s.count = 69) or ( ( s.other.count + 2 ) / 7 ) = 2").size()==1
+ s.createQuery(
+ "select distinct s from Simple s where ( ( s.other.count + 3 ) = (15*2)/2 and s.count = 69) or ( ( s.other.count + 2 ) / 7 ) = 2"
+ ).list()
+ .size()==1
);
assertTrue(
- s.find("select s from Simple s where ( ( s.other.count + 3 ) = (15*2)/2 and s.count = 69) or ( ( s.other.count + 2 ) / 7 ) = 2 order by s.other.count").size()==1
+ s.createQuery(
+ "select s from Simple s where ( ( s.other.count + 3 ) = (15*2)/2 and s.count = 69) or ( ( s.other.count + 2 ) / 7 ) = 2 order by s.other.count"
+ ).list()
+ .size()==1
);
Simple min = new Simple();
min.setCount(-1);
s.save(min, new Long(30) );
if ( ! (getDialect() instanceof MySQLDialect) && ! (getDialect() instanceof HSQLDialect) ) { //My SQL has no subqueries
assertTrue(
- s.find("from Simple s where s.count > ( select min(sim.count) from Simple sim )").size()==2
+ s.createQuery( "from Simple s where s.count > ( select min(sim.count) from Simple sim )" )
+ .list()
+ .size()==2
);
t.commit();
t = s.beginTransaction();
assertTrue(
- s.find("from Simple s where s = some( select sim from Simple sim where sim.count>=0 ) and s.count >= 0").size()==2
+ s.createQuery(
+ "from Simple s where s = some( select sim from Simple sim where sim.count>=0 ) and s.count >= 0"
+ ).list()
+ .size()==2
);
assertTrue(
- s.find("from Simple s where s = some( select sim from Simple sim where sim.other.count=s.other.count ) and s.other.count > 0").size()==1
+ s.createQuery(
+ "from Simple s where s = some( select sim from Simple sim where sim.other.count=s.other.count ) and s.other.count > 0"
+ ).list()
+ .size()==1
);
}
- Iterator iter = s.iterate("select sum(s.count) from Simple s group by s.count having sum(s.count) > 10");
+ Iterator iter = s.createQuery( "select sum(s.count) from Simple s group by s.count having sum(s.count) > 10" )
+ .iterate();
assertTrue( iter.hasNext() );
assertEquals( new Long(12), iter.next() );
assertTrue( !iter.hasNext() );
if ( ! (getDialect() instanceof MySQLDialect) ) {
- iter = s.iterate("select s.count from Simple s group by s.count having s.count = 12");
+ iter = s.createQuery( "select s.count from Simple s group by s.count having s.count = 12" ).iterate();
assertTrue( iter.hasNext() );
}
- s.iterate("select s.id, s.count, count(t), max(t.date) from Simple s, Simple t where s.count = t.count group by s.id, s.count order by s.count");
+ s.createQuery(
+ "select s.id, s.count, count(t), max(t.date) from Simple s, Simple t where s.count = t.count group by s.id, s.count order by s.count"
+ ).iterate();
Query q = s.createQuery("from Simple s");
q.setMaxResults(10);
@@ -486,6 +508,7 @@
public void testBlobClob() throws Exception {
Session s = openSession();
+ s.beginTransaction();
Blobber b = new Blobber();
b.setBlob( Hibernate.createBlob( "foo/bar/baz".getBytes() ) );
b.setClob( Hibernate.createClob("foo/bar/baz") );
@@ -499,10 +522,11 @@
b.getClob().getSubString(2, 3);
//b.getClob().setString(2, "abc");
s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
s = openSession();
+ s.beginTransaction();
b = (Blobber) s.load( Blobber.class, new Integer( b.getId() ) );
Blobber b2 = new Blobber();
s.save(b2);
@@ -512,22 +536,24 @@
b.getClob().getSubString(1, 6);
//b.getClob().setString(1, "qwerty");
s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
s = openSession();
+ s.beginTransaction();
b = (Blobber) s.load( Blobber.class, new Integer( b.getId() ) );
b.setClob( Hibernate.createClob("xcvfxvc xcvbx cvbx cvbx cvbxcvbxcvbxcvb") );
s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
s = openSession();
+ s.beginTransaction();
b = (Blobber) s.load( Blobber.class, new Integer( b.getId() ) );
assertTrue( b.getClob().getSubString(1, 7).equals("xcvfxvc") );
//b.getClob().setString(5, "1234567890");
s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
@@ -580,7 +606,7 @@
s = openSession();
t = s.beginTransaction();
- List result = s.find(query);
+ List result = s.createQuery( query ).list();
assertTrue( result.size() == 1 );
assertTrue(result.get(0) instanceof Simple);
s.delete( result.get(0) );
@@ -704,29 +730,60 @@
assertTrue( test.getDate1().equals(testvalue));
test = (TestInterSystemsFunctionsClass) s.get(TestInterSystemsFunctionsClass.class, new Long(10), LockMode.UPGRADE);
assertTrue( test.getDate1().equals(testvalue));
- Date value = (Date) s.find("select nvl(o.date,o.dateText) from TestInterSystemsFunctionsClass as o" ).get(0);
+ Date value = (Date) s.createQuery( "select nvl(o.date,o.dateText) from TestInterSystemsFunctionsClass as o" )
+ .list()
+ .get(0);
assertTrue( value.equals(testvalue));
- Object nv = s.find("select nullif(o.dateText,o.dateText) from TestInterSystemsFunctionsClass as o" ).get(0);
+ Object nv = s.createQuery( "select nullif(o.dateText,o.dateText) from TestInterSystemsFunctionsClass as o" )
+ .list()
+ .get(0);
assertTrue( nv == null);
- String dateText = (String) s.find("select nvl(o.dateText,o.date) from TestInterSystemsFunctionsClass as o" ).get(0);
+ String dateText = (String) s.createQuery(
+ "select nvl(o.dateText,o.date) from TestInterSystemsFunctionsClass as o"
+ ).list()
+ .get(0);
assertTrue( dateText.equals("1977-07-03"));
- value = (Date) s.find("select ifnull(o.date,o.date1) from TestInterSystemsFunctionsClass as o" ).get(0);
+ value = (Date) s.createQuery( "select ifnull(o.date,o.date1) from TestInterSystemsFunctionsClass as o" )
+ .list()
+ .get(0);
assertTrue( value.equals(testvalue));
- value = (Date) s.find("select ifnull(o.date3,o.date,o.date1) from TestInterSystemsFunctionsClass as o" ).get(0);
+ value = (Date) s.createQuery( "select ifnull(o.date3,o.date,o.date1) from TestInterSystemsFunctionsClass as o" )
+ .list()
+ .get(0);
assertTrue( value.equals(testvalue));
- Integer pos = (Integer) s.find("select position('07', o.dateText) from TestInterSystemsFunctionsClass as o" ).get(0);
+ Integer pos = (Integer) s.createQuery(
+ "select position('07', o.dateText) from TestInterSystemsFunctionsClass as o"
+ ).list()
+ .get(0);
assertTrue(pos.intValue() == 6);
- String st = (String) s.find("select convert(o.date1, SQL_TIME) from TestInterSystemsFunctionsClass as o" ).get(0);
+ String st = (String) s.createQuery( "select convert(o.date1, SQL_TIME) from TestInterSystemsFunctionsClass as o" )
+ .list()
+ .get(0);
assertTrue( st.equals("00:00:00"));
- java.sql.Time tm = (java.sql.Time) s.find("select cast(o.date1, time) from TestInterSystemsFunctionsClass as o" ).get(0);
+ java.sql.Time tm = (java.sql.Time) s.createQuery(
+ "select cast(o.date1, time) from TestInterSystemsFunctionsClass as o"
+ ).list()
+ .get(0);
assertTrue( tm.toString().equals("00:00:00"));
- Double diff = (Double)s.find("select timestampdiff(SQL_TSI_FRAC_SECOND, o.date3, o.date1) from TestInterSystemsFunctionsClass as o" ).get(0);
+ Double diff = (Double) s.createQuery(
+ "select timestampdiff(SQL_TSI_FRAC_SECOND, o.date3, o.date1) from TestInterSystemsFunctionsClass as o"
+ ).list()
+ .get(0);
assertTrue(diff.doubleValue() != 0.0);
- diff = (Double)s.find("select timestampdiff(SQL_TSI_MONTH, o.date3, o.date1) from TestInterSystemsFunctionsClass as o" ).get(0);
+ diff = (Double) s.createQuery(
+ "select timestampdiff(SQL_TSI_MONTH, o.date3, o.date1) from TestInterSystemsFunctionsClass as o"
+ ).list()
+ .get(0);
assertTrue(diff.doubleValue() == 16.0);
- diff = (Double)s.find("select timestampdiff(SQL_TSI_WEEK, o.date3, o.date1) from TestInterSystemsFunctionsClass as o" ).get(0);
+ diff = (Double) s.createQuery(
+ "select timestampdiff(SQL_TSI_WEEK, o.date3, o.date1) from TestInterSystemsFunctionsClass as o"
+ ).list()
+ .get(0);
assertTrue(diff.doubleValue() >= 16*4);
- diff = (Double)s.find("select timestampdiff(SQL_TSI_YEAR, o.date3, o.date1) from TestInterSystemsFunctionsClass as o" ).get(0);
+ diff = (Double) s.createQuery(
+ "select timestampdiff(SQL_TSI_YEAR, o.date3, o.date1) from TestInterSystemsFunctionsClass as o"
+ ).list()
+ .get(0);
assertTrue(diff.doubleValue() == 1.0);
t.commit();
Modified: core/trunk/testsuite/src/test/java/org/hibernate/test/filter/DynamicFilterTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/filter/DynamicFilterTest.java 2009-05-11 21:12:30 UTC (rev 16535)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/filter/DynamicFilterTest.java 2009-05-11 21:13:36 UTC (rev 16536)
@@ -270,7 +270,7 @@
session.enableFilter("region").setParameter("region", "APAC");
DetachedCriteria lineItemSubquery = DetachedCriteria.forClass(LineItem.class)
- .add(Restrictions.ge("quantity", 1L))
+ .add(Restrictions.ge( "quantity", new Long(1L) ))
.createCriteria("product")
.add(Restrictions.eq("name", "Acme Hair Gel"))
.setProjection(Property.forName("id"));
@@ -291,7 +291,7 @@
.setProjection(Property.forName("id"));
lineItemSubquery = DetachedCriteria.forClass(LineItem.class)
- .add(Restrictions.ge("quantity", 1L))
+ .add(Restrictions.ge("quantity", new Long(1L) ))
.createCriteria("product")
.add(Subqueries.propertyIn("id", productSubquery))
.setProjection(Property.forName("id"));
Modified: core/trunk/testsuite/src/test/java/org/hibernate/test/hql/ASTParserLoadingTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/hql/ASTParserLoadingTest.java 2009-05-11 21:12:30 UTC (rev 16535)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/hql/ASTParserLoadingTest.java 2009-05-11 21:13:36 UTC (rev 16536)
@@ -1638,7 +1638,9 @@
assertTrue( "Incorrect return type", obj instanceof List );
assertEquals( "Incorrect return type", ( (List) obj ).size(), 2 );
- iter = ((org.hibernate.classic.Session)session).iterate( "select new list(an.description, an.bodyWeight) from Animal an" );
+ iter = ( ( org.hibernate.classic.Session ) session ).createQuery(
+ "select new list(an.description, an.bodyWeight) from Animal an"
+ ).iterate();
assertTrue( "Incorrect result size", iter.hasNext() );
obj = iter.next();
assertTrue( "Incorrect return type", obj instanceof List );
Modified: core/trunk/testsuite/src/test/java/org/hibernate/test/legacy/ABCProxyTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/legacy/ABCProxyTest.java 2009-05-11 21:12:30 UTC (rev 16535)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/legacy/ABCProxyTest.java 2009-05-11 21:13:36 UTC (rev 16536)
@@ -55,7 +55,7 @@
s = openSession();
t = s.beginTransaction();
- List list = s.find("from B");
+ List list = s.createQuery( "from B" ).list();
assertTrue( list.size()==2 );
t.commit();
s.close();
@@ -200,8 +200,8 @@
t = s.beginTransaction();
s.save( new B() );
s.save( new A() );
- assertTrue( s.find("from B").size()==1 );
- assertTrue( s.find("from A").size()==2 );
+ assertTrue( s.createQuery( "from B" ).list().size()==1 );
+ assertTrue( s.createQuery( "from A" ).list().size()==2 );
s.delete("from A");
t.commit();
s.close();
@@ -253,14 +253,14 @@
t = s.beginTransaction();
List l = s.find( "from E e, A a where e.reverse = a.forward and a = ?", a, Hibernate.entity(A.class) );
assertTrue( l.size()==1 );
- l = s.find( "from E e join fetch e.reverse" );
+ l = s.createQuery( "from E e join fetch e.reverse" ).list();
assertTrue( l.size()==2 );
t.commit();
s.close();
s = openSession();
t = s.beginTransaction();
- l = s.find( "from E e" );
+ l = s.createQuery( "from E e" ).list();
assertTrue( l.size()==2 );
E e = (E) l.get(0);
assertTrue( e==e.getReverse().getForward() );
@@ -283,7 +283,7 @@
s = openSession();
t = s.beginTransaction();
- l = s.find( "from E e" );
+ l = s.createQuery( "from E e" ).list();
assertTrue( l.size()==0 );
t.commit();
s.close();
Modified: core/trunk/testsuite/src/test/java/org/hibernate/test/legacy/ABCTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/legacy/ABCTest.java 2009-05-11 21:12:30 UTC (rev 16535)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/legacy/ABCTest.java 2009-05-11 21:13:36 UTC (rev 16536)
@@ -42,7 +42,7 @@
s.clear();
getSessions().evict(D.class);
getSessions().evict(A.class);
- assertTrue( s.find("from D d join d.reverse r join d.inverse i where i = r").size()==1 );
+ assertTrue( s.createQuery( "from D d join d.reverse r join d.inverse i where i = r" ).list().size()==1 );
t.commit();
s.close();
}
@@ -75,7 +75,7 @@
d.setId( c1.getId() );
s.save(d);
- assertTrue( s.find("from C2 c where 1=1 or 1=1").size()==0 );
+ assertTrue( s.createQuery( "from C2 c where 1=1 or 1=1" ).list().size()==0 );
t.commit();
s.close();
Modified: core/trunk/testsuite/src/test/java/org/hibernate/test/legacy/CustomSQLTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/legacy/CustomSQLTest.java 2009-05-11 21:12:30 UTC (rev 16535)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/legacy/CustomSQLTest.java 2009-05-11 21:13:36 UTC (rev 16536)
@@ -163,7 +163,7 @@
p.setName("Max");
p.setLastName("Andersen");
- p.setNationalID("110974XYZ�");
+ p.setNationalID("110974XYZ�");
p.setAddress("P. P. Street 8");
Session s = openSession();
@@ -183,7 +183,7 @@
assertEquals(p2.getLastName(),p.getLastName());
s.flush();
- List list = s.find("select p from Party as p");
+ List list = s.createQuery( "select p from Party as p" ).list();
assertTrue(list.size() == 1);
s.connection().commit();
@@ -191,17 +191,17 @@
s = openSession();
- list = s.find("select p from Person as p where p.address = 'L�rkev�nget 1'");
+ list = s.createQuery( "select p from Person as p where p.address = 'L�rkev�nget 1'" ).list();
assertTrue(list.size() == 0);
- p.setAddress("L�rkev�nget 1");
+ p.setAddress("L�rkev�nget 1");
s.update(p);
- list = s.find("select p from Person as p where p.address = 'L�rkev�nget 1'");
+ list = s.createQuery( "select p from Person as p where p.address = 'L�rkev�nget 1'" ).list();
assertTrue(list.size() == 1);
- list = s.find("select p from Party as p where p.address = 'P. P. Street 8'");
+ list = s.createQuery( "select p from Party as p where p.address = 'P. P. Street 8'" ).list();
assertTrue(list.size() == 0);
s.delete(p);
- list = s.find("select p from Person as p");
+ list = s.createQuery( "select p from Person as p" ).list();
assertTrue(list.size() == 0);
s.connection().commit();
Modified: core/trunk/testsuite/src/test/java/org/hibernate/test/legacy/FooBarTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/legacy/FooBarTest.java 2009-05-11 21:12:30 UTC (rev 16535)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/legacy/FooBarTest.java 2009-05-11 21:13:36 UTC (rev 16536)
@@ -34,7 +34,6 @@
import org.hibernate.QueryException;
import org.hibernate.ScrollableResults;
import org.hibernate.Transaction;
-import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment;
import org.hibernate.classic.Session;
import org.hibernate.connection.ConnectionProvider;
@@ -45,14 +44,11 @@
import org.hibernate.criterion.Restrictions;
import org.hibernate.dialect.DB2Dialect;
import org.hibernate.dialect.DerbyDialect;
-import org.hibernate.dialect.Dialect;
import org.hibernate.dialect.HSQLDialect;
import org.hibernate.dialect.InterbaseDialect;
import org.hibernate.dialect.MckoiDialect;
import org.hibernate.dialect.MySQLDialect;
import org.hibernate.dialect.Oracle8iDialect;
-//import org.hibernate.dialect.Oracle9Dialect;
-//import org.hibernate.dialect.OracleDialect;
import org.hibernate.dialect.PointbaseDialect;
import org.hibernate.dialect.PostgreSQLDialect;
import org.hibernate.dialect.SAPDBDialect;
@@ -62,14 +58,17 @@
import org.hibernate.dialect.TimesTenDialect;
import org.hibernate.engine.SessionFactoryImplementor;
import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
-//import org.hibernate.mapping.RootClass;
import org.hibernate.proxy.HibernateProxy;
import org.hibernate.type.Type;
import org.hibernate.util.JoinedIterator;
import org.hibernate.util.SerializationHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
public class FooBarTest extends LegacyTestCase {
+ private static final Logger log = LoggerFactory.getLogger( FooBarTest.class );
public FooBarTest(String arg) {
super(arg);
@@ -108,6 +107,7 @@
public void testSaveOrUpdateCopyAny() throws Exception {
Session s = openSession();
+ s.beginTransaction();
Bar bar = new Bar();
One one = new One();
bar.setObject(one);
@@ -117,20 +117,22 @@
s.delete(g);
s.flush();
assertTrue( s.contains(one) );
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
s = openSession();
+ s.beginTransaction();
Bar bar2 = (Bar) s.saveOrUpdateCopy(bar);
s.flush();
s.delete(bar2);
s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
}
public void testRefreshProxy() throws Exception {
Session s = openSession();
+ s.beginTransaction();
Glarch g = new Glarch();
Serializable gid = s.save(g);
s.flush();
@@ -140,17 +142,17 @@
s.refresh(gp);
s.delete(gp);
s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
}
public void testOnCascadeDelete() throws Exception {
-
if ( ! supportsCircularCascadeDelete() ) {
return;
}
Session s = openSession();
+ s.beginTransaction();
Baz baz = new Baz();
baz.subs = new ArrayList();
Baz sub = new Baz();
@@ -159,17 +161,19 @@
s.save(baz);
s.flush();
assertTrue( s.createQuery("from Baz").list().size()==2 );
- s.connection().commit();
+ s.getTransaction().commit();
+ s.beginTransaction();
s.delete(baz);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
+ s.beginTransaction();
assertTrue( s.createQuery("from Baz").list().size()==0 );
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
}
public void testRemoveFromIdbag() throws Exception {
Session s = openSession();
+ s.beginTransaction();
Baz baz = new Baz();
baz.setByteBag( new ArrayList() );
byte[] bytes = { 12, 13 };
@@ -184,41 +188,42 @@
baz.getByteBag().add(bytes);
s.flush();
s.delete(baz);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
}
public void testLoad() throws Exception {
Session s = openSession();
+ s.beginTransaction();
Qux q = new Qux();
s.save(q);
BarProxy b = new Bar();
s.save(b);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
+
s = openSession();
+ s.beginTransaction();
q = (Qux) s.load(Qux.class, q.getKey() );
b = (BarProxy) s.load( Foo.class, b.getKey() );
b.getKey();
assertFalse( Hibernate.isInitialized(b) );
b.getBarString();
assertTrue( Hibernate.isInitialized(b) );
- BarProxy b2 = (BarProxy) s.load( Bar.class, new String( b.getKey() ) );
+ BarProxy b2 = (BarProxy) s.load( Bar.class, b.getKey() );
Qux q2 = (Qux) s.load( Qux.class, q.getKey() );
assertTrue( "loaded same object", q==q2 );
assertTrue( "loaded same object", b==b2 );
assertTrue( Math.round( b.getFormula() ) == b.getInt()/2 );
s.delete(q2);
s.delete(b2);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
}
public void testJoin() throws Exception {
Session s = openSession();
+ s.beginTransaction();
Foo foo = new Foo();
foo.setJoinedProp("foo");
s.save(foo);
@@ -227,25 +232,25 @@
s.flush();
String fid = foo.getKey();
s.delete(foo);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
s = openSession();
+ s.beginTransaction();
Foo foo2 = new Foo();
foo2.setJoinedProp("foo");
s.save(foo2);
- s.find("select foo.id from Foo foo where foo.joinedProp = 'foo'");
+ s.createQuery( "select foo.id from Foo foo where foo.joinedProp = 'foo'" ).list();
assertNull( s.get(Foo.class, fid) );
s.delete(foo2);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
}
public void testDereferenceLazyCollection() throws Exception {
Session s = openSession();
+ s.beginTransaction();
Baz baz = new Baz();
baz.setFooSet( new HashSet() );
Foo foo = new Foo();
@@ -253,31 +258,31 @@
s.save(foo);
s.save(baz);
foo.setBytes( "foobar".getBytes() );
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
s = openSession();
+ s.beginTransaction();
foo = (Foo) s.get( Foo.class, foo.getKey() );
assertTrue( Hibernate.isInitialized( foo.getBytes() ) );
assertTrue( foo.getBytes().length==6 );
baz = (Baz) s.get( Baz.class, baz.getCode() );
assertTrue( baz.getFooSet().size()==1 );
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
getSessions().evictCollection("org.hibernate.test.legacy.Baz.fooSet");
s = openSession();
+ s.beginTransaction();
baz = (Baz) s.get( Baz.class, baz.getCode() );
assertFalse( Hibernate.isInitialized( baz.getFooSet() ) );
baz.setFooSet(null);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
s = openSession();
+ s.beginTransaction();
foo = (Foo) s.get( Foo.class, foo.getKey() );
assertTrue( foo.getBytes().length==6 );
baz = (Baz) s.get( Baz.class, baz.getCode() );
@@ -285,13 +290,13 @@
assertTrue( baz.getFooSet().size()==0 );
s.delete(baz);
s.delete(foo);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
}
public void testMoveLazyCollection() throws Exception {
Session s = openSession();
+ s.beginTransaction();
Baz baz = new Baz();
Baz baz2 = new Baz();
baz.setFooSet( new HashSet() );
@@ -301,34 +306,34 @@
s.save(baz);
s.save(baz2);
foo.setBytes( "foobar".getBytes() );
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
s = openSession();
+ s.beginTransaction();
foo = (Foo) s.get( Foo.class, foo.getKey() );
assertTrue( Hibernate.isInitialized( foo.getBytes() ) );
assertTrue( foo.getBytes().length==6 );
baz = (Baz) s.get( Baz.class, baz.getCode() );
assertTrue( baz.getFooSet().size()==1 );
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
getSessions().evictCollection("org.hibernate.test.legacy.Baz.fooSet");
s = openSession();
+ s.beginTransaction();
baz = (Baz) s.get( Baz.class, baz.getCode() );
assertFalse( Hibernate.isInitialized( baz.getFooSet() ) );
baz2 = (Baz) s.get( Baz.class, baz2.getCode() );
baz2.setFooSet( baz.getFooSet() );
baz.setFooSet(null);
assertFalse( Hibernate.isInitialized( baz2.getFooSet() ) );
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
s = openSession();
+ s.beginTransaction();
foo = (Foo) s.get( Foo.class, foo.getKey() );
assertTrue( foo.getBytes().length==6 );
baz = (Baz) s.get( Baz.class, baz.getCode() );
@@ -340,27 +345,27 @@
s.delete(baz);
s.delete(baz2);
s.delete(foo);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
}
public void testCriteriaCollection() throws Exception {
Session s = openSession();
+ s.beginTransaction();
Baz bb = (Baz) s.createCriteria(Baz.class).uniqueResult();
assertTrue(bb==null);
Baz baz = new Baz();
s.save(baz);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
+
s = openSession();
+ s.beginTransaction();
Baz b = (Baz) s.createCriteria(Baz.class).uniqueResult();
assertTrue( Hibernate.isInitialized( b.getTopGlarchez() ) );
assertTrue( b.getTopGlarchez().size()==0 );
s.delete(b);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
}
@@ -373,64 +378,75 @@
s.save(foo2);
foo.setFoo(foo2);
- List list = s.find("from Foo foo inner join fetch foo.foo");
+ List list = s.createQuery( "from Foo foo inner join fetch foo.foo" ).list();
Foo foof = (Foo) list.get(0);
assertTrue( Hibernate.isInitialized( foof.getFoo() ) );
- list = s.find("from Baz baz left outer join fetch baz.fooToGlarch");
+ s.createQuery( "from Baz baz left outer join fetch baz.fooToGlarch" ).list();
- list = s.find(
- "select foo, bar from Foo foo left outer join foo.foo bar where foo = ?",
- foo,
- Hibernate.entity(Foo.class)
- );
+ list = s.createQuery( "select foo, bar from Foo foo left outer join foo.foo bar where foo = ?" )
+ .setParameter( 0, foo, Hibernate.entity(Foo.class) )
+ .list();
Object[] row1 = (Object[]) list.get(0);
assertTrue( row1[0]==foo && row1[1]==foo2 );
- s.find("select foo.foo.foo.string from Foo foo where foo.foo = 'bar'");
- s.find("select foo.foo.foo.foo.string from Foo foo where foo.foo = 'bar'");
- s.find("select foo from Foo foo where foo.foo.foo = 'bar'");
- s.find("select foo.foo.foo.foo.string from Foo foo where foo.foo.foo = 'bar'");
- s.find("select foo.foo.foo.string from Foo foo where foo.foo.foo.foo.string = 'bar'");
- if ( ! (getDialect() instanceof HSQLDialect) ) s.find("select foo.string from Foo foo where foo.foo.foo.foo = foo.foo.foo");
- s.find("select foo.string from Foo foo where foo.foo.foo = 'bar' and foo.foo.foo.foo = 'baz'");
- s.find("select foo.string from Foo foo where foo.foo.foo.foo.string = 'a' and foo.foo.string = 'b'");
+ s.createQuery( "select foo.foo.foo.string from Foo foo where foo.foo = 'bar'" ).list();
+ s.createQuery( "select foo.foo.foo.foo.string from Foo foo where foo.foo = 'bar'" ).list();
+ s.createQuery( "select foo from Foo foo where foo.foo.foo = 'bar'" ).list();
+ s.createQuery( "select foo.foo.foo.foo.string from Foo foo where foo.foo.foo = 'bar'" ).list();
+ s.createQuery( "select foo.foo.foo.string from Foo foo where foo.foo.foo.foo.string = 'bar'" ).list();
+ if ( ! (getDialect() instanceof HSQLDialect) )
+ s.createQuery( "select foo.string from Foo foo where foo.foo.foo.foo = foo.foo.foo" ).list();
+ s.createQuery( "select foo.string from Foo foo where foo.foo.foo = 'bar' and foo.foo.foo.foo = 'baz'" ).list();
+ s.createQuery( "select foo.string from Foo foo where foo.foo.foo.foo.string = 'a' and foo.foo.string = 'b'" )
+ .list();
- s.find("from Bar bar, foo in elements(bar.baz.fooArray)");
+ s.createQuery( "from Bar bar, foo in elements(bar.baz.fooArray)" ).list();
//s.find("from Baz as baz where baz.topComponents[baz].name = 'bazzz'");
if ( (getDialect() instanceof DB2Dialect) && !(getDialect() instanceof DerbyDialect) ) {
- s.find("from Foo foo where lower( foo.foo.string ) = 'foo'");
- s.find("from Foo foo where lower( (foo.foo.string || 'foo') || 'bar' ) = 'foo'");
- s.find("from Foo foo where repeat( (foo.foo.string || 'foo') || 'bar', 2 ) = 'foo'");
- s.find("from Bar foo where foo.foo.integer is not null and repeat( (foo.foo.string || 'foo') || 'bar', (5+5)/2 ) = 'foo'");
- s.find("from Bar foo where foo.foo.integer is not null or repeat( (foo.foo.string || 'foo') || 'bar', (5+5)/2 ) = 'foo'");
+ s.createQuery( "from Foo foo where lower( foo.foo.string ) = 'foo'" ).list();
+ s.createQuery( "from Foo foo where lower( (foo.foo.string || 'foo') || 'bar' ) = 'foo'" ).list();
+ s.createQuery( "from Foo foo where repeat( (foo.foo.string || 'foo') || 'bar', 2 ) = 'foo'" ).list();
+ s.createQuery(
+ "from Bar foo where foo.foo.integer is not null and repeat( (foo.foo.string || 'foo') || 'bar', (5+5)/2 ) = 'foo'"
+ ).list();
+ s.createQuery(
+ "from Bar foo where foo.foo.integer is not null or repeat( (foo.foo.string || 'foo') || 'bar', (5+5)/2 ) = 'foo'"
+ ).list();
}
- if (getDialect() instanceof SybaseDialect) {
- s.iterate("select baz from Baz as baz join baz.fooArray foo group by baz order by sum(foo.float)");
+ if (getDialect() instanceof SybaseDialect) {
+ s.createQuery( "select baz from Baz as baz join baz.fooArray foo group by baz order by sum(foo.float)" )
+ .iterate();
}
- s.find("from Foo as foo where foo.component.glarch.name is not null");
- s.find("from Foo as foo left outer join foo.component.glarch as glarch where glarch.name = 'foo'");
+ s.createQuery( "from Foo as foo where foo.component.glarch.name is not null" ).list();
+ s.createQuery( "from Foo as foo left outer join foo.component.glarch as glarch where glarch.name = 'foo'" )
+ .list();
- list = s.find("from Foo");
+ list = s.createQuery( "from Foo" ).list();
assertTrue( list.size()==2 && list.get(0) instanceof FooProxy );
- list = s.find("from Foo foo left outer join foo.foo");
+ list = s.createQuery( "from Foo foo left outer join foo.foo" ).list();
assertTrue( list.size()==2 && ( (Object[]) list.get(0) )[0] instanceof FooProxy );
s.createQuery("from Bar, Bar").list();
s.createQuery("from Foo, Bar").list();
- s.find("from Baz baz left join baz.fooToGlarch, Bar bar join bar.foo");
- s.find("from Baz baz left join baz.fooToGlarch join baz.fooSet");
- s.find("from Baz baz left join baz.fooToGlarch join fetch baz.fooSet foo left join fetch foo.foo");
+ s.createQuery( "from Baz baz left join baz.fooToGlarch, Bar bar join bar.foo" ).list();
+ s.createQuery( "from Baz baz left join baz.fooToGlarch join baz.fooSet" ).list();
+ s.createQuery( "from Baz baz left join baz.fooToGlarch join fetch baz.fooSet foo left join fetch foo.foo" )
+ .list();
- list = s.find("from Foo foo where foo.string='osama bin laden' and foo.boolean = true order by foo.string asc, foo.component.count desc");
+ list = s.createQuery(
+ "from Foo foo where foo.string='osama bin laden' and foo.boolean = true order by foo.string asc, foo.component.count desc"
+ ).list();
assertTrue( "empty query", list.size()==0 );
- Iterator iter = s.iterate("from Foo foo where foo.string='osama bin laden' order by foo.string asc, foo.component.count desc");
+ Iterator iter = s.createQuery(
+ "from Foo foo where foo.string='osama bin laden' order by foo.string asc, foo.component.count desc"
+ ).iterate();
assertTrue( "empty iterator", !iter.hasNext() );
- list = s.find("select foo.foo from Foo foo");
+ list = s.createQuery( "select foo.foo from Foo foo" ).list();
assertTrue( "query", list.size()==1 );
assertTrue( "returned object", list.get(0)==foo.getFoo() );
foo.getFoo().setFoo(foo);
@@ -446,63 +462,85 @@
) {
// && !db.equals("weblogic") {
if ( !( getDialect() instanceof InterbaseDialect ) ) {
- list = s.find("from Foo foo where ? = some elements(foo.component.importantDates)", new Date(), Hibernate.DATE);
+ list = s.createQuery( "from Foo foo where ? = some elements(foo.component.importantDates)" )
+ .setParameter( 0, new Date(), Hibernate.DATE )
+ .list();
assertTrue( "component query", list.size()==2 );
}
if( !( getDialect() instanceof TimesTenDialect)) {
- list = s.find("from Foo foo where size(foo.component.importantDates) = 3"); //WAS: 4
+ list = s.createQuery( "from Foo foo where size(foo.component.importantDates) = 3" ).list(); //WAS: 4
assertTrue( "component query", list.size()==2 );
- list = s.find("from Foo foo where 0 = size(foo.component.importantDates)");
+ list = s.createQuery( "from Foo foo where 0 = size(foo.component.importantDates)" ).list();
assertTrue( "component query", list.size()==0 );
}
- list = s.find("from Foo foo where exists elements(foo.component.importantDates)");
+ list = s.createQuery( "from Foo foo where exists elements(foo.component.importantDates)" ).list();
assertTrue( "component query", list.size()==2 );
- s.find("from Foo foo where not exists (from Bar bar where bar.id = foo.id)");
+ s.createQuery( "from Foo foo where not exists (from Bar bar where bar.id = foo.id)" ).list();
- s.find("select foo.foo from Foo foo where foo = some(select x from Foo x where x.long > foo.foo.long)");
- s.find("select foo.foo from Foo foo where foo = some(from Foo x where (x.long > foo.foo.long))");
+ s.createQuery(
+ "select foo.foo from Foo foo where foo = some(select x from Foo x where x.long > foo.foo.long)"
+ ).list();
+ s.createQuery( "select foo.foo from Foo foo where foo = some(from Foo x where (x.long > foo.foo.long))" )
+ .list();
if ( !( getDialect() instanceof TimesTenDialect)) {
- s.find("select foo.foo from Foo foo where foo.long = some( select max(x.long) from Foo x where (x.long > foo.foo.long) group by x.foo )");
+ s.createQuery(
+ "select foo.foo from Foo foo where foo.long = some( select max(x.long) from Foo x where (x.long > foo.foo.long) group by x.foo )"
+ ).list();
}
- s.find("from Foo foo where foo = some(select x from Foo x where x.long > foo.foo.long) and foo.foo.string='baz'");
- s.find("from Foo foo where foo.foo.string='baz' and foo = some(select x from Foo x where x.long > foo.foo.long)");
- s.find("from Foo foo where foo = some(select x from Foo x where x.long > foo.foo.long)");
+ s.createQuery(
+ "from Foo foo where foo = some(select x from Foo x where x.long > foo.foo.long) and foo.foo.string='baz'"
+ ).list();
+ s.createQuery(
+ "from Foo foo where foo.foo.string='baz' and foo = some(select x from Foo x where x.long > foo.foo.long)"
+ ).list();
+ s.createQuery( "from Foo foo where foo = some(select x from Foo x where x.long > foo.foo.long)" ).list();
- s.iterate("select foo.string, foo.date, foo.foo.string, foo.id from Foo foo, Baz baz where foo in elements(baz.fooArray) and foo.string like 'foo'");
+ s.createQuery(
+ "select foo.string, foo.date, foo.foo.string, foo.id from Foo foo, Baz baz where foo in elements(baz.fooArray) and foo.string like 'foo'"
+ ).iterate();
}
- list = s.find("from Foo foo where foo.component.count is null order by foo.component.count");
+ list = s.createQuery( "from Foo foo where foo.component.count is null order by foo.component.count" ).list();
assertTrue( "component query", list.size()==0 );
- list = s.find("from Foo foo where foo.component.name='foo'");
+ list = s.createQuery( "from Foo foo where foo.component.name='foo'" ).list();
assertTrue( "component query", list.size()==2 );
- list = s.find("select distinct foo.component.name, foo.component.name from Foo foo where foo.component.name='foo'");
+ list = s.createQuery(
+ "select distinct foo.component.name, foo.component.name from Foo foo where foo.component.name='foo'"
+ ).list();
assertTrue( "component query", list.size()==1 );
- list = s.find("select distinct foo.component.name, foo.id from Foo foo where foo.component.name='foo'");
+ list = s.createQuery( "select distinct foo.component.name, foo.id from Foo foo where foo.component.name='foo'" )
+ .list();
assertTrue( "component query", list.size()==2 );
- list = s.find("select foo.foo from Foo foo");
+ list = s.createQuery( "select foo.foo from Foo foo" ).list();
assertTrue( "query", list.size()==2 );
- list = s.find("from Foo foo where foo.id=?", foo.getKey(), Hibernate.STRING);
+ list = s.createQuery( "from Foo foo where foo.id=?" )
+ .setParameter( 0, foo.getKey(), Hibernate.STRING )
+ .list();
assertTrue( "id query", list.size()==1 );
- list = s.find("from Foo foo where foo.key=?", foo.getKey(), Hibernate.STRING);
+ list = s.createQuery( "from Foo foo where foo.key=?" )
+ .setParameter( 0, foo.getKey(), Hibernate.STRING )
+ .list();
assertTrue( "named id query", list.size()==1 );
assertTrue( "id query", list.get(0)==foo );
- list = s.find("select foo.foo from Foo foo where foo.string='fizard'");
+ list = s.createQuery( "select foo.foo from Foo foo where foo.string='fizard'" ).list();
assertTrue( "query", list.size()==1 );
assertTrue( "returned object", list.get(0)==foo.getFoo() );
- list = s.find("from Foo foo where foo.component.subcomponent.name='bar'");
+ list = s.createQuery( "from Foo foo where foo.component.subcomponent.name='bar'" ).list();
assertTrue( "components of components", list.size()==2 );
- list = s.find("select foo.foo from Foo foo where foo.foo.id=?", foo.getFoo().getKey(), Hibernate.STRING);
+ list = s.createQuery( "select foo.foo from Foo foo where foo.foo.id=?" )
+ .setParameter( 0, foo.getFoo().getKey(), Hibernate.STRING )
+ .list();
assertTrue( "by id query", list.size()==1 );
assertTrue( "by id returned object", list.get(0)==foo.getFoo() );
- s.find( "from Foo foo where foo.foo = ?", foo.getFoo(), Hibernate.entity(Foo.class) );
+ s.createQuery( "from Foo foo where foo.foo = ?" ).setParameter( 0, foo.getFoo(), Hibernate.entity(Foo.class) ).list();
- assertTrue( !s.iterate("from Bar bar where bar.string='a string' or bar.string='a string'").hasNext() );
+ assertTrue( !s.createQuery( "from Bar bar where bar.string='a string' or bar.string='a string'" )
+ .iterate()
+ .hasNext() );
- iter = s.iterate(
- "select foo.component.name, elements(foo.component.importantDates) from Foo foo where foo.foo.id=?",
- foo.getFoo().getKey(),
- Hibernate.STRING
- );
+ iter = s.createQuery( "select foo.component.name, elements(foo.component.importantDates) from Foo foo where foo.foo.id=?" )
+ .setParameter( 0, foo.getFoo().getKey(), Hibernate.STRING )
+ .iterate();
int i=0;
while ( iter.hasNext() ) {
i++;
@@ -510,29 +548,28 @@
assertTrue( row[0] instanceof String && ( row[1]==null || row[1] instanceof Date ) );
}
assertTrue(i==3); //WAS: 4
- iter = s.iterate(
- "select max( elements(foo.component.importantDates) ) from Foo foo group by foo.id"
- );
+ iter = s.createQuery( "select max( elements(foo.component.importantDates) ) from Foo foo group by foo.id" )
+ .iterate();
assertTrue( iter.next() instanceof Date );
- list = s.find(
- "select foo.foo.foo.foo from Foo foo, Foo foo2 where"
- + " foo = foo2.foo and not not ( not foo.string='fizard' )"
- + " and foo2.string between 'a' and (foo.foo.string)"
- + ( ( getDialect() instanceof HSQLDialect || getDialect() instanceof InterbaseDialect || getDialect() instanceof TimesTenDialect)?
- " and ( foo2.string in ( 'fiz', 'blah') or 1=1 )"
- :
- " and ( foo2.string in ( 'fiz', 'blah', foo.foo.string, foo.string, foo2.string ) )"
- )
- );
+ list = s.createQuery(
+ "select foo.foo.foo.foo from Foo foo, Foo foo2 where"
+ + " foo = foo2.foo and not not ( not foo.string='fizard' )"
+ + " and foo2.string between 'a' and (foo.foo.string)"
+ + ( ( getDialect() instanceof HSQLDialect || getDialect() instanceof InterbaseDialect || getDialect() instanceof TimesTenDialect ) ?
+ " and ( foo2.string in ( 'fiz', 'blah') or 1=1 )"
+ :
+ " and ( foo2.string in ( 'fiz', 'blah', foo.foo.string, foo.string, foo2.string ) )"
+ )
+ ).list();
assertTrue( "complex query", list.size()==1 );
assertTrue( "returned object", list.get(0)==foo );
foo.setString("from BoogieDown -tinsel town =!@#$^&*())");
- list = s.find("from Foo foo where foo.string='from BoogieDown -tinsel town =!@#$^&*())'");
+ list = s.createQuery( "from Foo foo where foo.string='from BoogieDown -tinsel town =!@#$^&*())'" ).list();
assertTrue( "single quotes", list.size()==1 );
- list = s.find("from Foo foo where not foo.string='foo''bar'");
+ list = s.createQuery( "from Foo foo where not foo.string='foo''bar'" ).list();
assertTrue( "single quotes", list.size()==2 );
- list = s.find("from Foo foo where foo.component.glarch.next is null");
+ list = s.createQuery( "from Foo foo where foo.component.glarch.next is null" ).list();
assertTrue( "query association in component", list.size()==2 );
Bar bar = new Bar();
Baz baz = new Baz();
@@ -543,31 +580,37 @@
baz.getManyToAny().add(foo);
s.save(bar);
s.save(baz);
- list = s.find(" from Bar bar where bar.baz.count=667 and bar.baz.count!=123 and not bar.baz.name='1-E-1'");
+ list = s.createQuery(
+ " from Bar bar where bar.baz.count=667 and bar.baz.count!=123 and not bar.baz.name='1-E-1'"
+ ).list();
assertTrue( "query many-to-one", list.size()==1 );
- list = s.find(" from Bar i where i.baz.name='Bazza'");
+ list = s.createQuery( " from Bar i where i.baz.name='Bazza'" ).list();
assertTrue( "query many-to-one", list.size()==1 );
- Iterator rs = s.iterate("select count(distinct foo.foo) from Foo foo");
+ Iterator rs = s.createQuery( "select count(distinct foo.foo) from Foo foo" ).iterate();
assertTrue( "count", ( (Long) rs.next() ).longValue()==2 );
assertTrue( !rs.hasNext() );
- rs = s.iterate("select count(foo.foo.boolean) from Foo foo");
+ rs = s.createQuery( "select count(foo.foo.boolean) from Foo foo" ).iterate();
assertTrue( "count", ( (Long) rs.next() ).longValue()==2 );
assertTrue( !rs.hasNext() );
- rs = s.iterate("select count(*), foo.int from Foo foo group by foo.int");
+ rs = s.createQuery( "select count(*), foo.int from Foo foo group by foo.int" ).iterate();
assertTrue( "count(*) group by", ( (Object[]) rs.next() )[0].equals( new Long(3) ) );
assertTrue( !rs.hasNext() );
- rs = s.iterate("select sum(foo.foo.int) from Foo foo");
+ rs = s.createQuery( "select sum(foo.foo.int) from Foo foo" ).iterate();
assertTrue( "sum", ( (Long) rs.next() ).longValue()==4 );
assertTrue( !rs.hasNext() );
- rs = s.iterate("select count(foo) from Foo foo where foo.id=?", foo.getKey(), Hibernate.STRING);
+ rs = s.createQuery( "select count(foo) from Foo foo where foo.id=?" )
+ .setParameter( 0, foo.getKey(), Hibernate.STRING )
+ .iterate();
assertTrue( "id query count", ( (Long) rs.next() ).longValue()==1 );
assertTrue( !rs.hasNext() );
- list = s.find( "from Foo foo where foo.boolean = ?", new Boolean(true), Hibernate.BOOLEAN );
+ s.createQuery( "from Foo foo where foo.boolean = ?" )
+ .setParameter( 0, new Boolean(true), Hibernate.BOOLEAN )
+ .list();
- list = s.find("select new Foo(fo.x) from Fo fo");
- list = s.find("select new Foo(fo.integer) from Foo fo");
+ s.createQuery( "select new Foo(fo.x) from Fo fo" ).list();
+ s.createQuery( "select new Foo(fo.integer) from Foo fo" ).list();
list = s.createQuery("select new Foo(fo.x) from Foo fo")
//.setComment("projection test")
@@ -580,7 +623,7 @@
.list();
assertTrue(list.size()==3);
- rs = s.iterate("select new Foo(fo.x) from Foo fo");
+ rs = s.createQuery( "select new Foo(fo.x) from Foo fo" ).iterate();
assertTrue( "projection iterate (results)", rs.hasNext() );
assertTrue( "projection iterate (return check)", Foo.class.isAssignableFrom( rs.next().getClass() ) );
@@ -588,7 +631,7 @@
assertTrue( "projection scroll (results)", sr.next() );
assertTrue( "projection scroll (return check)", Foo.class.isAssignableFrom( sr.get(0).getClass() ) );
- list = s.find("select foo.long, foo.component.name, foo, foo.foo from Foo foo");
+ list = s.createQuery( "select foo.long, foo.component.name, foo, foo.foo from Foo foo" ).list();
rs = list.iterator();
int count=0;
while ( rs.hasNext() ) {
@@ -600,7 +643,8 @@
assertTrue( row[3] instanceof Foo );
}
assertTrue(count!=0);
- list = s.find("select avg(foo.float), max(foo.component.name), count(distinct foo.id) from Foo foo");
+ list = s.createQuery( "select avg(foo.float), max(foo.component.name), count(distinct foo.id) from Foo foo" )
+ .list();
rs = list.iterator();
count=0;
while ( rs.hasNext() ) {
@@ -611,7 +655,7 @@
assertTrue( row[2] instanceof Long );
}
assertTrue(count!=0);
- list = s.find("select foo.long, foo.component, foo, foo.foo from Foo foo");
+ list = s.createQuery( "select foo.long, foo.component, foo, foo.foo from Foo foo" ).list();
rs = list.iterator();
count=0;
while ( rs.hasNext() ) {
@@ -627,16 +671,16 @@
s.save( new Holder("ice T") );
s.save( new Holder("ice cube") );
- assertTrue( s.find("from java.lang.Object as o").size()==15 );
- assertTrue( s.find("from Named").size()==7 );
- assertTrue( s.find("from Named n where n.name is not null").size()==4 );
- iter = s.iterate("from Named n");
+ assertTrue( s.createQuery( "from java.lang.Object as o" ).list().size()==15 );
+ assertTrue( s.createQuery( "from Named" ).list().size()==7 );
+ assertTrue( s.createQuery( "from Named n where n.name is not null" ).list().size()==4 );
+ iter = s.createQuery( "from Named n" ).iterate();
while ( iter.hasNext() ) {
assertTrue( iter.next() instanceof Named );
}
s.save( new Holder("bar") );
- iter = s.iterate("from Named n0, Named n1 where n0.name = n1.name");
+ iter = s.createQuery( "from Named n0, Named n1 where n0.name = n1.name" ).iterate();
int cnt = 0;
while ( iter.hasNext() ) {
Object[] row = (Object[]) iter.next();
@@ -644,14 +688,14 @@
}
if ( !(getDialect() instanceof HSQLDialect) ) {
assertTrue(cnt==2);
- assertTrue( s.find("from Named n0, Named n1 where n0.name = n1.name").size()==7 );
+ assertTrue( s.createQuery( "from Named n0, Named n1 where n0.name = n1.name" ).list().size()==7 );
}
Query qu = s.createQuery("from Named n where n.name = :name");
qu.getReturnTypes();
qu.getNamedParameters();
- iter = s.iterate("from java.lang.Object");
+ iter = s.createQuery( "from java.lang.Object" ).iterate();
int c = 0;
while ( iter.hasNext() ) {
iter.next();
@@ -659,46 +703,65 @@
}
assertTrue(c==16);
- s.iterate("select baz.code, min(baz.count) from Baz baz group by baz.code");
+ s.createQuery( "select baz.code, min(baz.count) from Baz baz group by baz.code" ).iterate();
- iter = s.iterate("selecT baz from Baz baz where baz.stringDateMap['foo'] is not null or baz.stringDateMap['bar'] = ?", new Date(), Hibernate.DATE);
+ iter = s.createQuery( "selecT baz from Baz baz where baz.stringDateMap['foo'] is not null or baz.stringDateMap['bar'] = ?" )
+ .setParameter( 0, new Date(), Hibernate.DATE )
+ .iterate();
assertFalse( iter.hasNext() );
- list = s.find("select baz from Baz baz where baz.stringDateMap['now'] is not null");
+ list = s.createQuery( "select baz from Baz baz where baz.stringDateMap['now'] is not null" ).list();
assertTrue( list.size()==1 );
- list = s.find("select baz from Baz baz where baz.stringDateMap['now'] is not null and baz.stringDateMap['big bang'] < baz.stringDateMap['now']");
+ list = s.createQuery(
+ "select baz from Baz baz where baz.stringDateMap['now'] is not null and baz.stringDateMap['big bang'] < baz.stringDateMap['now']"
+ ).list();
assertTrue( list.size()==1 );
- list = s.find("select index(date) from Baz baz join baz.stringDateMap date");
+ list = s.createQuery( "select index(date) from Baz baz join baz.stringDateMap date" ).list();
System.out.println(list);
assertTrue( list.size()==2 );
- s.find("from Foo foo where foo.integer not between 1 and 5 and foo.string not in ('cde', 'abc') and foo.string is not null and foo.integer<=3");
+ s.createQuery(
+ "from Foo foo where foo.integer not between 1 and 5 and foo.string not in ('cde', 'abc') and foo.string is not null and foo.integer<=3"
+ ).list();
- s.find("from Baz baz inner join baz.collectionComponent.nested.foos foo where foo.string is null");
+ s.createQuery( "from Baz baz inner join baz.collectionComponent.nested.foos foo where foo.string is null" )
+ .list();
if ( !(getDialect() instanceof MySQLDialect) && !(getDialect() instanceof MckoiDialect) && !(getDialect() instanceof SAPDBDialect) && !(getDialect() instanceof PointbaseDialect) ) {
- s.find("from Baz baz inner join baz.fooSet where '1' in (from baz.fooSet foo where foo.string is not null)");
- s.find("from Baz baz where 'a' in elements(baz.collectionComponent.nested.foos) and 1.0 in elements(baz.collectionComponent.nested.floats)");
- s.find("from Baz baz where 'b' in elements(baz.collectionComponent.nested.foos) and 1.0 in elements(baz.collectionComponent.nested.floats)");
+ s.createQuery(
+ "from Baz baz inner join baz.fooSet where '1' in (from baz.fooSet foo where foo.string is not null)"
+ ).list();
+ s.createQuery(
+ "from Baz baz where 'a' in elements(baz.collectionComponent.nested.foos) and 1.0 in elements(baz.collectionComponent.nested.floats)"
+ ).list();
+ s.createQuery(
+ "from Baz baz where 'b' in elements(baz.collectionComponent.nested.foos) and 1.0 in elements(baz.collectionComponent.nested.floats)"
+ ).list();
}
- s.find("from Foo foo join foo.foo where foo.foo in ('1','2','3')");
- if ( !(getDialect() instanceof HSQLDialect) ) s.find("from Foo foo left join foo.foo where foo.foo in ('1','2','3')");
- s.find("select foo.foo from Foo foo where foo.foo in ('1','2','3')");
- s.find("select foo.foo.string from Foo foo where foo.foo in ('1','2','3')");
- s.find("select foo.foo.string from Foo foo where foo.foo.string in ('1','2','3')");
- s.find("select foo.foo.long from Foo foo where foo.foo.string in ('1','2','3')");
- s.find("select count(*) from Foo foo where foo.foo.string in ('1','2','3') or foo.foo.long in (1,2,3)");
- s.find("select count(*) from Foo foo where foo.foo.string in ('1','2','3') group by foo.foo.long");
+ s.createQuery( "from Foo foo join foo.foo where foo.foo in ('1','2','3')" ).list();
+ if ( !(getDialect() instanceof HSQLDialect) )
+ s.createQuery( "from Foo foo left join foo.foo where foo.foo in ('1','2','3')" ).list();
+ s.createQuery( "select foo.foo from Foo foo where foo.foo in ('1','2','3')" ).list();
+ s.createQuery( "select foo.foo.string from Foo foo where foo.foo in ('1','2','3')" ).list();
+ s.createQuery( "select foo.foo.string from Foo foo where foo.foo.string in ('1','2','3')" ).list();
+ s.createQuery( "select foo.foo.long from Foo foo where foo.foo.string in ('1','2','3')" ).list();
+ s.createQuery( "select count(*) from Foo foo where foo.foo.string in ('1','2','3') or foo.foo.long in (1,2,3)" )
+ .list();
+ s.createQuery( "select count(*) from Foo foo where foo.foo.string in ('1','2','3') group by foo.foo.long" )
+ .list();
- s.find("from Foo foo1 left join foo1.foo foo2 left join foo2.foo where foo1.string is not null");
- s.find("from Foo foo1 left join foo1.foo.foo where foo1.string is not null");
- s.find("from Foo foo1 left join foo1.foo foo2 left join foo1.foo.foo foo3 where foo1.string is not null");
+ s.createQuery( "from Foo foo1 left join foo1.foo foo2 left join foo2.foo where foo1.string is not null" )
+ .list();
+ s.createQuery( "from Foo foo1 left join foo1.foo.foo where foo1.string is not null" ).list();
+ s.createQuery( "from Foo foo1 left join foo1.foo foo2 left join foo1.foo.foo foo3 where foo1.string is not null" )
+ .list();
- s.find("select foo.formula from Foo foo where foo.formula > 0");
+ s.createQuery( "select foo.formula from Foo foo where foo.formula > 0" ).list();
- int len = s.find("from Foo as foo join foo.foo as foo2 where foo2.id >'a' or foo2.id <'a'").size();
+ int len = s.createQuery( "from Foo as foo join foo.foo as foo2 where foo2.id >'a' or foo2.id <'a'" ).list().size();
assertTrue(len==2);
s.delete("from Holder");
+
txn.commit();
s.close();
@@ -708,22 +771,31 @@
assertTrue( Hibernate.isInitialized( baz.getManyToAny() ) );
assertTrue( baz.getManyToAny().size()==2 );
BarProxy barp = (BarProxy) baz.getManyToAny().get(0);
- s.find("from Baz baz join baz.manyToAny");
- assertTrue( s.find("select baz from Baz baz join baz.manyToAny a where index(a) = 0").size()==1 );
+ s.createQuery( "from Baz baz join baz.manyToAny" ).list();
+ assertTrue( s.createQuery( "select baz from Baz baz join baz.manyToAny a where index(a) = 0" ).list().size()==1 );
FooProxy foop = (FooProxy) s.get( Foo.class, foo.getKey() );
assertTrue( foop == baz.getManyToAny().get(1) );
barp.setBaz(baz);
- assertTrue( s.find("select bar from Bar bar where bar.baz.stringDateMap['now'] is not null").size()==1 );
- assertTrue( s.find("select bar from Bar bar join bar.baz b where b.stringDateMap['big bang'] < b.stringDateMap['now'] and b.stringDateMap['now'] is not null").size()==1 );
- assertTrue( s.find("select bar from Bar bar where bar.baz.stringDateMap['big bang'] < bar.baz.stringDateMap['now'] and bar.baz.stringDateMap['now'] is not null").size()==1 );
+ assertTrue(
+ s.createQuery( "select bar from Bar bar where bar.baz.stringDateMap['now'] is not null" ).list().size()==1 );
+ assertTrue(
+ s.createQuery(
+ "select bar from Bar bar join bar.baz b where b.stringDateMap['big bang'] < b.stringDateMap['now'] and b.stringDateMap['now'] is not null"
+ ).list()
+ .size()==1 );
+ assertTrue(
+ s.createQuery(
+ "select bar from Bar bar where bar.baz.stringDateMap['big bang'] < bar.baz.stringDateMap['now'] and bar.baz.stringDateMap['now'] is not null"
+ ).list()
+ .size()==1 );
- list = s.find("select foo.string, foo.component, foo.id from Bar foo");
+ list = s.createQuery( "select foo.string, foo.component, foo.id from Bar foo" ).list();
assertTrue ( ( (FooComponent) ( (Object[]) list.get(0) )[1] ).getName().equals("foo") );
- list = s.find("select elements(baz.components) from Baz baz");
+ list = s.createQuery( "select elements(baz.components) from Baz baz" ).list();
assertTrue( list.size()==2 );
- list = s.find("select bc.name from Baz baz join baz.components bc");
+ list = s.createQuery( "select bc.name from Baz baz join baz.components bc" ).list();
assertTrue( list.size()==2 );
//list = s.find("select bc from Baz baz join baz.components bc");
@@ -739,59 +811,64 @@
public void testCascadeDeleteDetached() throws Exception {
Session s = openSession();
+ s.beginTransaction();
Baz baz = new Baz();
List list = new ArrayList();
list.add( new Fee() );
baz.setFees(list);
s.save(baz);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
s = openSession();
+ s.beginTransaction();
baz = (Baz) s.get( Baz.class, baz.getCode() );
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
assertFalse( Hibernate.isInitialized( baz.getFees() ) );
s = openSession();
+ s.beginTransaction();
s.delete(baz);
s.flush();
- assertFalse( s.iterate("from Fee").hasNext() );
- s.connection().commit();
+ assertFalse( s.createQuery( "from Fee" ).iterate().hasNext() );
+ s.getTransaction().commit();
s.close();
s = openSession();
+ s.beginTransaction();
baz = new Baz();
list = new ArrayList();
list.add( new Fee() );
list.add( new Fee() );
baz.setFees(list);
s.save(baz);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
s = openSession();
+ s.beginTransaction();
baz = (Baz) s.get( Baz.class, baz.getCode() );
Hibernate.initialize( baz.getFees() );
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
assertTrue( baz.getFees().size()==2 );
s = openSession();
+ s.beginTransaction();
s.delete(baz);
s.flush();
- assertFalse( s.iterate("from Fee").hasNext() );
- s.connection().commit();
+ assertFalse( s.createQuery( "from Fee" ).iterate().hasNext() );
+ s.getTransaction().commit();
s.close();
}
public void testForeignKeys() throws Exception {
Session s = openSession();
+ s.beginTransaction();
Baz baz = new Baz();
Foo foo = new Foo();
List bag = new ArrayList();
@@ -799,44 +876,44 @@
baz.setIdFooBag(bag);
baz.setFoo(foo);
s.save(baz);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
s = openSession();
+ s.beginTransaction();
baz = (Baz) s.load( Baz.class, baz.getCode() );
s.delete(baz);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
}
public void testNonlazyCollection() throws Exception {
Session s = openSession();
+ s.beginTransaction();
Baz baz = new Baz();
s.save(baz);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
s = openSession();
+ s.beginTransaction();
baz = (Baz) s.createCriteria(Baz.class)
//.setComment("criteria test")
- .setFetchMode("stringDateMap", FetchMode.EAGER)
+ .setFetchMode( "stringDateMap", FetchMode.JOIN )
.uniqueResult();
assertTrue( Hibernate.isInitialized( baz.getFooToGlarch() ) );
assertTrue( Hibernate.isInitialized( baz.getFooComponentToFoo() ) );
assertTrue( !Hibernate.isInitialized( baz.getStringSet() ) );
assertTrue( Hibernate.isInitialized( baz.getStringDateMap() ) );
s.delete(baz);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
}
public void testReuseDeletedCollection() throws Exception {
Session s = openSession();
+ s.beginTransaction();
Baz baz = new Baz();
baz.setDefaults();
s.save(baz);
@@ -845,8 +922,7 @@
Baz baz2 = new Baz();
baz2.setStringArray( new String[] {"x-y-z"} );
s.save(baz2);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
baz2.setStringSet( baz.getStringSet() );
@@ -854,18 +930,18 @@
baz2.setFooArray( baz.getFooArray() );
s = openSession();
+ s.beginTransaction();
s.update(baz2);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
s = openSession();
+ s.beginTransaction();
baz2 = (Baz) s.load( Baz.class, baz2.getCode() );
assertTrue( baz2.getStringArray().length==3 );
assertTrue( baz2.getStringSet().size()==3 );
s.delete(baz2);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
@@ -873,6 +949,7 @@
public void testPropertyRef() throws Exception {
Session s = openSession();
+ s.beginTransaction();
Holder h = new Holder();
h.setName("foo");
Holder h2 = new Holder();
@@ -882,27 +959,29 @@
Qux q = new Qux();
q.setHolder(h2);
Serializable qid = s.save(q);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
s = openSession();
+ s.beginTransaction();
h = (Holder) s.load(Holder.class, hid);
assertEquals( h.getName(), "foo");
assertEquals( h.getOtherHolder().getName(), "bar");
- Object[] res = (Object[]) s.find("from Holder h join h.otherHolder oh where h.otherHolder.name = 'bar'").get(0);
+ Object[] res = (Object[]) s.createQuery( "from Holder h join h.otherHolder oh where h.otherHolder.name = 'bar'" )
+ .list()
+ .get(0);
assertTrue( res[0]==h );
q = (Qux) s.get(Qux.class, qid);
assertTrue( q.getHolder() == h.getOtherHolder() );
s.delete(h);
s.delete(q);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
}
public void testQueryCollectionOfValues() throws Exception {
Session s = openSession();
+ s.beginTransaction();
Baz baz = new Baz();
baz.setDefaults();
s.save(baz);
@@ -910,48 +989,41 @@
Serializable gid = s.save(g);
if ( !(getDialect() instanceof MySQLDialect) && !(getDialect() instanceof HSQLDialect) /*&& !(dialect instanceof MckoiDialect)*/ && !(getDialect() instanceof SAPDBDialect) && !(getDialect() instanceof PointbaseDialect) && !(getDialect() instanceof TimesTenDialect) ) {
- s.filter( baz.getFooArray(), "where size(this.bytes) > 0");
- s.filter( baz.getFooArray(), "where 0 in elements(this.bytes)");
+ s.createFilter( baz.getFooArray(), "where size(this.bytes) > 0" ).list();
+ s.createFilter( baz.getFooArray(), "where 0 in elements(this.bytes)" ).list();
}
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
s = openSession();
- //s.find("from Baz baz where baz.fooSet.string = 'foo'");
- //s.find("from Baz baz where baz.fooArray.string = 'foo'");
- //s.find("from Baz baz where baz.fooSet.foo.string = 'foo'");
- //s.find("from Baz baz join baz.fooSet.foo foo where foo.string = 'foo'");
- s.find("from Baz baz join baz.fooSet foo join foo.foo.foo foo2 where foo2.string = 'foo'");
- s.find("from Baz baz join baz.fooArray foo join foo.foo.foo foo2 where foo2.string = 'foo'");
- s.find("from Baz baz join baz.stringDateMap date where index(date) = 'foo'");
- s.find("from Baz baz join baz.topGlarchez g where index(g) = 'A'");
- s.find("select index(g) from Baz baz join baz.topGlarchez g");
+ s.beginTransaction();
+ s.createQuery( "from Baz baz join baz.fooSet foo join foo.foo.foo foo2 where foo2.string = 'foo'" ).list();
+ s.createQuery( "from Baz baz join baz.fooArray foo join foo.foo.foo foo2 where foo2.string = 'foo'" ).list();
+ s.createQuery( "from Baz baz join baz.stringDateMap date where index(date) = 'foo'" ).list();
+ s.createQuery( "from Baz baz join baz.topGlarchez g where index(g) = 'A'" ).list();
+ s.createQuery( "select index(g) from Baz baz join baz.topGlarchez g" ).list();
- assertTrue( s.find("from Baz baz left join baz.stringSet").size()==3 );
- baz = (Baz) s.find("from Baz baz join baz.stringSet str where str='foo'").get(0);
+ assertTrue( s.createQuery( "from Baz baz left join baz.stringSet" ).list().size()==3 );
+ baz = (Baz) s.createQuery( "from Baz baz join baz.stringSet str where str='foo'" ).list().get(0);
assertTrue( !Hibernate.isInitialized( baz.getStringSet() ) );
- baz = (Baz) s.find("from Baz baz left join fetch baz.stringSet").get(0);
+ baz = (Baz) s.createQuery( "from Baz baz left join fetch baz.stringSet" ).list().get(0);
assertTrue( Hibernate.isInitialized( baz.getStringSet() ) );
- assertTrue( s.find("from Baz baz join baz.stringSet string where string='foo'").size()==1 );
- assertTrue( s.find("from Baz baz inner join baz.components comp where comp.name='foo'").size()==1 );
+ assertTrue( s.createQuery( "from Baz baz join baz.stringSet string where string='foo'" ).list().size()==1 );
+ assertTrue( s.createQuery( "from Baz baz inner join baz.components comp where comp.name='foo'" ).list().size()==1 );
//List bss = s.find("select baz, ss from Baz baz inner join baz.stringSet ss");
- s.find("from Glarch g inner join g.fooComponents comp where comp.fee is not null");
- s.find("from Glarch g inner join g.fooComponents comp join comp.fee fee where fee.count > 0");
- s.find("from Glarch g inner join g.fooComponents comp where comp.fee.count is not null");
+ s.createQuery( "from Glarch g inner join g.fooComponents comp where comp.fee is not null" ).list();
+ s.createQuery( "from Glarch g inner join g.fooComponents comp join comp.fee fee where fee.count > 0" ).list();
+ s.createQuery( "from Glarch g inner join g.fooComponents comp where comp.fee.count is not null" ).list();
s.delete(baz);
- //s.delete("from Glarch g");
s.delete( s.get(Glarch.class, gid) );
- s.flush();
-
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
-
}
public void testBatchLoad() throws Exception {
Session s = openSession();
+ s.beginTransaction();
Baz baz = new Baz();
SortedSet stringSet = new TreeSet();
stringSet.add("foo");
@@ -980,11 +1052,11 @@
stringSet.add("baz");
baz3.setStringSet(stringSet);
s.save(baz3);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
s = openSession();
+ s.beginTransaction();
baz = (Baz) s.load( Baz.class, baz.getCode() );
baz2 = (Baz) s.load( Baz.class, baz2.getCode() );
baz3 = (Baz) s.load( Baz.class, baz3.getCode() );
@@ -1001,14 +1073,14 @@
s.delete(baz3);
Iterator iter = new JoinedIterator( new Iterator[] { baz.getFooSet().iterator(), baz2.getFooSet().iterator() } );
while ( iter.hasNext() ) s.delete( iter.next() );
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
}
public void testFetchInitializedCollection() throws Exception {
Session s = openSession();
+ s.beginTransaction();
Baz baz = new Baz();
Collection fooBag = new ArrayList();
fooBag.add( new Foo() );
@@ -1017,26 +1089,27 @@
s.save(baz);
s.flush();
fooBag = baz.getFooBag();
- s.find("from Baz baz left join fetch baz.fooBag");
+ s.createQuery( "from Baz baz left join fetch baz.fooBag" ).list();
assertTrue( fooBag==baz.getFooBag() );
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
s = openSession();
+ s.beginTransaction();
baz = (Baz) s.load( Baz.class, baz.getCode() );
Object bag = baz.getFooBag();
assertFalse( Hibernate.isInitialized(bag) );
- s.find("from Baz baz left join fetch baz.fooBag");
+ s.createQuery( "from Baz baz left join fetch baz.fooBag" ).list();
assertTrue( bag==baz.getFooBag() );
assertTrue( baz.getFooBag().size()==2 );
s.delete(baz);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
}
public void testLateCollectionAdd() throws Exception {
Session s = openSession();
+ s.beginTransaction();
Baz baz = new Baz();
List l = new ArrayList();
baz.setStringList(l);
@@ -1045,70 +1118,69 @@
l.add("bar");
s.flush();
l.add("baz");
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
s = openSession();
+ s.beginTransaction();
baz = (Baz) s.load(Baz.class, id);
assertTrue( baz.getStringList().size()==3 && baz.getStringList().contains("bar") );
s.delete(baz);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
}
public void testUpdate() throws Exception {
Session s = openSession();
+ s.beginTransaction();
Foo foo = new Foo();
s.save(foo);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
foo = (Foo) SerializationHelper.deserialize( SerializationHelper.serialize(foo) );
s = openSession();
+ s.beginTransaction();
FooProxy foo2 = (FooProxy) s.load( Foo.class, foo.getKey() );
foo2.setString("dirty");
foo2.setBoolean( new Boolean(false) );
foo2.setBytes( new byte[] { 1,2,3} );
foo2.setDate(null);
foo2.setShort( new Short("69") );
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
s = openSession();
+ s.beginTransaction();
foo2.setString("dirty again");
s.update(foo2);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
s = openSession();
+ s.beginTransaction();
foo2.setString("dirty again 2");
s.update(foo2);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
s = openSession();
+ s.beginTransaction();
Foo foo3 = new Foo();
s.load( foo3, foo.getKey() );
// There is an interbase bug that causes null integers to return as 0, also numeric precision is <= 15
assertTrue( "update", foo2.equalsFoo(foo3) );
s.delete(foo3);
- s.delete("from Glarch");
- s.flush();
- s.connection().commit();
+ doDelete( s, "from Glarch" );
+ s.getTransaction().commit();
s.close();
-
}
public void testListRemove() throws Exception {
Session s = openSession();
+ s.beginTransaction();
Baz b = new Baz();
List stringList = new ArrayList();
List feeList = new ArrayList();
@@ -1137,14 +1209,14 @@
"foo".equals( stringList.get(0) )
);
s.delete(b);
- s.delete("from Fee");
- s.flush();
- s.connection().commit();
+ doDelete( s, "from Fee" );
+ s.getTransaction().commit();
s.close();
}
public void testFetchInitializedCollectionDupe() throws Exception {
Session s = openSession();
+ s.beginTransaction();
Baz baz = new Baz();
Collection fooBag = new ArrayList();
fooBag.add( new Foo() );
@@ -1153,29 +1225,30 @@
s.save(baz);
s.flush();
fooBag = baz.getFooBag();
- s.find("from Baz baz left join fetch baz.fooBag");
+ s.createQuery( "from Baz baz left join fetch baz.fooBag" ).list();
assertTrue( Hibernate.isInitialized(fooBag) );
assertTrue( fooBag==baz.getFooBag() );
assertTrue( baz.getFooBag().size()==2 );
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
s = openSession();
+ s.beginTransaction();
baz = (Baz) s.load( Baz.class, baz.getCode() );
Object bag = baz.getFooBag();
assertFalse( Hibernate.isInitialized(bag) );
- s.find("from Baz baz left join fetch baz.fooBag");
+ s.createQuery( "from Baz baz left join fetch baz.fooBag" ).list();
assertTrue( Hibernate.isInitialized(bag) );
assertTrue( bag==baz.getFooBag() );
assertTrue( baz.getFooBag().size()==2 );
s.delete(baz);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
}
public void testSortables() throws Exception {
Session s = openSession();
+ s.beginTransaction();
Baz b = new Baz();
b.setName("name");
SortedSet ss = new TreeSet();
@@ -1184,13 +1257,13 @@
ss.add( new Sortable("baz") );
b.setSortablez(ss);
s.save(b);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
s = openSession();
+ s.beginTransaction();
Criteria cr = s.createCriteria(Baz.class);
- cr.setFetchMode("topGlarchez", FetchMode.LAZY);
+ cr.setFetchMode( "topGlarchez", FetchMode.SELECT );
List result = cr
.addOrder( Order.asc("name") )
.list();
@@ -1198,33 +1271,35 @@
b = (Baz) result.get(0);
assertTrue( b.getSortablez().size()==3 );
assertEquals( ( (Sortable) b.getSortablez().iterator().next() ).getName(), "bar" );
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
s = openSession();
+ s.beginTransaction();
result = s.createQuery("from Baz baz left join fetch baz.sortablez order by baz.name asc")
.list();
b = (Baz) result.get(0);
assertTrue( b.getSortablez().size()==3 );
assertEquals( ( (Sortable) b.getSortablez().iterator().next() ).getName(), "bar" );
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
s = openSession();
+ s.beginTransaction();
result = s.createQuery("from Baz baz order by baz.name asc")
.list();
b = (Baz) result.get(0);
assertTrue( b.getSortablez().size()==3 );
assertEquals( ( (Sortable) b.getSortablez().iterator().next() ).getName(), "bar" );
s.delete(b);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
}
public void testFetchList() throws Exception {
Session s = openSession();
+ s.beginTransaction();
Baz baz = new Baz();
s.save(baz);
Foo foo = new Foo();
@@ -1238,18 +1313,18 @@
list.add(fee);
}
baz.setFees(list);
- list = s.find("from Foo foo, Baz baz left join fetch baz.fees");
+ list = s.createQuery( "from Foo foo, Baz baz left join fetch baz.fees" ).list();
assertTrue( Hibernate.isInitialized( ( (Baz) ( (Object[]) list.get(0) )[1] ).getFees() ) );
s.delete(foo);
s.delete(foo2);
s.delete(baz);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
}
public void testBagOneToMany() throws Exception {
Session s = openSession();
+ s.beginTransaction();
Baz baz = new Baz();
List list = new ArrayList();
baz.setBazez(list);
@@ -1263,13 +1338,11 @@
s.delete( list.remove(1) );
s.flush();
s.delete(baz);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
}
public void testQueryLockMode() throws Exception {
-
Session s = openSession();
Transaction tx = s.beginTransaction();
Bar bar = new Bar();
@@ -1292,7 +1365,7 @@
s.reconnect();
tx = s.beginTransaction();
assertTrue( s.getCurrentLockMode(b)==LockMode.NONE );
- s.find("from Foo foo");
+ s.createQuery( "from Foo foo" ).list();
assertTrue( s.getCurrentLockMode(b)==LockMode.NONE );
q = s.createQuery("from Foo foo");
q.setLockMode("foo", LockMode.READ);
@@ -1327,34 +1400,34 @@
}
public void testManyToManyBag() throws Exception {
-
Session s = openSession();
+ s.beginTransaction();
Baz baz = new Baz();
Serializable id = s.save(baz);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
s = openSession();
+ s.beginTransaction();
baz = (Baz) s.load(Baz.class, id);
baz.getFooBag().add( new Foo() );
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
s = openSession();
+ s.beginTransaction();
baz = (Baz) s.load(Baz.class, id);
assertTrue( !Hibernate.isInitialized( baz.getFooBag() ) );
assertTrue( baz.getFooBag().size()==1 );
if ( !(getDialect() instanceof HSQLDialect) ) assertTrue( Hibernate.isInitialized( baz.getFooBag().iterator().next() ) );
s.delete(baz);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
}
public void testIdBag() throws Exception {
Session s = openSession();
+ s.beginTransaction();
Baz baz = new Baz();
s.save(baz);
List l = new ArrayList();
@@ -1373,11 +1446,11 @@
s.flush();
s.delete( l.remove(3) );
bytes[1]='o';
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
s = openSession();
+ s.beginTransaction();
baz = (Baz) s.load(Baz.class, baz.getCode());
assertTrue( baz.getIdFooBag().size()==3 );
assertTrue( baz.getByteBag().size()==3 );
@@ -1388,11 +1461,11 @@
baz.getByteBag().add(bytes);
baz.getByteBag().add(bytes);
assertTrue( baz.getByteBag().size()==5 );
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
s = openSession();
+ s.beginTransaction();
baz = (Baz) s.load(Baz.class, baz.getCode());
assertTrue( baz.getIdFooBag().size()==0 );
assertTrue( baz.getByteBag().size()==5 );
@@ -1400,17 +1473,16 @@
iter = baz.getByteBag().iterator();
iter.next();
iter.remove();
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
s = openSession();
+ s.beginTransaction();
baz = (Baz) s.load(Baz.class, baz.getCode());
assertTrue( baz.getIdFooBag().size()==1 );
assertTrue( baz.getByteBag().size()==4 );
s.delete(baz);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
}
@@ -1419,10 +1491,12 @@
}
public void testForceOuterJoin() throws Exception {
+ if ( isOuterJoinFetchingDisabled() ) {
+ return;
+ }
- if ( isOuterJoinFetchingDisabled() ) return;
-
Session s = openSession();
+ s.beginTransaction();
Glarch g = new Glarch();
FooComponent fc = new FooComponent();
fc.setGlarch(g);
@@ -1433,13 +1507,13 @@
s.save(f2);
Serializable id = s.save(f);
Serializable gid = s.getIdentifier( f.getComponent().getGlarch() );
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
getSessions().evict(Foo.class);
s = openSession();
+ s.beginTransaction();
f = (FooProxy) s.load(Foo.class, id);
assertFalse( Hibernate.isInitialized(f) );
assertTrue( Hibernate.isInitialized( f.getComponent().getGlarch() ) ); //outer-join="true"
@@ -1447,18 +1521,19 @@
assertEquals( s.getIdentifier( f.getComponent().getGlarch() ), gid );
s.delete(f);
s.delete( f.getFoo() );
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
}
public void testEmptyCollection() throws Exception {
Session s = openSession();
+ s.beginTransaction();
Serializable id = s.save( new Baz() );
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
+
s = openSession();
+ s.beginTransaction();
Baz baz = (Baz) s.load(Baz.class, id);
Set foos = baz.getFooSet();
assertTrue( foos.size()==0 );
@@ -1468,13 +1543,13 @@
s.flush();
s.delete(foo);
s.delete(baz);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
}
public void testOneToOneGenerator() throws Exception {
Session s = openSession();
+ s.beginTransaction();
X x = new X();
Y y = new Y();
x.setY(y);
@@ -1485,11 +1560,12 @@
assertEquals( id, s.save(x) );
s.flush();
assertTrue( s.contains(y) && s.contains(x) );
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
assertEquals( new Long(x.getId()), y.getId() );
s = openSession();
+ s.beginTransaction();
x = new X();
y = new Y();
x.setY(y);
@@ -1498,11 +1574,12 @@
s.save(y);
s.flush();
assertTrue( s.contains(y) && s.contains(x) );
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
assertEquals( new Long(x.getId()), y.getId() );
s = openSession();
+ s.beginTransaction();
x = new X();
y = new Y();
x.setY(y);
@@ -1514,9 +1591,8 @@
assertEquals( id, new Long( x.getId() ) );
s.flush();
assertTrue( s.contains(y) && s.contains(x) );
- s.delete("from X x");
- s.flush();
- s.connection().commit();
+ doDelete( s, "from X x" );
+ s.getTransaction().commit();
s.close();
}
@@ -1556,7 +1632,7 @@
count++;
}
assertTrue(count==3);
- assertTrue( s.delete("from Foo foo")==10 );
+ assertEquals( 10, doDelete( s, "from Foo foo" ) );
txn.commit();
s.close();
}
@@ -1567,39 +1643,43 @@
m.count = 12;
m.glarch = (Glarch) g;
g.setMultiple(m);
+
Session s = openSession();
+ s.beginTransaction();
Serializable gid = s.save(g);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
s = openSession();
- g = (Glarch) s.find("from Glarch g where g.multiple.count=12").get(0);
- s.connection().commit();
+ s.beginTransaction();
+ //g = (Glarch) s.createQuery( "from Glarch g where g.multiple.count=12" ).list().get(0);
+ s.createQuery( "from Glarch g where g.multiple.count=12" ).list().get(0);
+ s.getTransaction().commit();
s.close();
s = openSession();
- g = (Glarch) s.find("from Glarch g where g.multiple.glarch=g and g.multiple.count=12").get(0);
+ s.beginTransaction();
+ g = (Glarch) s.createQuery( "from Glarch g where g.multiple.glarch=g and g.multiple.count=12" ).list().get(0);
assertTrue( g.getMultiple()!=null );
assertEquals( g.getMultiple().count, 12 );
assertSame(g.getMultiple().glarch, g);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
s = openSession();
+ s.beginTransaction();
g = (GlarchProxy) s.load(Glarch.class, gid);
assertTrue( g.getMultiple()!=null );
assertEquals( g.getMultiple().count, 12 );
assertSame(g.getMultiple().glarch, g);
s.delete(g);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
}
public void testSaveAddDelete() throws Exception {
Session s = openSession();
+ s.beginTransaction();
Baz baz = new Baz();
Set bars = new HashSet();
baz.setCascadingBars(bars);
@@ -1608,7 +1688,7 @@
baz.getCascadingBars().add( new Bar() );
s.delete(baz);
s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
}
@@ -1628,7 +1708,9 @@
s.save(baz);
s.save(bar2);
- List list = s.find("from Bar bar left join bar.baz baz left join baz.cascadingBars b where bar.name like 'Bar %'");
+ List list = s.createQuery(
+ "from Bar bar left join bar.baz baz left join baz.cascadingBars b where bar.name like 'Bar %'"
+ ).list();
Object row = list.iterator().next();
assertTrue( row instanceof Object[] && ( (Object[]) row ).length==3 );
@@ -1753,42 +1835,45 @@
}
public void testDyna() throws Exception {
Session s = openSession();
+ s.beginTransaction();
GlarchProxy g = new Glarch();
g.setName("G");
Serializable id = s.save(g);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
s = openSession();
+ s.beginTransaction();
g = (GlarchProxy) s.load(Glarch.class, id);
assertTrue( g.getName().equals("G") );
assertTrue( g.getDynaBean().get("foo").equals("foo") && g.getDynaBean().get("bar").equals( new Integer(66) ) );
assertTrue( ! (g instanceof Glarch) );
g.getDynaBean().put("foo", "bar");
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
s = openSession();
+ s.beginTransaction();
g = (GlarchProxy) s.load(Glarch.class, id);
assertTrue( g.getDynaBean().get("foo").equals("bar") && g.getDynaBean().get("bar").equals( new Integer(66) ) );
g.setDynaBean(null);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
s = openSession();
+ s.beginTransaction();
g = (GlarchProxy) s.load(Glarch.class, id);
assertTrue( g.getDynaBean()==null );
s.delete(g);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
}
public void testFindByCriteria() throws Exception {
- if ( getDialect() instanceof DB2Dialect ) return;
+ if ( getDialect() instanceof DB2Dialect ) {
+ return;
+ }
+
Session s = openSession();
Transaction txn = s.beginTransaction();
Foo f = new Foo();
@@ -1867,12 +1952,12 @@
.list();
assertTrue( list.size()==0 );
list = s.createCriteria(Foo.class)
- .setFetchMode("component.importantDates", FetchMode.EAGER)
+ .setFetchMode( "component.importantDates", FetchMode.JOIN )
.list();
assertTrue( list.size()==3 );
list = s.createCriteria(Foo.class)
- .setFetchMode("component.importantDates", FetchMode.EAGER)
+ .setFetchMode( "component.importantDates", FetchMode.JOIN )
.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY)
.list();
assertTrue( list.size()==1 );
@@ -1889,11 +1974,11 @@
.add( Restrictions.like( "string", f.getString() ) )
.add( Restrictions.in( "boolean", new Boolean[] { f.getBoolean(), f.getBoolean() } ) )
.add( Restrictions.isNotNull("foo") )
- .setFetchMode("foo", FetchMode.EAGER)
- .setFetchMode("baz", FetchMode.LAZY)
- .setFetchMode("component.glarch", FetchMode.LAZY)
- .setFetchMode("foo.baz", FetchMode.LAZY)
- .setFetchMode("foo.component.glarch", FetchMode.LAZY)
+ .setFetchMode( "foo", FetchMode.JOIN )
+ .setFetchMode( "baz", FetchMode.SELECT )
+ .setFetchMode( "component.glarch", FetchMode.SELECT )
+ .setFetchMode( "foo.baz", FetchMode.SELECT )
+ .setFetchMode( "foo.component.glarch", FetchMode.SELECT )
.list();
f = (Foo) list.get(0);
assertTrue( Hibernate.isInitialized( f.getFoo() ) );
@@ -1914,14 +1999,14 @@
public void testAfterDelete() throws Exception {
Session s = openSession();
+ s.beginTransaction();
Foo foo = new Foo();
s.save(foo);
s.flush();
s.delete(foo);
s.save(foo);
s.delete(foo);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
}
@@ -1932,31 +2017,32 @@
Foo[] arr = new Foo[10];
arr[0] = foo1;
arr[9] = foo2;
+
Session s = openSession();
+ s.beginTransaction();
s.save(foo1);
s.save(foo2);
baz.setFooArray(arr);
s.save(baz);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
s = openSession();
+ s.beginTransaction();
baz = (Baz) s.load( Baz.class, baz.getCode() );
assertTrue( baz.getFooArray().length==1 );
- assertTrue( s.find("from Baz baz join baz.fooArray foo").size()==1 );
- assertTrue( s.find("from Foo foo").size()==2 );
- assertTrue( s.filter( baz.getFooArray(), "" ).size()==1 );
+ assertTrue( s.createQuery( "from Baz baz join baz.fooArray foo" ).list().size()==1 );
+ assertTrue( s.createQuery( "from Foo foo" ).list().size()==2 );
+ assertTrue( s.createFilter( baz.getFooArray(), "" ).list().size()==1 );
//assertTrue( s.delete("from java.lang.Object o")==9 );
- s.delete("from Foo foo");
+ doDelete( s, "from Foo foo" );
String bazid = baz.getCode();
s.delete(baz);
int rows=s.connection().createStatement().executeUpdate(
"delete from fooArray where id_='" + bazid + "' and i>=8"
);
assertTrue(rows==1);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
}
@@ -1985,24 +2071,24 @@
public void testCollectionCache() throws Exception {
Session s = openSession();
+ s.beginTransaction();
Baz baz = new Baz();
baz.setDefaults();
s.save(baz);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
s = openSession();
+ s.beginTransaction();
s.load( Baz.class, baz.getCode() );
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
s = openSession();
+ s.beginTransaction();
baz = (Baz) s.load( Baz.class, baz.getCode() );
s.delete(baz);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
}
@@ -2028,19 +2114,24 @@
s = openSession();
t = s.beginTransaction();
- assertTrue( s.find(
- "from Stuff as s where s.foo.id = ? and s.id.id = ? and s.moreStuff.id.intId = ? and s.moreStuff.id.stringId = ?",
- new Object[] { bar, new Long(1234), new Integer(12), "id" },
- new Type[] { Hibernate.entity(Foo.class), Hibernate.LONG, Hibernate.INTEGER, Hibernate.STRING }
- ).size()==1 );
- assertTrue( s.find(
- "from Stuff as s where s.foo.id = ? and s.id.id = ? and s.moreStuff.name = ?",
- new Object[] { bar, new Long(1234), "More Stuff" },
- new Type[] { Hibernate.entity(Foo.class), Hibernate.LONG, Hibernate.STRING }
- ).size()==1 );
- s.find("from Stuff as s where s.foo.string is not null");
+ List results = s.createQuery(
+ "from Stuff as s where s.foo.id = ? and s.id.id = ? and s.moreStuff.id.intId = ? and s.moreStuff.id.stringId = ?"
+ )
+ .setParameter( 0, bar, Hibernate.entity(Foo.class) )
+ .setParameter( 1, new Long(1234), Hibernate.LONG )
+ .setParameter( 2, new Integer(12), Hibernate.INTEGER )
+ .setParameter( 3, "id", Hibernate.STRING )
+ .list();
+ assertEquals( 1, results.size() );
+ results = s.createQuery( "from Stuff as s where s.foo.id = ? and s.id.id = ? and s.moreStuff.name = ?" )
+ .setParameter( 0, bar, Hibernate.entity(Foo.class) )
+ .setParameter( 1, new Long(1234), Hibernate.LONG )
+ .setParameter( 2, "More Stuff", Hibernate.STRING )
+ .list();
+ assertEquals( 1, results.size() );
+ s.createQuery( "from Stuff as s where s.foo.string is not null" ).list();
assertTrue(
- s.find("from Stuff as s where s.foo > '0' order by s.foo").size()==1
+ s.createQuery( "from Stuff as s where s.foo > '0' order by s.foo" ).list().size()==1
);
//s.createCriteria(Stuff.class).createCriteria("id.foo").add( Expression.isNull("foo") ).list();
t.commit();
@@ -2062,8 +2153,8 @@
s.load(stuff, stuff);
assertTrue( stuff.getProperty().equals( TimeZone.getDefault() ) );
assertTrue( stuff.getMoreStuff().getName().equals("More Stuff") );
- s.delete("from MoreStuff");
- s.delete("from Foo foo");
+ doDelete( s, "from MoreStuff" );
+ doDelete( s, "from Foo foo" );
t.commit();
s.close();
}
@@ -2085,10 +2176,9 @@
baz = (Baz) s.load( Baz.class, baz.getCode() );
assertTrue( baz.getFees().size()==2 );
s.delete(baz);
- assertTrue( !s.iterate("from Fee fee").hasNext() );
+ assertTrue( !s.createQuery( "from Fee fee" ).iterate().hasNext() );
t.commit();
s.close();
-
}
public void testCollectionsInSelect() throws Exception {
@@ -2108,7 +2198,7 @@
bar.setBaz(baz);
s.save(bar);
- List list = s.find("select new Result(foo.string, foo.long, foo.integer) from Foo foo");
+ List list = s.createQuery( "select new Result(foo.string, foo.long, foo.integer) from Foo foo" ).list();
assertTrue( list.size()==2 && ( list.get(0) instanceof Result ) && ( list.get(1) instanceof Result ) );
/*list = s.find("select new Result( baz.name, foo.long, count(elements(baz.fooArray)) ) from Baz baz join baz.fooArray foo group by baz.name, foo.long");
assertTrue( list.size()==1 && ( list.get(0) instanceof Result ) );
@@ -2116,7 +2206,9 @@
assertEquals( r.getName(), baz.getName() );
assertEquals( r.getCount(), 1 );
assertEquals( r.getAmount(), foos[1].getLong().longValue() );*/
- list = s.find("select new Result( baz.name, max(foo.long), count(foo) ) from Baz baz join baz.fooArray foo group by baz.name");
+ list = s.createQuery(
+ "select new Result( baz.name, max(foo.long), count(foo) ) from Baz baz join baz.fooArray foo group by baz.name"
+ ).list();
assertTrue( list.size()==1 && ( list.get(0) instanceof Result ) );
Result r = ((Result) list.get(0) );
assertEquals( r.getName(), baz.getName() );
@@ -2127,84 +2219,121 @@
//s.find("select max( elements(bar.baz.fooArray) ) from Bar as bar");
//The following test is disabled for databases with no subselects...also for Interbase (not sure why).
if ( !(getDialect() instanceof MySQLDialect) && !(getDialect() instanceof HSQLDialect) /*&& !(dialect instanceof MckoiDialect)*/ && !(getDialect() instanceof SAPDBDialect) && !(getDialect() instanceof PointbaseDialect) ) {
- s.find("select count(*) from Baz as baz where 1 in indices(baz.fooArray)");
- s.find("select count(*) from Bar as bar where 'abc' in elements(bar.baz.fooArray)");
- s.find("select count(*) from Bar as bar where 1 in indices(bar.baz.fooArray)");
+ s.createQuery( "select count(*) from Baz as baz where 1 in indices(baz.fooArray)" ).list();
+ s.createQuery( "select count(*) from Bar as bar where 'abc' in elements(bar.baz.fooArray)" ).list();
+ s.createQuery( "select count(*) from Bar as bar where 1 in indices(bar.baz.fooArray)" ).list();
if ( !(getDialect() instanceof DB2Dialect) && !(getDialect() instanceof Oracle8iDialect ) && !( getDialect() instanceof SybaseDialect ) && !( getDialect() instanceof Sybase11Dialect ) && !( getDialect() instanceof SybaseASE15Dialect )) {
// SybaseAnywhereDialect supports implicit conversions from strings to ints
- s.find("select count(*) from Bar as bar, bar.component.glarch.proxyArray as g where g.id in indices(bar.baz.fooArray)");
- s.find("select max( elements(bar.baz.fooArray) ) from Bar as bar, bar.component.glarch.proxyArray as g where g.id in indices(bar.baz.fooArray)");
+ s.createQuery(
+ "select count(*) from Bar as bar, bar.component.glarch.proxyArray as g where g.id in indices(bar.baz.fooArray)"
+ ).list();
+ s.createQuery(
+ "select max( elements(bar.baz.fooArray) ) from Bar as bar, bar.component.glarch.proxyArray as g where g.id in indices(bar.baz.fooArray)"
+ ).list();
}
- s.find("select count(*) from Bar as bar where '1' in (from bar.component.glarch.proxyArray g where g.name='foo')");
- s.find("select count(*) from Bar as bar where '1' in (from bar.component.glarch.proxyArray g where g.name='foo')");
- s.find("select count(*) from Bar as bar left outer join bar.component.glarch.proxyArray as pg where '1' in (from bar.component.glarch.proxyArray)");
+ s.createQuery(
+ "select count(*) from Bar as bar where '1' in (from bar.component.glarch.proxyArray g where g.name='foo')"
+ ).list();
+ s.createQuery(
+ "select count(*) from Bar as bar where '1' in (from bar.component.glarch.proxyArray g where g.name='foo')"
+ ).list();
+ s.createQuery(
+ "select count(*) from Bar as bar left outer join bar.component.glarch.proxyArray as pg where '1' in (from bar.component.glarch.proxyArray)"
+ ).list();
}
- list = s.find("from Baz baz left join baz.fooToGlarch join fetch baz.fooArray foo left join fetch foo.foo");
+ list = s.createQuery(
+ "from Baz baz left join baz.fooToGlarch join fetch baz.fooArray foo left join fetch foo.foo"
+ ).list();
assertTrue( list.size()==1 && ( (Object[]) list.get(0) ).length==2 );
- s.find("select baz.name from Bar bar inner join bar.baz baz inner join baz.fooSet foo where baz.name = bar.string");
- s.find("SELECT baz.name FROM Bar AS bar INNER JOIN bar.baz AS baz INNER JOIN baz.fooSet AS foo WHERE baz.name = bar.string");
+ s.createQuery(
+ "select baz.name from Bar bar inner join bar.baz baz inner join baz.fooSet foo where baz.name = bar.string"
+ ).list();
+ s.createQuery(
+ "SELECT baz.name FROM Bar AS bar INNER JOIN bar.baz AS baz INNER JOIN baz.fooSet AS foo WHERE baz.name = bar.string"
+ ).list();
- if ( !( getDialect() instanceof HSQLDialect ) ) s.find("select baz.name from Bar bar join bar.baz baz left outer join baz.fooSet foo where baz.name = bar.string");
+ if ( !( getDialect() instanceof HSQLDialect ) ) s.createQuery(
+ "select baz.name from Bar bar join bar.baz baz left outer join baz.fooSet foo where baz.name = bar.string"
+ ).list();
- s.find("select baz.name from Bar bar join bar.baz baz join baz.fooSet foo where baz.name = bar.string");
- s.find("SELECT baz.name FROM Bar AS bar JOIN bar.baz AS baz JOIN baz.fooSet AS foo WHERE baz.name = bar.string");
+ s.createQuery( "select baz.name from Bar bar join bar.baz baz join baz.fooSet foo where baz.name = bar.string" )
+ .list();
+ s.createQuery(
+ "SELECT baz.name FROM Bar AS bar JOIN bar.baz AS baz JOIN baz.fooSet AS foo WHERE baz.name = bar.string"
+ ).list();
if ( !( getDialect() instanceof HSQLDialect ) ) {
- s.find("select baz.name from Bar bar left join bar.baz baz left join baz.fooSet foo where baz.name = bar.string");
- s.find("select foo.string from Bar bar left join bar.baz.fooSet foo where bar.string = foo.string");
+ s.createQuery(
+ "select baz.name from Bar bar left join bar.baz baz left join baz.fooSet foo where baz.name = bar.string"
+ ).list();
+ s.createQuery( "select foo.string from Bar bar left join bar.baz.fooSet foo where bar.string = foo.string" )
+ .list();
}
- s.find("select baz.name from Bar bar left join bar.baz baz left join baz.fooArray foo where baz.name = bar.string");
- s.find("select foo.string from Bar bar left join bar.baz.fooArray foo where bar.string = foo.string");
+ s.createQuery(
+ "select baz.name from Bar bar left join bar.baz baz left join baz.fooArray foo where baz.name = bar.string"
+ ).list();
+ s.createQuery( "select foo.string from Bar bar left join bar.baz.fooArray foo where bar.string = foo.string" )
+ .list();
- s.find("select bar.string, foo.string from Bar bar inner join bar.baz as baz inner join baz.fooSet as foo where baz.name = 'name'");
- s.find("select foo from Bar bar inner join bar.baz as baz inner join baz.fooSet as foo");
- s.find("select foo from Bar bar inner join bar.baz.fooSet as foo");
+ s.createQuery(
+ "select bar.string, foo.string from Bar bar inner join bar.baz as baz inner join baz.fooSet as foo where baz.name = 'name'"
+ ).list();
+ s.createQuery( "select foo from Bar bar inner join bar.baz as baz inner join baz.fooSet as foo" ).list();
+ s.createQuery( "select foo from Bar bar inner join bar.baz.fooSet as foo" ).list();
- s.find("select bar.string, foo.string from Bar bar join bar.baz as baz join baz.fooSet as foo where baz.name = 'name'");
- s.find("select foo from Bar bar join bar.baz as baz join baz.fooSet as foo");
- s.find("select foo from Bar bar join bar.baz.fooSet as foo");
+ s.createQuery(
+ "select bar.string, foo.string from Bar bar join bar.baz as baz join baz.fooSet as foo where baz.name = 'name'"
+ ).list();
+ s.createQuery( "select foo from Bar bar join bar.baz as baz join baz.fooSet as foo" ).list();
+ s.createQuery( "select foo from Bar bar join bar.baz.fooSet as foo" ).list();
- assertTrue( s.find("from Bar bar join bar.baz.fooArray foo").size()==1 );
+ assertTrue( s.createQuery( "from Bar bar join bar.baz.fooArray foo" ).list().size()==1 );
- assertTrue( s.find("from Bar bar join bar.baz.fooSet foo").size()==0 );
- assertTrue( s.find("from Bar bar join bar.baz.fooArray foo").size()==1 );
+ assertTrue( s.createQuery( "from Bar bar join bar.baz.fooSet foo" ).list().size()==0 );
+ assertTrue( s.createQuery( "from Bar bar join bar.baz.fooArray foo" ).list().size()==1 );
s.delete(bar);
if ( getDialect() instanceof DB2Dialect || getDialect() instanceof PostgreSQLDialect ) {
- s.iterate("select one from One one join one.manies many group by one order by count(many)");
- s.iterate("select one from One one join one.manies many group by one having count(many) < 5");
+ s.createQuery( "select one from One one join one.manies many group by one order by count(many)" ).iterate();
+ s.createQuery( "select one from One one join one.manies many group by one having count(many) < 5" )
+ .iterate();
}
- s.find("from One one join one.manies many where one.id = 1 and many.id = 1");
- s.iterate("select one.id, elements(one.manies) from One one");
- s.iterate("select max( elements(one.manies) ) from One one");
- s.find("select one, elements(one.manies) from One one");
- //s.iterate("select one, max( elements(one.manies) ) from One one group by one");
- Iterator iter = s.iterate("select elements(baz.fooArray) from Baz baz where baz.id=?", baz.getCode(), Hibernate.STRING);
- //WAS: assertTrue( iter.next()==null && iter.next()==foos[1] && !iter.hasNext() );
+ s.createQuery( "from One one join one.manies many where one.id = 1 and many.id = 1" ).list();
+ s.createQuery( "select one.id, elements(one.manies) from One one" ).iterate();
+ s.createQuery( "select max( elements(one.manies) ) from One one" ).iterate();
+ s.createQuery( "select one, elements(one.manies) from One one" ).list();
+ Iterator iter = s.createQuery( "select elements(baz.fooArray) from Baz baz where baz.id=?" )
+ .setParameter( 0, baz.getCode(), Hibernate.STRING )
+ .iterate();
assertTrue( iter.next()==foos[1] && !iter.hasNext() );
- list = s.find("select elements(baz.fooArray) from Baz baz where baz.id=?", baz.getCode(), Hibernate.STRING);
- //WAS: assertTrue( list.size()==2 );
- assertTrue( list.size()==1 );
- iter = s.iterate("select indices(baz.fooArray) from Baz baz where baz.id=?", baz.getCode(), Hibernate.STRING);
- //WAS: assertTrue( iter.next().equals( new Integer(0) ) && iter.next().equals( new Integer(1) ) && !iter.hasNext() );
+ list = s.createQuery( "select elements(baz.fooArray) from Baz baz where baz.id=?" )
+ .setParameter( 0, baz.getCode(), Hibernate.STRING )
+ .list();
+ assertEquals( 1, list.size() );
+ iter = s.createQuery( "select indices(baz.fooArray) from Baz baz where baz.id=?" )
+ .setParameter( 0, baz.getCode(), Hibernate.STRING )
+ .iterate();
assertTrue( iter.next().equals( new Integer(1) ) && !iter.hasNext() );
- //assertTrue( s.iterate("select max( elements(baz.timeArray) ) from Baz baz where baz.id=?", baz.getCode(), Hibernate.STRING).next() instanceof Time );
- //assertTrue( s.iterate("select max( elements(baz.stringSet) ) from Baz baz where baz.id=?", baz.getCode(), Hibernate.STRING).next().equals("foo") );
- assertTrue( s.iterate("select size(baz.stringSet) from Baz baz where baz.id=?", baz.getCode(), Hibernate.STRING).next().equals( new Integer(3) ) );
- //s.find("from One one where sum one.manies.elements =0 or 1 = min one.manies.elements");
+ iter = s.createQuery( "select size(baz.stringSet) from Baz baz where baz.id=?" )
+ .setParameter( 0, baz.getCode(), Hibernate.STRING )
+ .iterate();
+ assertEquals( new Integer(3), iter.next() );
- s.find("from Foo foo where foo.component.glarch.id is not null");
+ s.createQuery( "from Foo foo where foo.component.glarch.id is not null" ).list();
- //iter = s.iterate("select baz, max( elements(baz.timeArray) ) from Baz baz group by baz");
- //while ( iter.hasNext() ) { Object[] arr = (Object[]) iter.next(); System.out.println( arr[0] + " " + arr[1] ); }
- iter = s.iterate("select baz, size(baz.stringSet), count( distinct elements(baz.stringSet) ), max( elements(baz.stringSet) ) from Baz baz group by baz");
- while ( iter.hasNext() ) { Object[] arr = (Object[]) iter.next(); System.out.println( arr[0] + " " + arr[1] + " " + arr[2] + " " + arr[3] ); }
+ iter = s.createQuery(
+ "select baz, size(baz.stringSet), count( distinct elements(baz.stringSet) ), max( elements(baz.stringSet) ) from Baz baz group by baz"
+ ).iterate();
+ while ( iter.hasNext() ) {
+ Object[] arr = (Object[]) iter.next();
+ log.info( arr[0] + " " + arr[1] + " " + arr[2] + " " + arr[3] );
+ }
s.delete(baz);
s.delete(baz2);
@@ -2221,30 +2350,30 @@
s.save(baz);
s.flush();
baz.getStringArray()[0] = "a new value";
- Iterator iter = s.iterate("from Baz baz");//no flush
+ Iterator iter = s.createQuery( "from Baz baz" ).iterate();//no flush
assertTrue( iter.next()==baz );
- iter = s.iterate("select elements(baz.stringArray) from Baz baz");
+ iter = s.createQuery( "select elements(baz.stringArray) from Baz baz" ).iterate();
boolean found = false;
while ( iter.hasNext() ) {
if ( iter.next().equals("a new value") ) found = true;
}
assertTrue(found);
baz.setStringArray(null);
- s.iterate("from Baz baz"); //no flush
- iter = s.iterate("select elements(baz.stringArray) from Baz baz");
+ s.createQuery( "from Baz baz" ).iterate(); //no flush
+ iter = s.createQuery( "select elements(baz.stringArray) from Baz baz" ).iterate();
assertTrue( !iter.hasNext() );
baz.getStringList().add("1E1");
- iter = s.iterate("from Foo foo");//no flush
+ iter = s.createQuery( "from Foo foo" ).iterate();//no flush
assertTrue( !iter.hasNext() );
- iter = s.iterate("select elements(baz.stringList) from Baz baz");
+ iter = s.createQuery( "select elements(baz.stringList) from Baz baz" ).iterate();
found = false;
while ( iter.hasNext() ) {
if ( iter.next().equals("1E1") ) found = true;
}
assertTrue(found);
baz.getStringList().remove("1E1");
- iter = s.iterate("select elements(baz.stringArray) from Baz baz"); //no flush
- iter = s.iterate("select elements(baz.stringList) from Baz baz");
+ iter = s.createQuery( "select elements(baz.stringArray) from Baz baz" ).iterate(); //no flush
+ iter = s.createQuery( "select elements(baz.stringList) from Baz baz" ).iterate();
found = false;
while ( iter.hasNext() ) {
if ( iter.next().equals("1E1") ) found = true;
@@ -2254,14 +2383,14 @@
List newList = new ArrayList();
newList.add("value");
baz.setStringList(newList);
- iter = s.iterate("from Foo foo");//no flush
+ iter = s.createQuery( "from Foo foo" ).iterate();//no flush
baz.setStringList(null);
- iter = s.iterate("select elements(baz.stringList) from Baz baz");
+ iter = s.createQuery( "select elements(baz.stringList) from Baz baz" ).iterate();
assertTrue( !iter.hasNext() );
baz.setStringList(newList);
- iter = s.iterate("from Foo foo");//no flush
- iter = s.iterate("select elements(baz.stringList) from Baz baz");
+ iter = s.createQuery( "from Foo foo" ).iterate();//no flush
+ iter = s.createQuery( "select elements(baz.stringList) from Baz baz" ).iterate();
assertTrue( iter.hasNext() );
s.delete(baz);
@@ -2272,9 +2401,9 @@
public void testPersistCollections() throws Exception {
Session s = openSession();
Transaction txn = s.beginTransaction();
- assertTrue( ( (Long) s.iterate("select count(*) from Bar").next() ).longValue()==0 );
- assertTrue( s.iterate("select count(*) from Bar b").next().equals( new Long(0) ) );
- assertFalse( s.iterate("from Glarch g").hasNext() );
+ assertEquals( 0, ( (Long) s.createQuery( "select count(*) from Bar" ).iterate().next() ).longValue() );
+ assertTrue( s.createQuery( "select count(*) from Bar b" ).iterate().next().equals( new Long(0) ) );
+ assertFalse( s.createQuery( "from Glarch g" ).iterate().hasNext() );
Baz baz = new Baz();
s.save(baz);
@@ -2287,14 +2416,13 @@
sgm.put( "a", new Glarch() );
sgm.put( "b", new Glarch() );
baz.setStringGlarchMap(sgm);
- //System.out.println( s.print(baz) );
txn.commit();
s.close();
s = openSession();
txn = s.beginTransaction();
- assertTrue( ( (Long) s.iterate("select count(*) from Bar").next() ).longValue()==1 );
- baz = (Baz) ( (Object[]) s.find("select baz, baz from Baz baz").get(0) )[1];
+ assertTrue( ( (Long) s.createQuery( "select count(*) from Bar" ).iterate().next() ).longValue()==1 );
+ baz = (Baz) ( (Object[]) s.createQuery( "select baz, baz from Baz baz" ).list().get(0) )[1];
assertTrue( baz.getCascadingBars().size()==1 );
//System.out.println( s.print(baz) );
Foo foo = new Foo();
@@ -2315,23 +2443,25 @@
//The following test is disabled databases with no subselects
if ( !(getDialect() instanceof MySQLDialect) && !(getDialect() instanceof HSQLDialect) && !(getDialect() instanceof PointbaseDialect) ) {
- List list = s.find("select foo from Foo foo, Baz baz where foo in elements(baz.fooArray) and 3 = some elements(baz.intArray) and 4 > all indices(baz.intArray)");
+ List list = s.createQuery(
+ "select foo from Foo foo, Baz baz where foo in elements(baz.fooArray) and 3 = some elements(baz.intArray) and 4 > all indices(baz.intArray)"
+ ).list();
assertTrue( "collection.elements find", list.size()==2 );
}
if (!(getDialect() instanceof SAPDBDialect) ) { // SAPDB doesn't like distinct with binary type
- List list = s.find("select distinct foo from Baz baz join baz.fooArray foo");
+ List list = s.createQuery( "select distinct foo from Baz baz join baz.fooArray foo" ).list();
assertTrue( "collection.elements find", list.size()==2 );
}
- List list = s.find("select foo from Baz baz join baz.fooSet foo");
+ List list = s.createQuery( "select foo from Baz baz join baz.fooSet foo" ).list();
assertTrue( "association.elements find", list.size()==1 );
txn.commit();
s.close();
s = openSession();
txn = s.beginTransaction();
- assertTrue( ( (Long) s.iterate("select count(*) from Bar").next() ).longValue()==1 );
- baz = (Baz) s.find("select baz from Baz baz order by baz").get(0);
+ assertTrue( ( (Long) s.createQuery( "select count(*) from Bar" ).iterate().next() ).longValue()==1 );
+ baz = (Baz) s.createQuery( "select baz from Baz baz order by baz" ).list().get(0);
assertTrue( "collection of custom types - added element", baz.getCustoms().size()==4 && baz.getCustoms().get(0)!=null );
assertTrue ( "component of component in collection", baz.getComponents()[1].getSubcomponent()!=null );
assertTrue( baz.getComponents()[1].getBaz()==baz );
@@ -2350,7 +2480,7 @@
s = openSession();
txn = s.beginTransaction();
- baz = (Baz) s.find("select baz from Baz baz order by baz").get(0);
+ baz = (Baz) s.createQuery( "select baz from Baz baz order by baz" ).list().get(0);
assertTrue( baz.getStringSet().size()==2 );
assertTrue( baz.getStringSet().first().equals("one") );
assertTrue( baz.getStringSet().last().equals("two") );
@@ -2362,7 +2492,7 @@
s = openSession();
txn = s.beginTransaction();
- assertTrue( ( (Long) s.iterate("select count(*) from Bar").next() ).longValue()==1 );
+ assertTrue( ( (Long) s.createQuery( "select count(*) from Bar" ).iterate().next() ).longValue()==1 );
baz = (Baz) s.load(Baz.class, baz.getCode());
assertTrue( baz.getCascadingBars().size()==1 );
Bar bar = new Bar();
@@ -2392,13 +2522,13 @@
s = openSession();
txn = s.beginTransaction();
- baz = (Baz) s.find("select baz from Baz baz order by baz").get(0);
+ baz = (Baz) s.createQuery( "select baz from Baz baz order by baz" ).list().get(0);
assertTrue( baz.getCascadingBars().size()==1 );
Session s2 = openSession();
Transaction txn2 = s2.beginTransaction();
- assertTrue( ( (Long) s2.iterate("select count(*) from Bar").next() ).longValue()==3 );
- Baz baz2 = (Baz) s2.find("select baz from Baz baz order by baz").get(0);
+ assertTrue( ( (Long) s2.createQuery( "select count(*) from Bar" ).iterate().next() ).longValue()==3 );
+ Baz baz2 = (Baz) s2.createQuery( "select baz from Baz baz order by baz" ).list().get(0);
Object o = baz2.getFooComponentToFoo().get( new FooComponent("name", 123, null, null) );
assertTrue(
o==baz2.getFooComponentToFoo().get( new FooComponent("nameName", 12, null, null) ) && o!=null
@@ -2441,8 +2571,8 @@
s = openSession();
txn = s.beginTransaction();
- assertTrue( ( (Long) s.iterate("select count(*) from Bar").next() ).longValue()==3 );
- baz = (Baz) s.find("select baz from Baz baz order by baz").get(0);
+ assertTrue( ( (Long) s.createQuery( "select count(*) from Bar" ).iterate().next() ).longValue()==3 );
+ baz = (Baz) s.createQuery( "select baz from Baz baz order by baz" ).list().get(0);
assertTrue( baz.getTopGlarchez().size()==2 );
assertTrue( baz.getCascadingBars().size()==1 );
txn.commit();
@@ -2455,13 +2585,13 @@
s2.reconnect();
txn2 = s2.beginTransaction();
baz = (Baz) s2.load(Baz.class, baz.getCode());
- assertTrue( ( (Long) s2.iterate("select count(*) from Bar").next() ).longValue()==3 );
+ assertTrue( ( (Long) s2.createQuery( "select count(*) from Bar" ).iterate().next() ).longValue()==3 );
s2.delete(baz);
s2.delete( baz.getTopGlarchez().get( new Character('G') ) );
s2.delete( baz.getTopGlarchez().get( new Character('H') ) );
int rows = s2.connection().createStatement().executeUpdate("update " + getDialect().openQuote() + "glarchez" + getDialect().closeQuote() + " set baz_map_id=null where baz_map_index='a'");
assertTrue(rows==1);
- assertTrue( s2.delete("from Bar bar")==2 );
+ assertEquals( 2, doDelete( s2, "from Bar bar" ) );
FooProxy[] arr = baz.getFooArray();
assertTrue( "new array of objects", arr.length==4 && arr[1].getKey().equals( foo.getKey() ) );
for ( int i=1; i<arr.length; i++ ) {
@@ -2470,7 +2600,7 @@
s2.load( Qux.class, new Long(666) ); //nonexistent
- assertTrue( s2.delete("from Glarch g")==1 );
+ assertEquals( 1, doDelete( s2, "from Glarch g" ) );
txn2.commit();
s2.disconnect();
@@ -2485,62 +2615,66 @@
public void testSaveFlush() throws Exception {
Session s = openSession();
+ s.beginTransaction();
Fee fee = new Fee();
s.save( fee, "key" );
fee.setFi("blah");
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
+
s = openSession();
+ s.beginTransaction();
fee = (Fee) s.load( Fee.class, fee.getKey() );
assertTrue( "blah".equals( fee.getFi() ) );
assertTrue( "key".equals( fee.getKey() ) );
s.delete(fee);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
}
public void testCreateUpdate() throws Exception {
Session s = openSession();
+ s.beginTransaction();
Foo foo = new Foo();
s.save(foo);
foo.setString("dirty");
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
+
s = openSession();
+ s.beginTransaction();
Foo foo2 = new Foo();
s.load( foo2, foo.getKey() );
// There is an interbase bug that causes null integers to return as 0, also numeric precision is <= 15
assertTrue( "create-update", foo.equalsFoo(foo2) );
//System.out.println( s.print(foo2) );
s.delete(foo2);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
s = openSession();
+ s.beginTransaction();
foo = new Foo();
s.save(foo, "assignedid");
foo.setString("dirty");
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
+
s = openSession();
+ s.beginTransaction();
s.load(foo2, "assignedid");
// There is an interbase bug that causes null integers to return as 0, also numeric precision is <= 15
assertTrue( "create-update", foo.equalsFoo(foo2) );
//System.out.println( s.print(foo2) );
s.delete(foo2);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
}
public void testUpdateCollections() throws Exception {
Session s = openSession();
+ s.beginTransaction();
Holder baz = new Holder();
baz.setName("123");
Foo f1 = new Foo();
@@ -2558,8 +2692,7 @@
s.save(f3);
s.save(o);
s.save(baz);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
baz.getOnes().set(0, null);
@@ -2569,12 +2702,13 @@
foos[1] = f1;
s = openSession();
+ s.beginTransaction();
s.saveOrUpdate(baz);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
s = openSession();
+ s.beginTransaction();
Holder h = (Holder) s.load(Holder.class, baz.getId());
assertTrue( h.getOnes().get(0)==null );
assertTrue( h.getOnes().get(1)!=null );
@@ -2582,7 +2716,7 @@
assertTrue( h.getFooArray()[1]!=null);
assertTrue( h.getFooArray()[2]!=null);
assertTrue( h.getFoos().size()==2 );
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
baz.getFoos().remove(f1);
@@ -2590,38 +2724,40 @@
baz.getFooArray()[0]=null;
baz.getFooArray()[0]=null;
baz.getFooArray()[0]=null;
+
s = openSession();
+ s.beginTransaction();
s.saveOrUpdate(baz);
- s.delete("from Foo");
+ doDelete( s, "from Foo" );
baz.getOnes().remove(o);
- s.delete("from One");
+ doDelete( s, "from One" );
s.delete(baz);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
-
}
public void testCreate() throws Exception {
Session s = openSession();
+ s.beginTransaction();
Foo foo = new Foo();
s.save(foo);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
+
s = openSession();
+ s.beginTransaction();
Foo foo2 = new Foo();
s.load( foo2, foo.getKey() );
// There is an interbase bug that causes null integers to return as 0, also numeric precision is <= 15
assertTrue( "create", foo.equalsFoo(foo2) );
s.delete(foo2);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
}
public void testCallback() throws Exception {
Session s = openSession();
+ s.beginTransaction();
Qux q = new Qux("0");
s.save(q);
q.setChild( new Qux("1") );
@@ -2635,43 +2771,45 @@
q4.setChild(q3);
s.save(q4);
s.save(q2);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
+
s = openSession();
- List l = s.find("from Qux");
+ s.beginTransaction();
+ List l = s.createQuery( "from Qux" ).list();
assertTrue( "", l.size()==5);
s.delete( l.get(0) );
s.delete( l.get(1) );
s.delete( l.get(2) );
s.delete( l.get(3) );
s.delete( l.get(4) );
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
}
public void testPolymorphism() throws Exception {
Session s = openSession();
+ s.beginTransaction();
Bar bar = new Bar();
s.save(bar);
bar.setBarString("bar bar");
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
+
s = openSession();
+ s.beginTransaction();
FooProxy foo = (FooProxy) s.load( Foo.class, bar.getKey() );
assertTrue( "polymorphic", foo instanceof BarProxy );
assertTrue( "subclass property", ( (BarProxy) foo ).getBarString().equals( bar.getBarString() ) );
//System.out.println( s.print(foo) );
s.delete(foo);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
}
public void testRemoveContains() throws Exception {
Session s = openSession();
+ s.beginTransaction();
Baz baz = new Baz();
baz.setDefaults();
s.save(baz);
@@ -2682,14 +2820,13 @@
Baz baz2 = (Baz) s.load( Baz.class, baz.getCode() );
assertFalse(baz==baz2);
s.delete(baz2);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
}
public void testCollectionOfSelf() throws Exception {
-
Session s = openSession();
+ s.beginTransaction();
Bar bar = new Bar();
s.save(bar);
bar.setAbstracts( new HashSet() );
@@ -2698,11 +2835,13 @@
bar.getAbstracts().add(bar2);
bar.setFoo(bar);
s.save(bar2);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
+
bar.setAbstracts(null);
+
s = openSession();
+ s.beginTransaction();
s.load( bar, bar.getKey() );
assertTrue( "collection contains self", bar.getAbstracts().size()==2 && bar.getAbstracts().contains(bar) );
assertTrue( "association to self", bar.getFoo()==bar );
@@ -2710,8 +2849,7 @@
while ( iter.hasNext() ) {
s.delete( iter.next() );
}
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
}
@@ -2728,18 +2866,18 @@
foo.setString("foo bar");
s.save( new Foo() );
s.save( new Bar() );
- List list1 = s.find("select foo from Foo foo where foo.string='foo bar'");
+ List list1 = s.createQuery( "select foo from Foo foo where foo.string='foo bar'" ).list();
assertTrue( "find size", list1.size()==1 );
assertTrue( "find ==", list1.get(0)==foo );
- List list2 = s.find("from Foo foo order by foo.string, foo.date");
+ List list2 = s.createQuery( "from Foo foo order by foo.string, foo.date" ).list();
assertTrue( "find size", list2.size()==4 );
- list1 = s.find("from Foo foo where foo.class='B'");
+ list1 = s.createQuery( "from Foo foo where foo.class='B'" ).list();
assertTrue( "class special property", list1.size()==2);
- list1 = s.find("from Foo foo where foo.class=Bar");
+ list1 = s.createQuery( "from Foo foo where foo.class=Bar" ).list();
assertTrue( "class special property", list1.size()==2);
- list1 = s.find("from Foo foo where foo.class=Bar");
- list2 = s.find("select bar from Bar bar, Foo foo where bar.string = foo.string and not bar=foo");
+ list1 = s.createQuery( "from Foo foo where foo.class=Bar" ).list();
+ list2 = s.createQuery( "select bar from Bar bar, Foo foo where bar.string = foo.string and not bar=foo" ).list();
assertTrue( "class special property", list1.size()==2);
assertTrue( "select from a subclass", list2.size()==1);
Trivial t = new Trivial();
@@ -2749,25 +2887,27 @@
s = openSession();
txn = s.beginTransaction();
- list1 = s.find("from Foo foo where foo.string='foo bar'");
+ list1 = s.createQuery( "from Foo foo where foo.string='foo bar'" ).list();
assertTrue( "find size", list1.size()==1 );
// There is an interbase bug that causes null integers to return as 0, also numeric precision is <= 15
assertTrue( "find equals", ( (Foo) list1.get(0) ).equalsFoo(foo) );
- list2 = s.find("select foo from Foo foo");
+ list2 = s.createQuery( "select foo from Foo foo" ).list();
assertTrue( "find size", list2.size()==5 );
- List list3 = s.find("from Bar bar where bar.barString='bar bar'");
+ List list3 = s.createQuery( "from Bar bar where bar.barString='bar bar'" ).list();
assertTrue( "find size", list3.size()==1 );
assertTrue( "find same instance", list2.contains( list1.get(0) ) && list2.contains( list2.get(0) ) );
- assertTrue( s.find("from Trivial").size()==1 );
- s.delete("from Trivial");
+ assertTrue( s.createQuery( "from Trivial" ).list().size()==1 );
+ doDelete( s, "from Trivial" );
- list2 = s.find("from Foo foo where foo.date = ?", new java.sql.Date(123), Hibernate.DATE);
+ list2 = s.createQuery( "from Foo foo where foo.date = ?" )
+ .setParameter( 0, new java.sql.Date(123), Hibernate.DATE )
+ .list();
assertTrue ( "find by date", list2.size()==4 );
Iterator iter = list2.iterator();
while ( iter.hasNext() ) {
s.delete( iter.next() );
}
- list2 = s.find("from Foo foo");
+ list2 = s.createQuery( "from Foo foo" ).list();
assertTrue( "find deleted", list2.size()==0);
txn.commit();
s.close();
@@ -2775,6 +2915,7 @@
public void testDeleteRecursive() throws Exception {
Session s = openSession();
+ s.beginTransaction();
Foo x = new Foo();
Foo y = new Foo();
x.setFoo(y);
@@ -2784,45 +2925,14 @@
s.flush();
s.delete(y);
s.delete(x);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
}
- /*public void testSubcollections() throws Exception {
- Session s = sessionsopenSession();
- Baz baz = new Baz();
- s.save(baz);
- baz.setDefaults();
- s.flush();
- s.connection().commit();
- s.close();
- s = sessionsopenSession();
- baz = (Baz) s.load( Baz.class, baz.getCode() );
- Set[] setArray = baz.getSetArray();
- baz.setSetArray(null);
- baz.setAnotherSetArray(setArray);
- baz.setAnotherSetList( baz.getSetList() );
- baz.setSetList(null);
- s.flush();
- s.connection().commit();
- s.close();
- s = sessionsopenSession();
- baz = (Baz) s.load( Baz.class, baz.getCode() );
- assertTrue( baz.getAnotherSetArray().length==2 && baz.getAnotherSetArray()[0]!=null, "subcollection moved property");
- assertTrue( baz.getSetArray()==null, "subcollection moved property");
- assertTrue( baz.getAnotherSetList().size()==4 && baz.getAnotherSetList().get(2)!=null, "subcollection moved role");
- assertTrue( baz.getSetList()==null, "subcollection moved role");
- s.delete(baz);
- s.flush();
- s.connection().commit();
- s.close();
- }*/
-
-
public void testReachability() throws Exception {
//first for unkeyed collections
Session s = openSession();
+ s.beginTransaction();
Baz baz1 = new Baz();
s.save(baz1);
Baz baz2 = new Baz();
@@ -2832,20 +2942,20 @@
Foo foo = new Foo();
s.save(foo);
baz1.getFooSet().add(foo);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
s = openSession();
+ s.beginTransaction();
baz2 = (Baz) s.load( Baz.class, baz2.getCode() );
baz1 = (Baz) s.load( Baz.class, baz1.getCode() );
baz2.setFooSet( baz1.getFooSet() ); baz1.setFooSet(null);
baz2.setIntArray( baz1.getIntArray() ); baz1.setIntArray(null);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
s = openSession();
+ s.beginTransaction();
baz2 = (Baz) s.load( Baz.class, baz2.getCode() );
baz1 = (Baz) s.load( Baz.class, baz1.getCode() );
assertTrue( "unkeyed reachability", baz2.getIntArray().length==4 );
@@ -2857,43 +2967,44 @@
s.delete(fp);
s.delete(baz1);
s.delete(baz2);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
//now for collections of collections
s = openSession();
+ s.beginTransaction();
baz1 = new Baz();
s.save(baz1);
baz2 = new Baz();
s.save(baz2);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
+
s = openSession();
+ s.beginTransaction();
baz2 = (Baz) s.load( Baz.class, baz2.getCode() );
baz1 = (Baz) s.load( Baz.class, baz1.getCode() );
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
+
s = openSession();
+ s.beginTransaction();
baz2 = (Baz) s.load( Baz.class, baz2.getCode() );
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
+
s = openSession();
+ s.beginTransaction();
baz2 = (Baz) s.load( Baz.class, baz2.getCode() );
baz1 = (Baz) s.load( Baz.class, baz1.getCode() );
- //System.out.println( s.print(baz1) + s.print(baz2) );
- //System.out.println( s.print(baz1) + s.print(baz2) );
s.delete(baz1);
s.delete(baz2);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
//now for keyed collections
s = openSession();
+ s.beginTransaction();
baz1 = new Baz();
s.save(baz1);
baz2 = new Baz();
@@ -2905,25 +3016,26 @@
baz1.setStringDateMap( new TreeMap() );
baz1.getStringDateMap().put("today", new Date( System.currentTimeMillis() ) );
baz1.getStringDateMap().put("tomorrow", new Date( System.currentTimeMillis() + 86400000 ) );
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
+
s = openSession();
+ s.beginTransaction();
baz2 = (Baz) s.load( Baz.class, baz2.getCode() );
baz1 = (Baz) s.load( Baz.class, baz1.getCode() );
baz2.setFooArray( baz1.getFooArray() ); baz1.setFooArray(null);
baz2.setStringDateMap( baz1.getStringDateMap() ); baz1.setStringDateMap(null);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
+
s = openSession();
+ s.beginTransaction();
baz2 = (Baz) s.load( Baz.class, baz2.getCode() );
baz1 = (Baz) s.load( Baz.class, baz1.getCode() );
assertTrue( "reachability", baz2.getStringDateMap().size()==2 );
assertTrue( "reachability", baz2.getFooArray().length==3 );
assertTrue( "reachability", baz1.getStringDateMap().size()==0 );
assertTrue( "reachability", baz1.getFooArray().length==0 );
- //System.out.println( s.print(baz1) + s.print(baz2) );
assertTrue( "null element", baz2.getFooArray()[1]==null );
assertTrue( "non-null element", baz2.getStringDateMap().get("today")!=null );
assertTrue( "non-null element", baz2.getStringDateMap().get("tomorrow")!=null );
@@ -2933,49 +3045,52 @@
s.delete(baz1);
s.delete(baz2);
s.flush();
- assertTrue( s.find("from java.lang.Object").size()==0 );
- s.connection().commit();
+ assertTrue( s.createQuery( "from java.lang.Object" ).list().size()==0 );
+ s.getTransaction().commit();
s.close();
}
public void testPersistentLifecycle() throws Exception {
Session s = openSession();
+ s.beginTransaction();
Qux q = new Qux();
s.save(q);
q.setStuff("foo bar baz qux");
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
+
s = openSession();
+ s.beginTransaction();
q = (Qux) s.load( Qux.class, q.getKey() );
assertTrue( "lifecycle create", q.getCreated() );
assertTrue( "lifecycle load", q.getLoaded() );
assertTrue( "lifecycle subobject", q.getFoo()!=null );
s.delete(q);
assertTrue( "lifecycle delete", q.getDeleted() );
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
+
s = openSession();
- assertTrue( "subdeletion", s.find("from Foo foo").size()==0);
- s.flush();
- s.connection().commit();
+ s.beginTransaction();
+ assertTrue( "subdeletion", s.createQuery( "from Foo foo" ).list().size()==0);
+ s.getTransaction().commit();
s.close();
}
public void testIterators() throws Exception {
Session s = openSession();
+ s.beginTransaction();
for ( int i=0; i<10; i++ ) {
Qux q = new Qux();
Object qid = s.save(q);
assertTrue("not null", qid!=null);
}
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
s = openSession();
- Iterator iter = s.iterate("from Qux q where q.stuff is null");
+ s.beginTransaction();
+ Iterator iter = s.createQuery( "from Qux q where q.stuff is null" ).iterate();
int count=0;
while ( iter.hasNext() ) {
Qux q = (Qux) iter.next();
@@ -2984,24 +3099,20 @@
count++;
}
assertTrue("iterate", count==10);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
s = openSession();
- assertTrue(
- "delete by query",
- s.delete("from Qux q where q.stuff=?", "foo", Hibernate.STRING)==8
- );
- s.flush();
- s.connection().commit();
+ s.beginTransaction();
+ assertEquals( 8, doDelete( s, "from Qux q where q.stuff=?", "foo", Hibernate.STRING ) );
+ s.getTransaction().commit();
s.close();
s = openSession();
- iter = s.iterate("from Qux q");
+ s.beginTransaction();
+ iter = s.createQuery( "from Qux q" ).iterate();
assertTrue( "empty iterator", !iter.hasNext() );
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
}
@@ -3031,7 +3142,7 @@
g.setName("foo");
assertTrue(
"find by version",
- s.find("from Glarch g where g.version=2").size()==1
+ s.createQuery( "from Glarch g where g.version=2" ).list().size()==1
);
g.setName("bar");
txn.commit();
@@ -3122,7 +3233,7 @@
assertTrue( "versioned collection after", g.getVersion()==4 );
s.delete(g);
s.flush();
- assertTrue( s.find("from java.lang.Object").size()==0 );
+ assertTrue( s.createQuery( "from java.lang.Object" ).list().size()==0 );
s.connection().commit();
s.close();
}
@@ -3221,27 +3332,27 @@
last = next;
last.setOrder( (short) (i+1) );
}
- Iterator iter = s.iterate("from Glarch g");
+ Iterator iter = s.createQuery( "from Glarch g" ).iterate();
while ( iter.hasNext() ) {
iter.next();
}
- List list = s.find("from Glarch g");
+ List list = s.createQuery( "from Glarch g" ).list();
assertTrue( "recursive find", list.size()==6 );
txn.commit();
s.close();
s = openSession();
txn = s.beginTransaction();
- list = s.find("from Glarch g");
+ list = s.createQuery( "from Glarch g" ).list();
assertTrue( "recursive iter", list.size()==6 );
- list = s.find("from Glarch g where g.next is not null");
+ list = s.createQuery( "from Glarch g where g.next is not null" ).list();
assertTrue( "recursive iter", list.size()==5 );
txn.commit();
s.close();
s = openSession();
txn = s.beginTransaction();
- iter = s.iterate("from Glarch g order by g.order asc");
+ iter = s.createQuery( "from Glarch g order by g.order asc" ).iterate();
while ( iter.hasNext() ) {
GlarchProxy g = (GlarchProxy) iter.next();
assertTrue( "not null", g!=null );
@@ -3263,18 +3374,18 @@
flast = flast.getFoo();
flast.setString( "foo" + (i+1) );
}
- iter = s.iterate("from Foo foo");
+ iter = s.createQuery( "from Foo foo" ).iterate();
while ( iter.hasNext() ) {
iter.next();
}
- list = s.find("from Foo foo");
+ list = s.createQuery( "from Foo foo" ).list();
assertTrue( "recursive find", list.size()==6 );
txn.commit();
s.close();
s = openSession();
txn = s.beginTransaction();
- list = s.find("from Foo foo");
+ list = s.createQuery( "from Foo foo" ).list();
assertTrue( "recursive iter", list.size()==6 );
iter = list.iterator();
while ( iter.hasNext() ) {
@@ -3285,7 +3396,7 @@
s = openSession();
txn = s.beginTransaction();
- iter = s.iterate("from Foo foo order by foo.string asc");
+ iter = s.createQuery( "from Foo foo order by foo.string asc" ).iterate();
while ( iter.hasNext() ) {
BarProxy bar = (BarProxy) iter.next();
assertTrue( "not null", bar!=null );
@@ -3368,7 +3479,7 @@
assertTrue( iter.previous() );
assertTrue( s.delete("from Foo")==4 );
s.flush();
- assertTrue( s.find("from java.lang.Object").size()==0 );
+ assertTrue( s.createQuery( "from java.lang.Object" ).list().size()==0 );
txn.commit();
s.close();
}
@@ -3381,23 +3492,28 @@
Foo foo1 = new Foo();
s.save(foo1);
foo.setFoo(foo1);
- List l = s.find("select parent, child from Foo parent, Foo child where parent.foo = child");
+ List l = s.createQuery( "select parent, child from Foo parent, Foo child where parent.foo = child" ).list();
assertTrue( "multi-column find", l.size()==1 );
- Iterator rs = s.iterate("select count(distinct child.id), count(distinct parent.id) from Foo parent, Foo child where parent.foo = child");
+ Iterator rs = s.createQuery(
+ "select count(distinct child.id), count(distinct parent.id) from Foo parent, Foo child where parent.foo = child"
+ ).iterate();
Object[] row = (Object[]) rs.next();
assertTrue( "multi-column count", ( (Long) row[0] ).intValue()==1 );
assertTrue( "multi-column count", ( (Long) row[1] ).intValue()==1 );
assertTrue( !rs.hasNext() );
- rs = s.iterate("select child.id, parent.id, child.long from Foo parent, Foo child where parent.foo = child");
+ rs = s.createQuery( "select child.id, parent.id, child.long from Foo parent, Foo child where parent.foo = child" )
+ .iterate();
row = (Object[]) rs.next();
assertTrue( "multi-column id", row[0].equals( foo.getFoo().getKey() ) );
assertTrue( "multi-column id", row[1].equals( foo.getKey() ) );
assertTrue( "multi-column property", row[2].equals( foo.getFoo().getLong() ) );
assertTrue( !rs.hasNext() );
- rs = s.iterate("select child.id, parent.id, child.long, child, parent.foo from Foo parent, Foo child where parent.foo = child");
+ rs = s.createQuery(
+ "select child.id, parent.id, child.long, child, parent.foo from Foo parent, Foo child where parent.foo = child"
+ ).iterate();
row = (Object[]) rs.next();
assertTrue(
foo.getFoo().getKey().equals( row[0] ) &&
@@ -3415,7 +3531,9 @@
s = openSession();
txn = s.beginTransaction();
- Iterator iter = s.iterate("select parent, child from Foo parent, Foo child where parent.foo = child and parent.string='a string'");
+ Iterator iter = s.createQuery(
+ "select parent, child from Foo parent, Foo child where parent.foo = child and parent.string='a string'"
+ ).iterate();
int deletions=0;
while ( iter.hasNext() ) {
Object[] pnc = (Object[]) iter.next();
@@ -3449,7 +3567,7 @@
s.close();
s = openSession();
tx = s.beginTransaction();
- assertTrue( s.find("from Fee fee").size()==0 );
+ assertTrue( s.createQuery( "from Fee fee" ).list().size()==0 );
tx.commit();
s.close();
}
@@ -3477,13 +3595,14 @@
s.close();
s = openSession();
tx = s.beginTransaction();
- assertTrue( s.find("from Fee fee").size()==0 );
+ assertTrue( s.createQuery( "from Fee fee" ).list().size()==0 );
tx.commit();
s.close();
}
public void testUpdateOrder() throws Exception {
Session s = openSession();
+ s.beginTransaction();
Fee fee1 = new Fee();
s.save(fee1);
Fee fee2 = new Fee();
@@ -3496,11 +3615,11 @@
fee2.setAnotherFee(fee3);
s.save(fee3);
s.save(fee2);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
s = openSession();
+ s.beginTransaction();
fee1.setCount(10);
fee2.setCount(20);
fee3.setCount(30);
@@ -3511,19 +3630,19 @@
s.delete(fee1);
s.delete(fee2);
s.delete(fee3);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
s = openSession();
- Transaction tx = s.beginTransaction();
- assertTrue( s.find("from Fee fee").size()==0 );
- tx.commit();
+ s.beginTransaction();
+ assertTrue( s.createQuery( "from Fee fee" ).list().size()==0 );
+ s.getTransaction().commit();
s.close();
}
public void testUpdateFromTransient() throws Exception {
Session s = openSession();
+ s.beginTransaction();
Fee fee1 = new Fee();
s.save(fee1);
Fee fee2 = new Fee();
@@ -3536,94 +3655,99 @@
fee2.setAnotherFee(fee3);
s.save(fee3);
s.save(fee2);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
fee1.setFi("changed");
+
s = openSession();
+ s.beginTransaction();
s.saveOrUpdate(fee1);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
Qux q = new Qux("quxxy");
q.setTheKey(0);
fee1.setQux(q);
+
s = openSession();
+ s.beginTransaction();
s.saveOrUpdate(fee1);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
-
s = openSession();
+ s.beginTransaction();
fee1 = (Fee) s.load( Fee.class, fee1.getKey() );
assertTrue( "updated from transient", fee1.getFi().equals("changed") );
assertTrue( "unsaved value", fee1.getQux()!=null );
s.delete( fee1.getQux() );
fee1.setQux(null);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
fee2.setFi("CHANGED");
fee2.getFees().add("an element");
fee1.setFi("changed again");
+
s = openSession();
+ s.beginTransaction();
s.saveOrUpdate(fee2);
s.update( fee1, fee1.getKey() );
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
s = openSession();
+ s.beginTransaction();
Fee fee = new Fee();
s.load( fee, fee2.getKey() );
fee1 = (Fee) s.load( Fee.class, fee1.getKey() );
assertTrue( "updated from transient", fee1.getFi().equals("changed again") );
assertTrue( "updated from transient", fee.getFi().equals("CHANGED") );
assertTrue( "updated collection", fee.getFees().contains("an element") );
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
fee.getFees().clear();
fee.getFees().add("new element");
fee1.setFee(null);
+
s = openSession();
+ s.beginTransaction();
s.saveOrUpdate(fee);
s.saveOrUpdate(fee1);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
s = openSession();
+ s.beginTransaction();
s.load( fee, fee.getKey() );
assertTrue( "update", fee.getAnotherFee()!=null );
assertTrue( "update", fee.getFee()!=null );
assertTrue( "update", fee.getAnotherFee().getFee()==fee.getFee() );
assertTrue( "updated collection", fee.getFees().contains("new element") );
assertTrue( "updated collection", !fee.getFees().contains("an element") );
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
fee.setQux( new Qux("quxy") );
+
s = openSession();
+ s.beginTransaction();
s.saveOrUpdate(fee);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
fee.getQux().setStuff("xxx");
+
s = openSession();
+ s.beginTransaction();
s.saveOrUpdate(fee);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
s = openSession();
+ s.beginTransaction();
s.load( fee, fee.getKey() );
assertTrue( "cascade update", fee.getQux()!=null );
assertTrue( "cascade update", fee.getQux().getStuff().equals("xxx") );
@@ -3632,38 +3756,38 @@
assertTrue( "update", fee.getAnotherFee().getFee()==fee.getFee() );
fee.getAnotherFee().setAnotherFee(null);
s.delete(fee);
- s.delete("from Fee fee");
- s.flush();
- s.connection().commit();
+ doDelete( s, "from Fee fee" );
+ s.getTransaction().commit();
s.close();
s = openSession();
- Transaction tx = s.beginTransaction();
- assertTrue( s.find("from Fee fee").size()==0 );
- tx.commit();
+ s.beginTransaction();
+ assertTrue( s.createQuery( "from Fee fee" ).list().size()==0 );
+ s.getTransaction().commit();
s.close();
}
public void testArraysOfTimes() throws Exception {
Session s = openSession();
+ s.beginTransaction();
Baz baz = new Baz() ;
s.save(baz);
baz.setDefaults();
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
+
s = openSession();
-
+ s.beginTransaction();
baz.getTimeArray()[2] = new Date(123);
baz.getTimeArray()[3] = new java.sql.Time(1234);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
+
s = openSession();
+ s.beginTransaction();
baz = (Baz) s.load( Baz.class, baz.getCode() );
s.delete(baz);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
}
@@ -3711,7 +3835,7 @@
foo = new Foo();
s.save(foo);
foo.setCustom( new String[] { "one", "two" } );
- assertTrue( s.find("from Foo foo where foo.custom.s1 = 'one'").get(0)==foo );
+ assertTrue( s.createQuery( "from Foo foo where foo.custom.s1 = 'one'" ).list().get(0)==foo );
s.delete(foo);
txn.commit();
s.close();
@@ -3720,36 +3844,37 @@
public void testNoForeignKeyViolations() throws Exception {
Session s = openSession();
+ s.beginTransaction();
Glarch g1 = new Glarch();
Glarch g2 = new Glarch();
g1.setNext(g2);
g2.setNext(g1);
s.save(g1);
s.save(g2);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
+
s = openSession();
- List l = s.find("from Glarch g where g.next is not null");
+ s.beginTransaction();
+ List l = s.createQuery( "from Glarch g where g.next is not null" ).list();
s.delete( l.get(0) );
s.delete( l.get(1) );
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
}
public void testLazyCollections() throws Exception {
Session s = openSession();
+ s.beginTransaction();
Qux q = new Qux();
s.save(q);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
s = openSession();
+ s.beginTransaction();
q = (Qux) s.load( Qux.class, q.getKey() );
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
System.out.println("Two exceptions are supposed to occur:");
@@ -3772,52 +3897,55 @@
assertTrue( "lazy collection with many-to-many", ok );
s = openSession();
+ s.beginTransaction();
q = (Qux) s.load( Qux.class, q.getKey() );
s.delete(q);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
}
public void testNewSessionLifecycle() throws Exception {
Session s = openSession();
+ s.beginTransaction();
Serializable fid = null;
try {
Foo f = new Foo();
s.save(f);
fid = s.getIdentifier(f);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
}
catch (Exception e) {
- s.connection().rollback();
+ s.getTransaction().rollback();
throw e;
}
finally {
s.close();
}
+
s = openSession();
+ s.beginTransaction();
try {
Foo f = new Foo();
s.delete(f);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
}
catch (Exception e) {
- s.connection().rollback();
+ s.getTransaction().rollback();
}
finally {
s.close();
}
+
s = openSession();
+ s.beginTransaction();
try {
Foo f = (Foo) s.load(Foo.class, fid, LockMode.UPGRADE);
s.delete(f);
s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
}
catch (Exception e) {
- s.connection().rollback();
+ s.getTransaction().rollback();
throw e;
}
finally {
@@ -3827,50 +3955,56 @@
public void testDisconnect() throws Exception {
Session s = openSession();
+ s.beginTransaction();
Foo foo = new Foo();
Foo foo2 = new Foo();
s.save(foo);
s.save(foo2);
foo2.setFoo(foo);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
+
s.disconnect();
s.reconnect();
+
s.delete(foo);
foo2.setFoo(null);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
+
s.disconnect();
s.reconnect();
+
s.delete(foo2);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
}
public void testOrderBy() throws Exception {
-
Session s = openSession();
- Transaction tx = s.beginTransaction();
+ s.beginTransaction();
Foo foo = new Foo();
s.save(foo);
- List list = s.find("select foo from Foo foo, Fee fee where foo.dependent = fee order by foo.string desc, foo.component.count asc, fee.id");
+ List list = s.createQuery(
+ "select foo from Foo foo, Fee fee where foo.dependent = fee order by foo.string desc, foo.component.count asc, fee.id"
+ ).list();
assertTrue( "order by", list.size()==1 );
Foo foo2 = new Foo();
s.save(foo2);
foo.setFoo(foo2);
- list = s.find("select foo.foo, foo.dependent from Foo foo order by foo.foo.string desc, foo.component.count asc, foo.dependent.id");
+ list = s.createQuery(
+ "select foo.foo, foo.dependent from Foo foo order by foo.foo.string desc, foo.component.count asc, foo.dependent.id"
+ ).list();
assertTrue( "order by", list.size()==1 );
- list = s.find("select foo from Foo foo order by foo.dependent.id, foo.dependent.fi");
+ list = s.createQuery( "select foo from Foo foo order by foo.dependent.id, foo.dependent.fi" ).list();
assertTrue( "order by", list.size()==2 );
s.delete(foo);
s.delete(foo2);
- tx.commit();
+ s.getTransaction().commit();
s.close();
s = openSession();
+ s.beginTransaction();
Many manyB = new Many();
s.save(manyB);
One oneB = new One();
@@ -3883,63 +4017,30 @@
s.save(oneA);
oneA.setValue("a");
manyA.setOne(oneA);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
s = openSession();
- Iterator it = s.iterate(
- "SELECT one FROM " +
- One.class.getName() +
- " one ORDER BY one.value ASC"
- );
- int count = 0;
- while ( it.hasNext() ) {
- One one = (One)it.next();
- switch (count) {
- case 0:
- assertTrue("ordering failed", "a".equals(one.getValue()));
- break;
- case 1:
- assertTrue("ordering failed", "b".equals(one.getValue()));
- break;
- default:
- assertTrue("more than two elements", false);
- break;
- }
- count ++;
- }
- s.flush();
- s.connection().commit();
+ s.beginTransaction();
+ List results = s.createQuery( "SELECT one FROM " + One.class.getName() + " one ORDER BY one.value ASC" ).list();
+ assertEquals( 2, results.size() );
+ assertEquals( "'a' isn't first element", "a", ( (One) results.get(0) ).getValue() );
+ assertEquals( "'b' isn't second element", "b", ( (One) results.get(2) ).getValue() );
+ s.getTransaction().commit();
s.close();
s = openSession();
- it = s.iterate(
- "SELECT many.one FROM " +
- Many.class.getName() +
- " many ORDER BY many.one.value ASC, many.one.id"
- );
- count = 0;
- while ( it.hasNext() ) {
- One one = (One)it.next();
- switch (count) {
- case 0:
- assertTrue("'a' isn't first element", "a".equals(one.getValue()));
- break;
- case 1:
- assertTrue("'b' isn't second element", "b".equals(one.getValue()));
- break;
- default:
- assertTrue("more than two elements", false);
- break;
- }
- count ++;
- }
- s.flush();
- s.connection().commit();
+ results = s.createQuery( "SELECT many.one FROM " + Many.class.getName() + " many ORDER BY many.one.value ASC, many.one.id" )
+ .list();
+ assertEquals( 2, results.size() );
+ assertEquals( 2, results.size() );
+ assertEquals( "'a' isn't first element", "a", ( (One) results.get(0) ).getValue() );
+ assertEquals( "'b' isn't second element", "b", ( (One) results.get(2) ).getValue() );
+ s.getTransaction().commit();
s.close();
s = openSession();
+ s.beginTransaction();
oneA = (One)s.load(One.class, oneA.getKey());
manyA = (Many)s.load(Many.class, manyA.getKey());
oneB = (One)s.load(One.class, oneB.getKey());
@@ -3948,90 +4049,57 @@
s.delete(oneA);
s.delete(manyB);
s.delete(oneB);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
}
public void testManyToOne() throws Exception {
Session s = openSession();
+ s.beginTransaction();
One one = new One();
s.save(one);
one.setValue("yada");
Many many = new Many();
many.setOne(one);
s.save(many);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
s = openSession();
+ s.beginTransaction();
one = (One) s.load( One.class, one.getKey() );
one.getManies().size();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
-
s = openSession();
+ s.beginTransaction();
many = (Many) s.load( Many.class, many.getKey() );
assertTrue( "many-to-one assoc", many.getOne()!=null );
s.delete( many.getOne() );
s.delete(many);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
}
public void testSaveDelete() throws Exception {
Session s = openSession();
+ s.beginTransaction();
Foo f = new Foo();
s.save(f);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
s = openSession();
+ s.beginTransaction();
s.delete( s.load( Foo.class, f.getKey() ) );
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
}
- /*public void testIdNotFound() throws Exception {
- // The following test is only enabled for MySQL which has no foreign key constraints.
- // I disabled this test cos it didn't clean up after itself so other tests failed
- if (db.equals("mysql")) {
- Session s = sessionsopenSession();
- Glarch g = (Glarch) s.create(Glarch.class);
- Glarch g2 = (Glarch) s.create(Glarch.class);
- g.setNext(g2);
- Serializable gid = s.getID(g);
- Serializable g2id = s.getID(g2);
- s.commit();
-
- s = sessionsopenSession();
- g2 = (Glarch) s.load( Glarch.class, g2id );
- s.delete(g2);
- s.commit();
-
- s = sessionsopenSession();
- boolean ok = false;
- try {
- g = (Glarch) s.load( Glarch.class, gid );
- }
- catch (HibernateException e) {
- ok = "id not found or provided object was wrong class".equals(e.getMessage());
- }
- catch (java.lang.StackOverflowError soe) {
- ok = false;
- }
- assertTrue( ok, "id not found");
- s.cancel();
- }
- }*/
-
public void testProxyArray() throws Exception {
Session s = openSession();
+ s.beginTransaction();
GlarchProxy g = new Glarch();
Glarch g1 = new Glarch();
Glarch g2 = new Glarch();
@@ -4047,25 +4115,23 @@
s.save(g1);
s.save(g2);
Serializable id = s.getIdentifier(g);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
s = openSession();
+ s.beginTransaction();
g = (GlarchProxy) s.load(Glarch.class, id);
assertTrue( "array of proxies", g.getProxyArray().length==2 );
assertTrue( "array of proxies", g.getProxyArray()[0]!=null );
assertTrue("deferred load test",g.getProxyArray()[1].getProxyArray()[0]==null );
assertTrue("deferred load test",g.getProxyArray()[1].getProxyArray()[2]==g );
assertTrue( "set of proxies", g.getProxySet().size()==2 );
- Iterator iter = s.iterate("from Glarch g");
+ Iterator iter = s.createQuery( "from Glarch g" ).iterate();
while ( iter.hasNext() ) {
iter.next();
iter.remove();
}
-
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.disconnect();
SerializationHelper.deserialize( SerializationHelper.serialize(s) );
s.close();
@@ -4073,57 +4139,60 @@
public void testCache() throws Exception {
Session s = openSession();
+ s.beginTransaction();
Immutable im = new Immutable();
s.save(im);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
+
s = openSession();
+ s.beginTransaction();
s.load( im, im.getId() );
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
+
s = openSession();
+ s.beginTransaction();
s.load( im, im.getId() );
- assertTrue(
- "cached object identity",
- s.find(
- "from Immutable im where im = ?",
+ assertEquals(
+ "cached object identity",
im,
- Hibernate.entity(Immutable.class)
- ).get(0)==im &&
- im == s.load( Immutable.class, im.getId() )
+ s.createQuery( "from Immutable im where im = ?" ).setParameter( 0, im, Hibernate.entity(Immutable.class) ).uniqueResult()
);
s.connection().createStatement().executeUpdate("delete from immut");
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
}
public void testFindLoad() throws Exception {
Session s = openSession();
+ s.beginTransaction();
FooProxy foo = new Foo();
s.save(foo);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
+
s = openSession();
- foo = (FooProxy) s.find("from Foo foo").get(0);
+ s.beginTransaction();
+ foo = (FooProxy) s.createQuery( "from Foo foo" ).list().get(0);
FooProxy foo2 = (FooProxy) s.load( Foo.class, foo.getKey() );
assertTrue("find returns same object as load", foo==foo2);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
+
s = openSession();
+ s.beginTransaction();
foo2 = (FooProxy) s.load( Foo.class, foo.getKey() );
- foo = (FooProxy) s.find("from Foo foo").get(0);
+ foo = (FooProxy) s.createQuery( "from Foo foo" ).list().get(0);
assertTrue("find returns same object as load", foo==foo2);
- s.delete("from Foo foo");
- s.flush();
- s.connection().commit();
+ doDelete( s, "from Foo foo" );
+ s.getTransaction().commit();
s.close();
}
public void testRefresh() throws Exception {
Session s = openSession();
+ s.beginTransaction();
Foo foo = new Foo();
s.save(foo);
s.flush();
@@ -4136,8 +4205,7 @@
assertTrue( s.getCurrentLockMode(foo)==LockMode.UPGRADE );
}
s.delete(foo);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
}
@@ -4146,9 +4214,9 @@
Transaction txn = s.beginTransaction();
FooProxy foo = new Foo();
s.save(foo);
- assertTrue( "autoflush create", s.find("from Foo foo").size()==1 );
+ assertTrue( "autoflush create", s.createQuery( "from Foo foo" ).list().size()==1 );
foo.setChar( new Character('X') );
- assertTrue( "autoflush update", s.find("from Foo foo where foo.char='X'").size()==1 );
+ assertTrue( "autoflush update", s.createQuery( "from Foo foo where foo.char='X'" ).list().size()==1 );
txn.commit();
s.close();
@@ -4159,46 +4227,52 @@
//assertTrue( s.find("from Foo foo where not foo.char='X'").size()==1, "autoflush update" );
if ( !(getDialect() instanceof MySQLDialect) && !(getDialect() instanceof HSQLDialect) && !(getDialect() instanceof PointbaseDialect) ) {
foo.setBytes( "osama".getBytes() );
- assertTrue( "autoflush collection update", s.find("from Foo foo where 111 in elements(foo.bytes)").size()==1 );
+ assertTrue( "autoflush collection update",
+ s.createQuery( "from Foo foo where 111 in elements(foo.bytes)" ).list().size()==1 );
foo.getBytes()[0] = 69;
- assertTrue( "autoflush collection update", s.find("from Foo foo where 69 in elements(foo.bytes)").size()==1 );
+ assertTrue( "autoflush collection update",
+ s.createQuery( "from Foo foo where 69 in elements(foo.bytes)" ).list()
+ .size()==1 );
}
s.delete(foo);
- assertTrue( "autoflush delete", s.find("from Foo foo").size()==0 );
+ assertTrue( "autoflush delete", s.createQuery( "from Foo foo" ).list().size()==0 );
txn.commit();
s.close();
}
public void testVeto() throws Exception {
Session s = openSession();
+ s.beginTransaction();
Vetoer v = new Vetoer();
s.save(v); Serializable id = s.save(v);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
s = openSession();
- s.update(v, id); s.update(v, id);
- s.delete(v); s.delete(v);
- s.flush();
- s.connection().commit();
+ s.update(v, id);
+ s.update(v, id);
+ s.delete(v);
+ s.delete(v);
+ s.getTransaction().commit();
s.close();
}
public void testSerializableType() throws Exception {
Session s = openSession();
+ s.beginTransaction();
Vetoer v = new Vetoer();
v.setStrings( new String[] { "foo", "bar", "baz" } );
s.save(v); Serializable id = s.save(v);
v.getStrings()[1] = "osama";
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
+
s = openSession();
+ s.beginTransaction();
v = (Vetoer) s.load(Vetoer.class, id);
assertTrue( "serializable type", v.getStrings()[1].equals("osama") );
s.delete(v); s.delete(v);
s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
}
@@ -4215,17 +4289,17 @@
tx = s.beginTransaction();
baz = (Baz) s.load(Baz.class, baz.getCode());
baz.getStringArray()[0] = "bark";
- Iterator i = s.iterate("select elements(baz.stringArray) from Baz baz");
+ Iterator i = s.createQuery( "select elements(baz.stringArray) from Baz baz" ).iterate();
boolean found = false;
while ( i.hasNext() ) {
if ( "bark".equals( i.next() ) ) found = true;
}
assertTrue(found);
baz.setStringArray(null);
- i = s.iterate("select distinct elements(baz.stringArray) from Baz baz");
+ i = s.createQuery( "select distinct elements(baz.stringArray) from Baz baz" ).iterate();
assertTrue( !i.hasNext() );
baz.setStringArray( new String[] { "foo", "bar" } );
- i = s.iterate("select elements(baz.stringArray) from Baz baz");
+ i = s.createQuery( "select elements(baz.stringArray) from Baz baz" ).iterate();
assertTrue( i.hasNext() );
Foo foo = new Foo();
@@ -4233,7 +4307,7 @@
s.flush();
baz.setFooArray( new Foo[] {foo} );
- i = s.iterate("select foo from Baz baz join baz.fooArray foo");
+ i = s.createQuery( "select foo from Baz baz join baz.fooArray foo" ).iterate();
found = false;
while ( i.hasNext() ) {
if ( foo==i.next() ) found = true;
@@ -4241,31 +4315,31 @@
assertTrue(found);
baz.getFooArray()[0] = null;
- i = s.iterate("select foo from Baz baz join baz.fooArray foo");
+ i = s.createQuery( "select foo from Baz baz join baz.fooArray foo" ).iterate();
assertTrue( !i.hasNext() );
baz.getFooArray()[0] = foo;
- i = s.iterate("select elements(baz.fooArray) from Baz baz");
+ i = s.createQuery( "select elements(baz.fooArray) from Baz baz" ).iterate();
assertTrue( i.hasNext() );
- if ( !(getDialect() instanceof MySQLDialect) && !(getDialect() instanceof HSQLDialect) && !(getDialect() instanceof InterbaseDialect) && !(getDialect() instanceof PointbaseDialect) && !(getDialect() instanceof SAPDBDialect) ) {
+ if ( !(getDialect() instanceof MySQLDialect)
+ && !(getDialect() instanceof HSQLDialect)
+ && !(getDialect() instanceof InterbaseDialect)
+ && !(getDialect() instanceof PointbaseDialect)
+ && !(getDialect() instanceof SAPDBDialect) ) {
baz.getFooArray()[0] = null;
- i = s.iterate(
- "from Baz baz where ? in elements(baz.fooArray)",
- foo, Hibernate.entity(Foo.class)
- );
+ i = s.createQuery( "from Baz baz where ? in elements(baz.fooArray)" )
+ .setParameter( 0, foo, Hibernate.entity( Foo.class ) )
+ .iterate();
assertTrue( !i.hasNext() );
baz.getFooArray()[0] = foo;
- i = s.iterate(
- "select foo from Foo foo where foo in "
- + "(select elt from Baz baz join baz.fooArray elt)"
- );
+ i = s.createQuery( "select foo from Foo foo where foo in (select elt from Baz baz join baz.fooArray elt)" )
+ .iterate();
assertTrue( i.hasNext() );
}
s.delete(foo);
s.delete(baz);
tx.commit();
s.close();
-
}
public void testUserProvidedConnection() throws Exception {
@@ -4273,13 +4347,13 @@
dcp.configure( Environment.getProperties() );
Session s = getSessions().openSession( dcp.getConnection() );
Transaction tx = s.beginTransaction();
- s.find("from Fo");
+ s.createQuery( "from Fo" ).list();
tx.commit();
Connection c = s.disconnect();
assertTrue( c!=null );
s.reconnect(c);
tx = s.beginTransaction();
- s.find("from Fo");
+ s.createQuery( "from Fo" ).list();
tx.commit();
assertTrue( s.close()==c );
c.close();
@@ -4287,24 +4361,26 @@
public void testCachedCollection() throws Exception {
Session s = openSession();
+ s.beginTransaction();
Baz baz = new Baz();
baz.setDefaults();
s.save(baz);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
+
s = openSession();
+ s.beginTransaction();
baz = (Baz) s.load( Baz.class, baz.getCode() );
( (FooComponent) baz.getTopComponents().get(0) ).setCount(99);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
+
s = openSession();
+ s.beginTransaction();
baz = (Baz) s.load( Baz.class, baz.getCode() );
assertTrue( ( (FooComponent) baz.getTopComponents().get(0) ).getCount()==99 );
s.delete(baz);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
}
@@ -4321,7 +4397,7 @@
//s.flush();
//s.connection().commit();
assertTrue(
- s.iterate("from Foo foo where foo.dependent.qux.foo.string = 'foo2'").hasNext()
+ s.createQuery( "from Foo foo where foo.dependent.qux.foo.string = 'foo2'" ).iterate().hasNext()
);
s.delete(foo);
txn.commit();
@@ -4330,6 +4406,7 @@
public void testLoadAfterDelete() throws Exception {
Session s = openSession();
+ s.beginTransaction();
Foo foo = new Foo();
Serializable id = s.save(foo);
s.flush();
@@ -4373,67 +4450,69 @@
err=true;
}
assertTrue(err);
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
}
public void testObjectType() throws Exception {
Session s = openSession();
+ s.beginTransaction();
GlarchProxy g = new Glarch();
Foo foo = new Foo();
g.setAny(foo);
Serializable gid = s.save(g);
s.save(foo);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
+
s = openSession();
+ s.beginTransaction();
g = (GlarchProxy) s.load(Glarch.class, gid);
assertTrue( g.getAny()!=null && g.getAny() instanceof FooProxy );
s.delete( g.getAny() );
s.delete(g);
- //s.delete( g.getAny() );
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
}
public void testAny() throws Exception {
Session s = openSession();
+ s.beginTransaction();
One one = new One();
BarProxy foo = new Bar();
foo.setObject(one);
- //Serializable oid = s.save(one);
Serializable fid = s.save(foo);
Serializable oid = one.getKey();
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
+
s = openSession();
- assertTrue( s.find(
- "from Bar bar where bar.object.id = ? and bar.object.class = ?",
- new Object[] { oid, new Character('O') },
- new Type[] { Hibernate.LONG, Hibernate.CHARACTER }
- ).size()==1 );
- assertTrue( s.find(
- "select one from One one, Bar bar where bar.object.id = one.id and bar.object.class = 'O'"
- ).size()==1 );
- s.flush();
- s.connection().commit();
+ s.beginTransaction();
+ List results = s.createQuery( "from Bar bar where bar.object.id = ? and bar.object.class = ?" )
+ .setParameter( 0, oid, Hibernate.LONG )
+ .setParameter( 1, new Character('O'), Hibernate.CHARACTER )
+ .list();
+ assertEquals( 1, results.size() );
+ results = s.createQuery( "select one from One one, Bar bar where bar.object.id = one.id and bar.object.class = 'O'" )
+ .list();
+ assertEquals( 1, results.size() );
+ s.getTransaction().commit();
s.close();
+
s = openSession();
+ s.beginTransaction();
foo = (BarProxy) s.load(Foo.class, fid);
assertTrue( foo.getObject()!=null && foo.getObject() instanceof One && s.getIdentifier( foo.getObject() ).equals(oid) );
//s.delete( foo.getObject() );
s.delete(foo);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
}
public void testEmbeddedCompositeID() throws Exception {
Session s = openSession();
+ s.beginTransaction();
Location l = new Location();
l.setCountryCode("AU");
l.setDescription("foo bar");
@@ -4442,26 +4521,31 @@
l.setStreetNumber(300);
l.setCity("Melbourne");
s.save(l);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
+
s = openSession();
+ s.beginTransaction();
s.setFlushMode(FlushMode.MANUAL);
- l = (Location) s.find("from Location l where l.countryCode = 'AU' and l.description='foo bar'").get(0);
+ l = (Location) s.createQuery( "from Location l where l.countryCode = 'AU' and l.description='foo bar'" )
+ .list()
+ .get(0);
assertTrue( l.getCountryCode().equals("AU") );
assertTrue( l.getCity().equals("Melbourne") );
assertTrue( l.getLocale().equals( Locale.getDefault() ) );
assertTrue( s.createCriteria(Location.class).add( Restrictions.eq( "streetNumber", new Integer(300) ) ).list().size()==1 );
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
s = openSession();
+ s.beginTransaction();
l.setDescription("sick're");
s.update(l);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
+
s = openSession();
+ s.beginTransaction();
l = new Location();
l.setCountryCode("AU");
l.setDescription("foo bar");
@@ -4472,8 +4556,7 @@
assertTrue( l==s.load(Location.class, l) );
assertTrue( l.getLocale().equals( Locale.getDefault() ) );
s.delete(l);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
}
@@ -4502,7 +4585,7 @@
assertTrue( baz.getCascadingBars().iterator().next()!=null );
baz.getCascadingBars().clear(); //test all-delete-orphan;
s.flush();
- assertTrue( s.find("from Bar bar").size()==0 );
+ assertTrue( s.createQuery( "from Bar bar" ).list().size()==0 );
s.delete(baz);
t.commit();
s.close();
@@ -4528,7 +4611,7 @@
bars = baz.getCascadingBars();
assertEquals( 4, bars.size() );
bars.remove( bars.iterator().next() );
- assertEquals( 3, s.find("From Bar bar").size() );
+ assertEquals( 3, s.createQuery( "From Bar bar" ).list().size() );
t.commit();
s.close();
@@ -4540,7 +4623,7 @@
bars.remove( bars.iterator().next() );
s.delete(baz);
bars.remove( bars.iterator().next() );
- assertEquals( 0, s.find("From Bar bar").size() );
+ assertEquals( 0, s.createQuery( "From Bar bar" ).list().size() );
t.commit();
s.close();
@@ -4574,8 +4657,8 @@
s = openSession();
t = s.beginTransaction();
s.update(baz);
- assertEquals( 2, s.find("From Bar bar").size() );
- assertEquals( 3, s.find("From Foo foo").size() );
+ assertEquals( 2, s.createQuery( "From Bar bar" ).list().size() );
+ assertEquals( 3, s.createQuery( "From Foo foo" ).list().size() );
t.commit();
s.close();
@@ -4584,10 +4667,10 @@
t = s.beginTransaction();
s.update(baz);
bars.remove( bars.iterator().next() );
- assertEquals( 1, s.find("From Foo foo").size() );
+ assertEquals( 1, s.createQuery( "From Foo foo" ).list().size() );
s.delete(baz);
//s.flush();
- assertEquals( 0, s.find("From Foo foo").size() );
+ assertEquals( 0, s.createQuery( "From Foo foo" ).list().size() );
t.commit();
s.close();
@@ -4595,6 +4678,7 @@
public void testProxiesInCollections() throws Exception {
Session s = openSession();
+ s.beginTransaction();
Baz baz = new Baz();
Bar bar = new Bar();
Bar bar2 = new Bar();
@@ -4615,11 +4699,11 @@
baz.setFooBag(list);
Serializable id = s.save(baz);
Serializable bid = ( (Bar) baz.getCascadingBars().iterator().next() ).getKey();
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
s = openSession();
+ s.beginTransaction();
BarProxy barprox = (BarProxy) s.load(Bar.class, bid);
BarProxy bar2prox = (BarProxy) s.load(Bar.class, bar2id);
assertTrue(bar2prox instanceof HibernateProxy);
@@ -4633,10 +4717,9 @@
assertTrue( baz.getFooArray()[1]==bar2prox );
if ( !isOuterJoinFetchingDisabled() ) assertTrue( !(baz.getFooBag().iterator().next() instanceof HibernateProxy) ); //many-to-many outer-join="true"
assertTrue( !(baz.getFooSet().iterator().next() instanceof HibernateProxy) ); //one-to-many
- s.delete("from Baz");
- s.delete("from Foo");
- s.flush();
- s.connection().commit();
+ doDelete( s, "from Baz" );
+ doDelete( s, "from Foo" );
+ s.getTransaction().commit();
s.close();
}
@@ -4665,7 +4748,7 @@
assertTrue( q.list().size()==10 );
q.setMaxResults(5);
assertTrue( q.list().size()==5 );
- s.delete("from Foo");
+ doDelete( s, "from Foo" );
txn.commit();
s.close();
Modified: core/trunk/testsuite/src/test/java/org/hibernate/test/legacy/FumTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/legacy/FumTest.java 2009-05-11 21:12:30 UTC (rev 16535)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/legacy/FumTest.java 2009-05-11 21:13:36 UTC (rev 16536)
@@ -95,6 +95,7 @@
public void testCriteriaCollection() throws Exception {
Session s = openSession();
+ s.beginTransaction();
Fum fum = new Fum( fumKey("fum") );
fum.setFum("a value");
fum.getMapComponent().getFummap().put("self", fum);
@@ -102,10 +103,11 @@
fum.getMapComponent().getStringmap().put("string2", "a notha staring");
fum.getMapComponent().setCount(1);
s.save(fum);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
+
s = openSession();
+ s.beginTransaction();
Fum b = (Fum) s.createCriteria(Fum.class).add(
Restrictions.in("fum", new String[] { "a value", "no value" } )
)
@@ -114,8 +116,7 @@
assertTrue( b.getMapComponent().getFummap().size()==1 );
assertTrue( b.getMapComponent().getStringmap().size()==2 );
s.delete(b);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
}
@@ -166,7 +167,7 @@
base = s.createCriteria(Fum.class)
.add( Restrictions.like("fum", "f%") )
.setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP)
- .setFetchMode("friends", FetchMode.EAGER);
+ .setFetchMode( "friends", FetchMode.JOIN );
base.createCriteria("fo", "fo")
.add( Restrictions.eq( "fum", fum.getFo().getFum() ) );
map = (Map) base.list().get(0);
@@ -203,7 +204,9 @@
s.delete(fum);
s.delete( fum.getFo() );
Iterator iter = fum.getFriends().iterator();
- while ( iter.hasNext() ) s.delete( iter.next() );
+ while ( iter.hasNext() ) {
+ s.delete( iter.next() );
+ }
txn.commit();
s.close();
}
@@ -226,7 +229,6 @@
}
public void testBeanResultTransformer() throws HibernateException, SQLException {
-
Session s = openSession();
Transaction transaction = s.beginTransaction();
Fum fum = new Fum( fumKey("fum") );
@@ -271,7 +273,6 @@
s.flush();
transaction.commit();
s.close();
-
}
@@ -284,9 +285,9 @@
fum = new Fum( fumKey("fi") );
fum.setFum("fee fi fo");
s.save(fum);
- List list = s.find("select fum.id from Fum as fum where not fum.fum='FRIEND'");
+ List list = s.createQuery( "select fum.id from Fum as fum where not fum.fum='FRIEND'" ).list();
assertTrue( "list identifiers", list.size()==2);
- Iterator iter = s.iterate("select fum.id from Fum fum where not fum.fum='FRIEND'");
+ Iterator iter = s.createQuery( "select fum.id from Fum fum where not fum.fum='FRIEND'" ).iterate();
int i=0;
while ( iter.hasNext() ) {
assertTrue( "iterate identifiers", iter.next() instanceof FumCompositeID);
@@ -302,7 +303,6 @@
public FumCompositeID fumKey(String str) {
-
return fumKey(str,false);
}
@@ -320,7 +320,7 @@
else {
id.setDate( new Date() );
}
- id.setString( new String(str) );
+ id.setString( str );
if (aCompositeQueryTest) {
id.setShort( fumKeyShort++ );
@@ -353,11 +353,11 @@
s.save(fum2);
assertTrue(
"find composite keyed objects",
- s.find("from Fum fum where not fum.fum='FRIEND'").size()==2
+ s.createQuery( "from Fum fum where not fum.fum='FRIEND'" ).list().size()==2
);
assertTrue(
"find composite keyed object",
- s.find("select fum from Fum fum where fum.fum='fee fi fo'").get(0)==fum
+ s.createQuery( "select fum from Fum fum where fum.fum='fee fi fo'" ).list().get(0)==fum
);
fum.setFo(null);
txn.commit();
@@ -365,7 +365,7 @@
s = openSession();
txn = s.beginTransaction();
- Iterator iter = s.iterate("from Fum fum where not fum.fum='FRIEND'");
+ Iterator iter = s.createQuery( "from Fum fum where not fum.fum='FRIEND'" ).iterate();
int i = 0;
while ( iter.hasNext() ) {
fum = (Fum) iter.next();
@@ -401,6 +401,7 @@
public void testCompositeIDQuery() throws Exception {
Session s = openSession();
+ s.beginTransaction();
Fum fee = new Fum( fumKey("fee",true) );
fee.setFum("fee");
s.save(fee);
@@ -414,38 +415,40 @@
Fum fum = new Fum( fumKey("fum",true) );
fum.setFum("fum");
s.save(fum);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
s = openSession();
+ s.beginTransaction();
// Try to find the Fum object "fo" that we inserted searching by the string in the id
- List vList = s.find("from Fum fum where fum.id.string='fo'" );
+ List vList = s.createQuery( "from Fum fum where fum.id.string='fo'" ).list();
assertTrue( "find by composite key query (find fo object)", vList.size() == 1 );
fum = (Fum)vList.get(0);
assertTrue( "find by composite key query (check fo object)", fum.getId().getString().equals("fo") );
// Try to find the Fum object "fi" that we inserted searching by the date in the id
- vList = s.find("from Fum fum where fum.id.short = ?",new Short(fiShort),Hibernate.SHORT);
- assertTrue( "find by composite key query (find fi object)", vList.size() == 1 );
+ vList = s.createQuery( "from Fum fum where fum.id.short = ?" )
+ .setParameter( 0, new Short(fiShort), Hibernate.SHORT )
+ .list();
+ assertEquals( "find by composite key query (find fi object)", 1, vList.size() );
fi = (Fum)vList.get(0);
- assertTrue( "find by composite key query (check fi object)", fi.getId().getString().equals("fi") );
+ assertEquals( "find by composite key query (check fi object)", "fi", fi.getId().getString() );
// Make sure we can return all of the objects by searching by the date id
- assertTrue(
- "find by composite key query with arguments",
- s.find("from Fum fum where fum.id.date <= ? and not fum.fum='FRIEND'",new Date(),Hibernate.DATE).size()==4
- );
- s.flush();
- s.connection().commit();
+ vList = s.createQuery( "from Fum fum where fum.id.date <= ? and not fum.fum='FRIEND'" )
+ .setParameter( 0, new Date(), Hibernate.DATE )
+ .list();
+ assertEquals( "find by composite key query with arguments", 4, vList.size() );
+ s.getTransaction().commit();
s.close();
s = openSession();
+ s.beginTransaction();
assertTrue(
- s.iterate("select fum.id.short, fum.id.date, fum.id.string from Fum fum").hasNext()
+ s.createQuery( "select fum.id.short, fum.id.date, fum.id.string from Fum fum" ).iterate().hasNext()
);
assertTrue(
- s.iterate("select fum.id from Fum fum").hasNext()
+ s.createQuery( "select fum.id from Fum fum" ).iterate().hasNext()
);
Query qu = s.createQuery("select fum.fum, fum , fum.fum, fum.id.date from Fum fum");
Type[] types = qu.getReturnTypes();
@@ -466,34 +469,36 @@
assertTrue( "iterate on composite key", j==8 );
fum = (Fum) s.load( Fum.class, fum.getId() );
- s.filter( fum.getQuxArray(), "where this.foo is null" );
- s.filter( fum.getQuxArray(), "where this.foo.id = ?", "fooid", Hibernate.STRING );
+ s.createFilter( fum.getQuxArray(), "where this.foo is null" ).list();
+ s.createFilter( fum.getQuxArray(), "where this.foo.id = ?" )
+ .setParameter( 0, "fooid", Hibernate.STRING )
+ .list();
Query f = s.createFilter( fum.getQuxArray(), "where this.foo.id = :fooId" );
f.setString("fooId", "abc");
assertFalse( f.iterate().hasNext() );
- iter = s.iterate("from Fum fum where not fum.fum='FRIEND'");
+ iter = s.createQuery( "from Fum fum where not fum.fum='FRIEND'" ).iterate();
int i = 0;
while ( iter.hasNext() ) {
fum = (Fum) iter.next();
- //iter.remove();
s.delete(fum);
i++;
}
assertTrue( "iterate on composite key", i==4 );
s.flush();
- s.iterate("from Fum fu, Fum fo where fu.fo.id.string = fo.id.string and fo.fum is not null");
+ s.createQuery( "from Fum fu, Fum fo where fu.fo.id.string = fo.id.string and fo.fum is not null" ).iterate();
- s.find("from Fumm f1 inner join f1.fum f2");
+ s.createQuery( "from Fumm f1 inner join f1.fum f2" ).list();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
}
public void testCompositeIDCollections() throws Exception {
Session s = openSession();
+ s.beginTransaction();
Fum fum1 = new Fum( fumKey("fum1") );
Fum fum2 = new Fum( fumKey("fum2") );
fum1.setFum("fee fo fi");
@@ -509,11 +514,11 @@
q.setFums(set);
q.setMoreFums(list);
fum1.setQuxArray( new Qux[] {q} );
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
s = openSession();
+ s.beginTransaction();
q = (Qux) s.load( Qux.class, q.getKey() );
assertTrue( "collection of fums", q.getFums().size()==2 );
assertTrue( "collection of fums", q.getMoreFums().size()==1 );
@@ -526,14 +531,14 @@
f = (Fum) iter.next();
s.delete(f);
s.delete(q);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
}
public void testDeleteOwner() throws Exception {
Session s = openSession();
+ s.beginTransaction();
Qux q = new Qux();
s.save(q);
Fum f1 = new Fum( fumKey("f1") );
@@ -550,20 +555,20 @@
q.setMoreFums(list);
s.save(f1);
s.save(f2);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
s = openSession();
+ s.beginTransaction();
q = (Qux) s.load( Qux.class, q.getKey(), LockMode.UPGRADE );
s.lock( q, LockMode.UPGRADE );
s.delete(q);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
s = openSession();
- list = s.find("from Fum fum where not fum.fum='FRIEND'");
+ s.beginTransaction();
+ list = s.createQuery( "from Fum fum where not fum.fum='FRIEND'" ).list();
assertTrue( "deleted owner", list.size()==2 );
s.lock( list.get(0), LockMode.UPGRADE );
s.lock( list.get(1), LockMode.UPGRADE );
@@ -571,14 +576,14 @@
while ( iter.hasNext() ) {
s.delete( iter.next() );
}
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
}
public void testCompositeIDs() throws Exception {
Session s = openSession();
+ s.beginTransaction();
Fo fo = Fo.newFo();
Properties props = new Properties();
props.setProperty("foo", "bar");
@@ -588,11 +593,11 @@
s.save( fo, fumKey("an instance of fo") );
s.flush();
props.setProperty("x", "y");
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
s = openSession();
+ s.beginTransaction();
fo = (Fo) s.load( Fo.class, fumKey("an instance of fo") );
props = (Properties) fo.getSerial();
assertTrue( props.getProperty("foo").equals("bar") );
@@ -600,15 +605,15 @@
assertTrue( props.getProperty("x").equals("y") );
assertTrue( fo.getBuf()[0]=='a' );
fo.getBuf()[1]=(byte)126;
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
s = openSession();
+ s.beginTransaction();
fo = (Fo) s.load( Fo.class, fumKey("an instance of fo") );
assertTrue( fo.getBuf()[1]==126 );
assertTrue(
- s.iterate("from Fo fo where fo.id.string like 'an instance of fo'").next()==fo
+ s.createQuery( "from Fo fo where fo.id.string like 'an instance of fo'" ).iterate().next()==fo
);
s.delete(fo);
s.flush();
@@ -619,12 +624,13 @@
catch (Exception e) {
//System.out.println( e.getMessage() );
}
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
}
public void testKeyManyToOne() throws Exception {
Session s = openSession();
+ s.beginTransaction();
Inner sup = new Inner();
InnerKey sid = new InnerKey();
sup.setDudu("dudu");
@@ -647,75 +653,84 @@
s.save(sup);
s.save(m);
s.save(d);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
s = openSession();
- Inner in = (Inner) s.find("from Inner").get(0);
+ s.beginTransaction();
+ Inner in = (Inner) s.createQuery( "from Inner" ).list().get(0);
assertTrue( in.getMiddles().size()==1 );
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
+
s = openSession();
- assertTrue( s.find("from Inner _inner join _inner.middles middle").size()==1 );
- s.flush();
- s.connection().commit();
+ s.beginTransaction();
+ assertTrue( s.createQuery( "from Inner _inner join _inner.middles middle" ).list().size()==1 );
+ s.getTransaction().commit();
s.close();
s = openSession();
+ s.beginTransaction();
d = (Outer) s.load(Outer.class, did);
assertTrue( d.getId().getMaster().getId().getSup().getDudu().equals("dudu") );
s.delete(d);
s.delete( d.getId().getMaster() );
s.save( d.getId().getMaster() );
s.save(d);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
s = openSession();
- d = (Outer) s.find("from Outer o where o.id.detailId = ?", d.getId().getDetailId(), Hibernate.STRING ).get(0);
- s.find("from Outer o where o.id.master.id.sup.dudu is not null");
- s.find("from Outer o where o.id.master.id.sup.id.akey is not null");
- s.find("from Inner i where i.backOut.id.master.id.sup.id.akey = i.id.bkey");
- List l = s.find("select o.id.master.id.sup.dudu from Outer o where o.id.master.id.sup.dudu is not null");
+ s.beginTransaction();
+ d = (Outer) s.createQuery( "from Outer o where o.id.detailId = ?" )
+ .setParameter( 0, d.getId().getDetailId(), Hibernate.STRING )
+ .list()
+ .get(0);
+ s.createQuery( "from Outer o where o.id.master.id.sup.dudu is not null" ).list();
+ s.createQuery( "from Outer o where o.id.master.id.sup.id.akey is not null" ).list();
+ s.createQuery( "from Inner i where i.backOut.id.master.id.sup.id.akey = i.id.bkey" ).list();
+ List l = s.createQuery( "select o.id.master.id.sup.dudu from Outer o where o.id.master.id.sup.dudu is not null" )
+ .list();
assertTrue(l.size()==1);
- l = s.find("select o.id.master.id.sup.id.akey from Outer o where o.id.master.id.sup.id.akey is not null");
+ l = s.createQuery( "select o.id.master.id.sup.id.akey from Outer o where o.id.master.id.sup.id.akey is not null" )
+ .list();
assertTrue(l.size()==1);
- s.find("select i.backOut.id.master.id.sup.id.akey from Inner i where i.backOut.id.master.id.sup.id.akey = i.id.bkey");
- s.find("from Outer o where o.id.master.bla = ''");
- s.find("from Outer o where o.id.master.id.one = ''");
- s.find("from Inner inn where inn.id.bkey is not null and inn.backOut.id.master.id.sup.id.akey > 'a'");
- s.find("from Outer as o left join o.id.master m left join m.id.sup where o.bubu is not null");
- s.find("from Outer as o left join o.id.master.id.sup s where o.bubu is not null");
- s.find("from Outer as o left join o.id.master m left join o.id.master.id.sup s where o.bubu is not null");
+ s.createQuery(
+ "select i.backOut.id.master.id.sup.id.akey from Inner i where i.backOut.id.master.id.sup.id.akey = i.id.bkey"
+ ).list();
+ s.createQuery( "from Outer o where o.id.master.bla = ''" ).list();
+ s.createQuery( "from Outer o where o.id.master.id.one = ''" ).list();
+ s.createQuery( "from Inner inn where inn.id.bkey is not null and inn.backOut.id.master.id.sup.id.akey > 'a'" )
+ .list();
+ s.createQuery( "from Outer as o left join o.id.master m left join m.id.sup where o.bubu is not null" ).list();
+ s.createQuery( "from Outer as o left join o.id.master.id.sup s where o.bubu is not null" ).list();
+ s.createQuery( "from Outer as o left join o.id.master m left join o.id.master.id.sup s where o.bubu is not null" )
+ .list();
s.delete(d);
s.delete( d.getId().getMaster() );
s.delete( d.getId().getMaster().getId().getSup() );
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
}
public void testCompositeKeyPathExpressions() throws Exception {
Session s = openSession();
- s.find("select fum1.fo from Fum fum1 where fum1.fo.fum is not null");
- s.find("from Fum fum1 where fum1.fo.fum is not null order by fum1.fo.fum");
+ s.beginTransaction();
+ s.createQuery( "select fum1.fo from Fum fum1 where fum1.fo.fum is not null" ).list();
+ s.createQuery( "from Fum fum1 where fum1.fo.fum is not null order by fum1.fo.fum" ).list();
if ( !(getDialect() instanceof MySQLDialect) && !(getDialect() instanceof HSQLDialect) && !(getDialect() instanceof MckoiDialect) && !(getDialect() instanceof PointbaseDialect) ) {
- s.find("from Fum fum1 where exists elements(fum1.friends)");
+ s.createQuery( "from Fum fum1 where exists elements(fum1.friends)" ).list();
if(!(getDialect() instanceof TimesTenDialect)) { // can't execute because TimesTen can't do subqueries combined with aggreations
- s.find("from Fum fum1 where size(fum1.friends) = 0");
+ s.createQuery( "from Fum fum1 where size(fum1.friends) = 0" ).list();
}
}
- s.find("select elements(fum1.friends) from Fum fum1");
- s.find("from Fum fum1, fr in elements( fum1.friends )");
- s.connection().commit();
+ s.createQuery( "select elements(fum1.friends) from Fum fum1" ).list();
+ s.createQuery( "from Fum fum1, fr in elements( fum1.friends )" ).list();
+ s.getTransaction().commit();
s.close();
}
public void testUnflushedSessionSerialization() throws Exception {
-
///////////////////////////////////////////////////////////////////////////
// Test insertions across serializations
Session s = getSessions().openSession();
Modified: core/trunk/testsuite/src/test/java/org/hibernate/test/legacy/IJ2Test.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/legacy/IJ2Test.java 2009-05-11 21:12:30 UTC (rev 16535)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/legacy/IJ2Test.java 2009-05-11 21:13:36 UTC (rev 16536)
@@ -70,11 +70,11 @@
getSessions().evict(I.class);
s = getSessions().openSession();
- assertTrue( s.find("from I").size()==2 );
- assertTrue( s.find("from J").size()==1 );
- assertTrue( s.find("from J j where j.amount > 0 and j.name is not null").size()==1 );
- assertTrue( s.find("from I i where i.class = org.hibernate.test.legacy.I").size()==1 );
- assertTrue( s.find("from I i where i.class = J").size()==1 );
+ assertTrue( s.createQuery( "from I" ).list().size()==2 );
+ assertTrue( s.createQuery( "from J" ).list().size()==1 );
+ assertTrue( s.createQuery( "from J j where j.amount > 0 and j.name is not null" ).list().size()==1 );
+ assertTrue( s.createQuery( "from I i where i.class = org.hibernate.test.legacy.I" ).list().size()==1 );
+ assertTrue( s.createQuery( "from I i where i.class = J" ).list().size()==1 );
s.connection().commit();
s.close();
@@ -108,9 +108,9 @@
getSessions().evict(I.class);
s = getSessions().openSession();
- assertTrue( s.find("from K k inner join k.is i where i.name = 'j'").size()==1 );
- assertTrue( s.find("from K k inner join k.is i where i.name = 'i'").size()==1 );
- assertTrue( s.find("from K k left join fetch k.is").size()==2 );
+ assertTrue( s.createQuery( "from K k inner join k.is i where i.name = 'j'" ).list().size()==1 );
+ assertTrue( s.createQuery( "from K k inner join k.is i where i.name = 'i'" ).list().size()==1 );
+ assertTrue( s.createQuery( "from K k left join fetch k.is" ).list().size()==2 );
s.connection().commit();
s.close();
Modified: core/trunk/testsuite/src/test/java/org/hibernate/test/legacy/IJTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/legacy/IJTest.java 2009-05-11 21:12:30 UTC (rev 16535)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/legacy/IJTest.java 2009-05-11 21:13:36 UTC (rev 16536)
@@ -63,10 +63,10 @@
s.close();
s = getSessions().openSession();
- assertTrue( s.find("from I").size()==2 );
- assertTrue( s.find("from J").size()==1 );
- assertTrue( s.find("from I i where i.class = 0").size()==1 );
- assertTrue( s.find("from I i where i.class = 1").size()==1 );
+ assertTrue( s.createQuery( "from I" ).list().size()==2 );
+ assertTrue( s.createQuery( "from J" ).list().size()==1 );
+ assertTrue( s.createQuery( "from I i where i.class = 0" ).list().size()==1 );
+ assertTrue( s.createQuery( "from I i where i.class = 1" ).list().size()==1 );
s.connection().commit();
s.close();
Modified: core/trunk/testsuite/src/test/java/org/hibernate/test/legacy/LegacyTestCase.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/legacy/LegacyTestCase.java 2009-05-11 21:12:30 UTC (rev 16535)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/legacy/LegacyTestCase.java 2009-05-11 21:13:36 UTC (rev 16536)
@@ -1,11 +1,16 @@
package org.hibernate.test.legacy;
+import java.util.Iterator;
+
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment;
import org.hibernate.hql.classic.ClassicQueryTranslatorFactory;
import org.hibernate.util.StringHelper;
import org.hibernate.junit.functional.FunctionalTestCase;
import org.hibernate.dialect.Dialect;
+import org.hibernate.classic.Session;
+import org.hibernate.type.Type;
+import org.hibernate.Query;
/**
* @author Steve Ebersole
@@ -54,4 +59,34 @@
}
}
}
+
+ protected int doDelete(Session session, String queryString) {
+ return doDelete( session, session.createQuery( queryString ) );
+ }
+
+ protected int doDelete(Session session, String queryString, Object param, Type paramType) {
+ Query query = session.createQuery( queryString )
+ .setParameter( 0, param, paramType );
+ return doDelete( session, query );
+ }
+
+ protected int doDelete(Session session, String queryString, Object[] params, Type[] paramTypes) {
+ Query query = session.createQuery( queryString );
+ if ( params != null ) {
+ for ( int i = 0; i < params.length; i++ ) {
+ query.setParameter( i, params[i], paramTypes[i] );
+ }
+ }
+ return doDelete( session, query );
+ }
+
+ protected int doDelete(Session session, Query selectQuery) {
+ int count = 0;
+ Iterator itr = selectQuery.list().iterator();
+ while ( itr.hasNext() ) {
+ session.delete( itr.next() );
+ count++;
+ }
+ return count;
+ }
}
Modified: core/trunk/testsuite/src/test/java/org/hibernate/test/legacy/MasterDetailTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/legacy/MasterDetailTest.java 2009-05-11 21:12:30 UTC (rev 16535)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/legacy/MasterDetailTest.java 2009-05-11 21:13:36 UTC (rev 16536)
@@ -166,11 +166,11 @@
s = openSession();
t = s.beginTransaction();
- List list = s.find("from Up up order by up.id2 asc");
+ List list = s.createQuery( "from Up up order by up.id2 asc" ).list();
assertTrue( list.size()==2 );
assertFalse( list.get(0) instanceof Down );
assertTrue( list.get(1) instanceof Down );
- list = s.find("from Down down");
+ list = s.createQuery( "from Down down" ).list();
assertTrue( list.size()==1 );
assertTrue( list.get(0) instanceof Down );
//list = s.find("from Up down where down.class = Down");
@@ -195,7 +195,7 @@
s.close();
s = openSession();
t = s.beginTransaction();
- Iterator i = s.iterate("from Master");
+ Iterator i = s.createQuery( "from Master" ).iterate();
m = (Master) i.next();
assertTrue( m.getOtherMaster()==m );
if (getDialect() instanceof HSQLDialect) { m.setOtherMaster(null); s.flush(); }
@@ -273,7 +273,7 @@
s.close();
s = openSession();
t = s.beginTransaction();
- s.find("from Several");
+ s.createQuery( "from Several" ).list();
t.commit();
s.close();
s = openSession();
@@ -287,12 +287,12 @@
Session s = openSession();
Transaction t = s.beginTransaction();
if ( !(getDialect() instanceof MySQLDialect) && !(getDialect() instanceof SAPDBDialect) && !(getDialect() instanceof MckoiDialect) ) {
- s.iterate("FROM Master m WHERE NOT EXISTS ( FROM m.details d WHERE NOT d.i=5 )");
- s.iterate("FROM Master m WHERE NOT 5 IN ( SELECT d.i FROM m.details AS d )");
+ s.createQuery( "FROM Master m WHERE NOT EXISTS ( FROM m.details d WHERE NOT d.i=5 )" ).iterate();
+ s.createQuery( "FROM Master m WHERE NOT 5 IN ( SELECT d.i FROM m.details AS d )" ).iterate();
}
- s.iterate("SELECT m FROM Master m JOIN m.details d WHERE d.i=5");
- s.find("SELECT m FROM Master m JOIN m.details d WHERE d.i=5");
- s.find("SELECT m.id FROM Master AS m JOIN m.details AS d WHERE d.i=5");
+ s.createQuery( "SELECT m FROM Master m JOIN m.details d WHERE d.i=5" ).iterate();
+ s.createQuery( "SELECT m FROM Master m JOIN m.details d WHERE d.i=5" ).list();
+ s.createQuery( "SELECT m.id FROM Master AS m JOIN m.details AS d WHERE d.i=5" ).list();
t.commit();
s.close();
}
@@ -318,7 +318,9 @@
if ( !(getDialect() instanceof MySQLDialect) && !(getDialect() instanceof SAPDBDialect) && !(getDialect() instanceof MckoiDialect) && !(getDialect() instanceof org.hibernate.dialect.TimesTenDialect)) {
assertTrue(
"query",
- s.find("from Detail d, Master m where m = d.master and size(m.outgoing) = 0 and size(m.incoming) = 0").size()==2
+ s.createQuery(
+ "from Detail d, Master m where m = d.master and size(m.outgoing) = 0 and size(m.incoming) = 0"
+ ).list().size()==2
);
}
t.commit();
@@ -348,17 +350,17 @@
s = openSession();
t = s.beginTransaction();
- assertTrue( s.find("select elements(master.details) from Master master").size()==2 );
+ assertTrue( s.createQuery( "select elements(master.details) from Master master" ).list().size()==2 );
t.commit();
s.close();
s = openSession();
t = s.beginTransaction();
- List list = s.find("from Master m left join fetch m.details");
+ List list = s.createQuery( "from Master m left join fetch m.details" ).list();
Master m = (Master) list.get(0);
assertTrue( Hibernate.isInitialized( m.getDetails() ) );
assertTrue( m.getDetails().size()==2 );
- list = s.find("from Detail d inner join fetch d.master");
+ list = s.createQuery( "from Detail d inner join fetch d.master" ).list();
Detail dt = (Detail) list.get(0);
Serializable dtid = s.getIdentifier(dt);
assertTrue( dt.getMaster()==m );
@@ -370,7 +372,8 @@
s = openSession();
t = s.beginTransaction();
- list = s.find("select m from Master m1, Master m left join fetch m.details where m.name=m1.name");
+ list = s.createQuery( "select m from Master m1, Master m left join fetch m.details where m.name=m1.name" )
+ .list();
assertTrue( Hibernate.isInitialized( ( (Master) list.get(0) ).getDetails() ) );
dt = (Detail) s.load(Detail.class, dtid);
assertTrue( ( (Master) list.get(0) ).getDetails().contains(dt) );
@@ -379,7 +382,9 @@
s = openSession();
t = s.beginTransaction();
- list = s.find("select m, m1.name from Master m1, Master m left join fetch m.details where m.name=m1.name");
+ list = s.createQuery(
+ "select m, m1.name from Master m1, Master m left join fetch m.details where m.name=m1.name"
+ ).list();
assertTrue( Hibernate.isInitialized( ( (Master) ( (Object[]) list.get(0) )[0] ).getDetails() ) );
dt = (Detail) s.load(Detail.class, dtid);
assertTrue( ( (Master) ( (Object[]) list.get(0) )[0] ).getDetails().contains(dt) );
@@ -395,8 +400,8 @@
Detail dd = (Detail) s.load(Detail.class, did);
master = dd.getMaster();
assertTrue( "detail-master", master.getDetails().contains(dd) );
- assertTrue( s.filter( master.getDetails(), "order by this.i desc").size()==2 );
- assertTrue( s.filter( master.getDetails(), "select this where this.id > -1").size()==2 );
+ assertTrue( s.createFilter( master.getDetails(), "order by this.i desc" ).list().size()==2 );
+ assertTrue( s.createFilter( master.getDetails(), "select this where this.id > -1" ).list().size()==2 );
Query q = s.createFilter( master.getDetails(), "where this.id > :id" );
q.setInteger("id", -1);
assertTrue( q.list().size()==2 );
@@ -413,18 +418,21 @@
q.setParameterList("ids", list);
assertTrue( q.list().size()==1 );
assertTrue( q.iterate().hasNext() );
- assertTrue( s.filter( master.getDetails(), "where this.id > -1").size()==2 );
- assertTrue( s.filter( master.getDetails(), "select this.master where this.id > -1").size()==2 );
- assertTrue( s.filter( master.getDetails(), "select m from Master m where this.id > -1 and this.master=m").size()==2 );
- assertTrue( s.filter( master.getIncoming(), "where this.id > -1 and this.name is not null").size()==0 );
+ assertTrue( s.createFilter( master.getDetails(), "where this.id > -1" ).list().size()==2 );
+ assertTrue( s.createFilter( master.getDetails(), "select this.master where this.id > -1" ).list().size()==2 );
+ assertTrue(
+ s.createFilter( master.getDetails(), "select m from Master m where this.id > -1 and this.master=m" )
+ .list()
+ .size()==2 );
+ assertTrue( s.createFilter( master.getIncoming(), "where this.id > -1 and this.name is not null" ).list().size()==0 );
assertTrue( s.createFilter( master.getDetails(), "select max(this.i)" ).iterate().next() instanceof Integer );
assertTrue( s.createFilter( master.getDetails(), "select max(this.i) group by this.id" ).iterate().next() instanceof Integer );
assertTrue( s.createFilter( master.getDetails(), "select count(*)" ).iterate().next() instanceof Long );
assertTrue( s.createFilter( master.getDetails(), "select this.master" ).list().size()==2 );
- assertTrue( s.filter( master.getMoreDetails(), "" ).size()==0 );
- assertTrue( s.filter( master.getIncoming(), "" ).size()==0 );
+ assertTrue( s.createFilter( master.getMoreDetails(), "" ).list().size()==0 );
+ assertTrue( s.createFilter( master.getIncoming(), "" ).list().size()==0 );
Query f = s.createFilter( master.getDetails(), "select max(this.i) where this.i < :top and this.i>=:bottom" );
f.setInteger("top", 100);
@@ -474,7 +482,7 @@
master1.addIncoming(master3);
master3.addOutgoing(master1);
Serializable m1id = s.getIdentifier(master1);
- assertTrue( s.filter( master1.getIncoming(), "where this.id > 0 and this.name is not null").size()==2 );
+ assertTrue( s.createFilter( master1.getIncoming(), "where this.id > 0 and this.name is not null" ).list().size()==2 );
s.flush();
s.connection().commit();
s.close();
@@ -596,8 +604,8 @@
m = (Master) s.load( Master.class, mid );
assertTrue( ( (Detail) m.getMoreDetails().iterator().next() ).getSubDetails().size()!=0 );
s.delete(m);
- assertTrue( s.find("from SubDetail").size()==0 );
- assertTrue( s.find("from Detail d").size()==0 );
+ assertTrue( s.createQuery( "from SubDetail" ).list().size()==0 );
+ assertTrue( s.createQuery( "from Detail d" ).list().size()==0 );
s.delete( s.load(Master.class, m0id) );
txn.commit();
s.close();
@@ -796,7 +804,8 @@
assertTrue( list.get(1)!=null && list.get(0)==null );
assertTrue(
- s.iterate("from Category c where c.name = org.hibernate.test.legacy.Category.ROOT_CATEGORY").hasNext()
+ s.createQuery( "from Category c where c.name = org.hibernate.test.legacy.Category.ROOT_CATEGORY" )
+ .iterate().hasNext()
);
s.delete(c);
s.flush();
Modified: core/trunk/testsuite/src/test/java/org/hibernate/test/legacy/MultiTableTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/legacy/MultiTableTest.java 2009-05-11 21:12:30 UTC (rev 16535)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/legacy/MultiTableTest.java 2009-05-11 21:13:36 UTC (rev 16536)
@@ -55,45 +55,49 @@
public void testFetchOneToMany() throws Exception {
Session s = openSession();
- s.createCriteria(Po.class).setFetchMode("set", FetchMode.EAGER).list();
- s.createCriteria(Po.class).setFetchMode("list", FetchMode.EAGER).list();
- s.connection().commit();
+ s.beginTransaction();
+ s.createCriteria(Po.class).setFetchMode("set", FetchMode.JOIN).list();
+ s.createCriteria(Po.class).setFetchMode("list", FetchMode.JOIN).list();
+ s.getTransaction().commit();
s.close();
}
public void testNarrow() throws Exception {
Session s = openSession();
- s.find("from Po po, Lower low where low.mypo = po");
- s.find("from Po po join po.set as sm where sm.amount > 0");
- s.find("from Po po join po.top as low where low.foo = 'po'");
- s.connection().commit();
+ s.beginTransaction();
+ s.createQuery("from Po po, Lower low where low.mypo = po").list();
+ s.createQuery("from Po po join po.set as sm where sm.amount > 0").list();
+ s.createQuery("from Po po join po.top as low where low.foo = 'po'").list();
+ s.getTransaction().commit();
s.close();
}
public void testJoins() throws Exception {
Session s = openSession();
- s.find("from Lower l join l.yetanother l2 where lower(l2.name) > 'a'");
- s.find("from Lower l where lower(l.yetanother.top.name) > 'a'");
- s.find("from SubMulti sm join sm.children smc where smc.name > 'a'");
- s.find("select s, ya from Lower s join s.yetanother ya");
- s.find("from Lower s1 join s1.bag s2");
- s.find("from Lower s1 left join s1.bag s2");
- s.find("select s, a from Lower s join s.another a");
- s.find("select s, a from Lower s left join s.another a");
- s.find("from Top s, Lower ls");
- s.find("from Lower ls join ls.set s where s.name > 'a'");
- s.find("from Po po join po.list sm where sm.name > 'a'");
- s.find("from Lower ls inner join ls.another s where s.name is not null");
- s.find("from Lower ls where ls.other.another.name is not null");
- s.find("from Multi m where m.derived like 'F%'");
- s.find("from SubMulti m where m.derived like 'F%'");
- s.connection().commit();
+ s.beginTransaction();
+ s.createQuery( "from Lower l join l.yetanother l2 where lower(l2.name) > 'a'" ).list();
+ s.createQuery( "from Lower l where lower(l.yetanother.top.name) > 'a'" ).list();
+ s.createQuery( "from SubMulti sm join sm.children smc where smc.name > 'a'" ).list();
+ s.createQuery( "select s, ya from Lower s join s.yetanother ya" ).list();
+ s.createQuery( "from Lower s1 join s1.bag s2" ).list();
+ s.createQuery( "from Lower s1 left join s1.bag s2" ).list();
+ s.createQuery( "select s, a from Lower s join s.another a" ).list();
+ s.createQuery( "select s, a from Lower s left join s.another a" ).list();
+ s.createQuery( "from Top s, Lower ls" ).list();
+ s.createQuery( "from Lower ls join ls.set s where s.name > 'a'" ).list();
+ s.createQuery( "from Po po join po.list sm where sm.name > 'a'" ).list();
+ s.createQuery( "from Lower ls inner join ls.another s where s.name is not null" ).list();
+ s.createQuery( "from Lower ls where ls.other.another.name is not null" ).list();
+ s.createQuery( "from Multi m where m.derived like 'F%'" ).list();
+ s.createQuery( "from SubMulti m where m.derived like 'F%'" ).list();
+ s.getTransaction().commit();
s.close();
}
public void testSubclassCollection() throws Exception {
//if ( getDialect() instanceof HSQLDialect ) return; //TODO: figure out why!?
Session s = openSession();
+ s.beginTransaction();
SubMulti sm = new SubMulti();
SubMulti sm1 = new SubMulti();
SubMulti sm2 = new SubMulti();
@@ -111,37 +115,45 @@
Serializable id = s.save(sm);
s.save(sm1);
s.save(sm2);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
getSessions().evict(SubMulti.class);
s = openSession();
+ s.beginTransaction();
s.connection().createStatement().executeQuery(
"select * from leafsubsubclass sm, nonleafsubclass m, rootclass s where sm.sid=m.sid and sm.sid=s.id1_ and sm.sid=1"
).next();
- assertTrue( s.find("select s from SubMulti as sm join sm.children as s where s.amount>-1 and s.name is null").size()==2 );
- s.find("select c from SubMulti sm join sm.children c");
- assertTrue( s.find("select elements(sm.children) from SubMulti as sm").size()==2 );
- assertTrue( s.find("select distinct sm from SubMulti as sm join sm.children as s where s.amount>-1 and s.name is null").size()==1 );
+ assertTrue(
+ s.createQuery(
+ "select s from SubMulti as sm join sm.children as s where s.amount>-1 and s.name is null"
+ ).list().size()==2 );
+ s.createQuery( "select c from SubMulti sm join sm.children c" ).list();
+ assertTrue( s.createQuery( "select elements(sm.children) from SubMulti as sm" ).list().size()==2 );
+ assertTrue(
+ s.createQuery(
+ "select distinct sm from SubMulti as sm join sm.children as s where s.amount>-1 and s.name is null"
+ ).list().size()==1 );
sm = (SubMulti) s.load(SubMulti.class, id);
assertTrue( sm.getChildren().size()==2 );
assertEquals(
- s.filter( sm.getMoreChildren(), "select count(*) where this.amount>-1 and this.name is null" ).iterator().next(),
+ s.createFilter( sm.getMoreChildren(), "select count(*) where this.amount>-1 and this.name is null" ).list().get(0),
new Long(2)
);
assertEquals( "FOO", sm.getDerived() );
assertSame(
- s.iterate("select distinct s from SubMulti s where s.moreChildren[1].amount < 1.0").next(),
+ s.createQuery( "select distinct s from SubMulti s where s.moreChildren[1].amount < 1.0" ).iterate().next(),
sm
);
assertTrue( sm.getMoreChildren().size()==2 );
s.delete(sm);
Iterator iter = sm.getChildren().iterator();
- while ( iter.hasNext() ) s.delete( iter.next() );
+ while ( iter.hasNext() ) {
+ s.delete( iter.next() );
+ }
s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
}
@@ -166,26 +178,26 @@
public void testQueries() throws Exception {
Session s = openSession();
+ s.beginTransaction();
Long id = ( Long ) s.save( new TrivialClass() );
+ s.getTransaction().commit();
+ s.close();
- s.flush();
- s.connection().commit();
- s.close();
s = openSession();
+ s.beginTransaction();
TrivialClass tc = (TrivialClass) s.load(TrivialClass.class, id);
- s.find("from TrivialClass s where s.id = 2");
- s.find("select t.count from Top t");
- s.find("from Lower s where s.another.name='name'");
- s.find("from Lower s where s.yetanother.name='name'");
- s.find("from Lower s where s.yetanother.name='name' and s.yetanother.foo is null");
- s.find("from Top s where s.count=1");
- s.find("select s.count from Top s, Lower ls where ls.another=s");
- s.find("select elements(ls.bag), elements(ls.set) from Lower ls");
- s.iterate("from Lower");
- s.iterate("from Top");
+ s.createQuery( "from TrivialClass s where s.id = 2" ).list();
+ s.createQuery( "select t.count from Top t" ).list();
+ s.createQuery( "from Lower s where s.another.name='name'" ).list();
+ s.createQuery( "from Lower s where s.yetanother.name='name'" ).list();
+ s.createQuery( "from Lower s where s.yetanother.name='name' and s.yetanother.foo is null" ).list();
+ s.createQuery( "from Top s where s.count=1" ).list();
+ s.createQuery( "select s.count from Top s, Lower ls where ls.another=s" ).list();
+ s.createQuery( "select elements(ls.bag), elements(ls.set) from Lower ls" ).list();
+ s.createQuery( "from Lower" ).iterate();
+ s.createQuery( "from Top" ).iterate();
s.delete(tc);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
}
@@ -197,9 +209,12 @@
s.save( sm );
t.commit();
s.close();
+
s = openSession();
- s.delete( "from SubMulti" );
+// doDelete( s, "from SubMulti" );
+// t = s.beginTransaction();
t = s.beginTransaction();
+ doDelete( s, "from SubMulti" );
t.commit();
s.close();
}
@@ -263,7 +278,7 @@
s = openSession();
t = s.beginTransaction();
- Iterator iter = s.iterate("select\n\nt from Top t where t.count>0");
+ Iterator iter = s.createQuery( "select\n\nt from Top t where t.count>0" ).iterate();
boolean foundSimp = false;
boolean foundMulti = false;
boolean foundSubMulti = false;
@@ -274,34 +289,35 @@
if ( o instanceof SubMulti ) foundSubMulti = true;
}
assertTrue( foundSimp&&foundMulti&&foundSubMulti );
- s.find("from Multi m where m.count>0 and m.extraProp is not null");
- s.find("from Top m where m.count>0 and m.name is not null");
- s.find("from Lower m where m.other is not null");
- s.find("from Multi m where m.other.id = 1");
- s.find("from SubMulti m where m.amount > 0.0");
+ s.createQuery( "from Multi m where m.count>0 and m.extraProp is not null" ).list();
+ s.createQuery( "from Top m where m.count>0 and m.name is not null" ).list();
+ s.createQuery( "from Lower m where m.other is not null" ).list();
+ s.createQuery( "from Multi m where m.other.id = 1" ).list();
+ s.createQuery( "from SubMulti m where m.amount > 0.0" ).list();
assertTrue(
- s.find("from Multi").size()==2
+ s.createQuery( "from Multi" ).list().size()==2
);
assertTrue(
- s.find("from Multi m where m.class = SubMulti").size()==1
+ s.createQuery( "from Multi m where m.class = SubMulti" ).list().size()==1
);
assertTrue(
- s.find("from Top m where m.class = Multi").size()==1
+ s.createQuery( "from Top m where m.class = Multi" ).list().size()==1
);
assertTrue(
- s.find("from Top").size()==3
+ s.createQuery( "from Top" ).list().size()==3
);
assertTrue(
- s.find("from Lower").size()==0
+ s.createQuery( "from Lower" ).list().size()==0
);
assertTrue(
- s.find("from SubMulti").size()==1
+ s.createQuery( "from SubMulti" ).list().size()==1
);
- s.find("from Lower ls join ls.bag s where s.id is not null");
- s.find("from Lower ls join ls.set s where s.id is not null");
- if ( !(getDialect() instanceof MySQLDialect) ) s.find("from SubMulti sm where exists elements(sm.children)");
+ s.createQuery( "from Lower ls join ls.bag s where s.id is not null" ).list();
+ s.createQuery( "from Lower ls join ls.set s where s.id is not null" ).list();
+ if ( !(getDialect() instanceof MySQLDialect) )
+ s.createQuery( "from SubMulti sm where exists elements(sm.children)" ).list();
List l = s.createCriteria(Top.class).list();
assertTrue( l.size()==3 );
@@ -334,14 +350,13 @@
t = s.beginTransaction();
s.update(multi, mid);
s.delete(multi);
- assertTrue( s.delete("from Top")==2);
+ assertEquals( 2, doDelete( s, "from Top" ) );
t.commit();
s.close();
}
public void testMultiTableGeneratedId() throws Exception {
-
Session s = openSession();
Transaction t = s.beginTransaction();
Multi multi = new Multi();
@@ -400,7 +415,7 @@
s = openSession();
t = s.beginTransaction();
- Iterator iter = s.iterate("select\n\nt from Top t where t.count>0");
+ Iterator iter = s.createQuery( "select\n\nt from Top t where t.count>0" ).iterate();
boolean foundSimp = false;
boolean foundMulti = false;
boolean foundSubMulti = false;
@@ -411,30 +426,31 @@
if ( o instanceof SubMulti ) foundSubMulti = true;
}
assertTrue( foundSimp&&foundMulti&&foundSubMulti );
- s.find("from Multi m where m.count>0 and m.extraProp is not null");
- s.find("from Top m where m.count>0 and m.name is not null");
- s.find("from Lower m where m.other is not null");
- s.find("from Multi m where m.other.id = 1");
- s.find("from SubMulti m where m.amount > 0.0");
+ s.createQuery( "from Multi m where m.count>0 and m.extraProp is not null" ).list();
+ s.createQuery( "from Top m where m.count>0 and m.name is not null" ).list();
+ s.createQuery( "from Lower m where m.other is not null" ).list();
+ s.createQuery( "from Multi m where m.other.id = 1" ).list();
+ s.createQuery( "from SubMulti m where m.amount > 0.0" ).list();
assertTrue(
- s.find("from Multi").size()==2
+ s.createQuery( "from Multi" ).list().size()==2
);
/*assertTrue(
s.find("from m in class Multi where m.class = Multi").size()==1
);*/
assertTrue(
- s.find("from Top").size()==3
+ s.createQuery( "from Top" ).list().size()==3
);
assertTrue(
- s.find("from Lower").size()==0
+ s.createQuery( "from Lower" ).list().size()==0
);
assertTrue(
- s.find("from SubMulti").size()==1
+ s.createQuery( "from SubMulti" ).list().size()==1
);
- s.find("from Lower ls join ls.bag s where s.id is not null");
- if ( !(getDialect() instanceof MySQLDialect) ) s.find("from SubMulti sm where exists elements(sm.children)");
+ s.createQuery( "from Lower ls join ls.bag s where s.id is not null" ).list();
+ if ( !(getDialect() instanceof MySQLDialect) )
+ s.createQuery( "from SubMulti sm where exists elements(sm.children)" ).list();
t.commit();
s.close();
@@ -451,7 +467,7 @@
t = s.beginTransaction();
s.update( multi, multiId );
s.delete(multi);
- assertTrue( s.delete("from Top")==2);
+ assertEquals( 2, doDelete( s, "from Top" ) );
t.commit();
s.close();
@@ -460,7 +476,7 @@
public void testMultiTableCollections() throws Exception {
Session s = openSession();
Transaction t = s.beginTransaction();
- assertTrue( s.find("from Top").size()==0 );
+ assertTrue( s.createQuery( "from Top" ).list().size()==0 );
Multi multi = new Multi();
multi.setExtraProp("extra");
multi.setName("name");
@@ -499,7 +515,7 @@
if ( o instanceof Multi ) foundMulti++;
}
assertTrue( foundSimple==2 && foundMulti==1 );
- assertTrue( s.delete("from Top")==3 );
+ assertEquals( 3, doDelete( s, "from Top" ) );
t.commit();
s.close();
}
@@ -507,7 +523,7 @@
public void testMultiTableManyToOne() throws Exception {
Session s = openSession();
Transaction t = s.beginTransaction();
- assertTrue( s.find("from Top").size()==0 );
+ assertTrue( s.createQuery( "from Top" ).list().size()==0 );
Multi multi = new Multi();
multi.setExtraProp("extra");
multi.setName("name");
@@ -573,31 +589,34 @@
assertTrue( po.getSet().size()==2 );
assertTrue( po.getList().size()==1 );
s.delete(po);
- assertTrue( s.find("from Top").size()==0 );
+ assertTrue( s.createQuery( "from Top" ).list().size()==0 );
t.commit();
s.close();
}
public void testOneToOne() throws Exception {
Session s = openSession();
+ s.beginTransaction();
Lower ls = new Lower();
Serializable id = s.save(ls);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
+
s = openSession();
+ s.beginTransaction();
s.load(Lower.class, id);
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
+
s = openSession();
s.delete( s.load(Lower.class, id) );
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
}
public void testCollectionPointer() throws Exception {
Session sess = openSession();
+ sess.beginTransaction();
Lower ls = new Lower();
List list = new ArrayList();
ls.setBag(list);
@@ -606,16 +625,15 @@
sess.save(s);
sess.flush();
list.add(s);
- sess.flush();
- sess.connection().commit();
+ sess.getTransaction().commit();
sess.close();
sess = openSession();
+ sess.beginTransaction();
ls = (Lower) sess.load(Lower.class, id);
assertTrue( ls.getBag().size()==1 );
- sess.delete("from java.lang.Object");
- sess.flush();
- sess.connection().commit();
+ doDelete( sess, "from java.lang.Object" );
+ sess.getTransaction().commit();
sess.close();
}
Modified: core/trunk/testsuite/src/test/java/org/hibernate/test/legacy/ParentChildTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/legacy/ParentChildTest.java 2009-05-11 21:12:30 UTC (rev 16535)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/legacy/ParentChildTest.java 2009-05-11 21:13:36 UTC (rev 16536)
@@ -67,6 +67,7 @@
public void testReplicate() throws Exception {
Session s = openSession();
+ s.beginTransaction();
Container baz = new Container();
Contained f = new Contained();
List list = new ArrayList();
@@ -77,30 +78,29 @@
baz.setBag(list2);
s.save(f);
s.save(baz);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
+
s = openSession();
s.replicate(baz, ReplicationMode.OVERWRITE);
-
// HHH-2378
SessionImpl x = (SessionImpl)s;
EntityEntry entry = x.getPersistenceContext().getEntry( baz );
assertNull(entry.getVersion());
-
- s.flush();
- s.connection().commit();
+ // ~~~~~~~
+ s.getTransaction().commit();
s.close();
+
s = openSession();
s.replicate(baz, ReplicationMode.IGNORE);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
+
s = openSession();
+ s.beginTransaction();
s.delete(baz);
s.delete(f);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
}
@@ -108,7 +108,7 @@
Session s = openSession();
Transaction t = s.beginTransaction();
Serializable id = s.save( new Parent() );
- assertTrue( s.find("from Parent p left join fetch p.child").size()==1 );
+ assertTrue( s.createQuery( "from Parent p left join fetch p.child" ).list().size()==1 );
t.commit();
s.close();
@@ -116,8 +116,8 @@
t = s.beginTransaction();
Parent p = (Parent) s.createQuery("from Parent p left join fetch p.child").uniqueResult();
assertTrue( p.getChild()==null );
- s.find("from Parent p join p.child c where c.x > 0");
- s.find("from Child c join c.parent p where p.x > 0");
+ s.createQuery( "from Parent p join p.child c where c.x > 0" ).list();
+ s.createQuery( "from Child c join c.parent p where p.x > 0" ).list();
t.commit();
s.close();
@@ -177,7 +177,7 @@
s.delete(foo);
s.delete( s.get(Foo.class, id2) );
s.delete( s.get(Foo.class, "xyzid") );
- assertTrue( s.delete("from java.lang.Object")==3 );
+ assertEquals( 2, doDelete( s, "from java.lang.Object" ) );
t.commit();
s.close();
@@ -322,9 +322,9 @@
assertTrue( Hibernate.isInitialized(baz.getTopGlarchez()) ); //cos it is nonlazy
assertTrue( !Hibernate.isInitialized(baz.getFooSet()) );
- list = s.createCriteria(Child.class).setFetchMode("parent", FetchMode.JOIN).list();
-
- s.delete("from Glarch g");
+ s.createCriteria(Child.class).setFetchMode("parent", FetchMode.JOIN).list();
+
+ doDelete( s, "from Glarch g" );
s.delete( s.get(Foo.class, foo1.getKey() ) );
s.delete( s.get(Foo.class, foo2.getKey() ) );
s.delete(baz);
@@ -429,57 +429,60 @@
sx.setName("s");
s.save( sx, new Long(5) );
assertTrue(
- s.find("select c from ContainerX c, Simple s where c.oneToMany[2] = s")
- .size() == 1
+ s.createQuery( "select c from ContainerX c, Simple s where c.oneToMany[2] = s" ).list()
+ .size() == 1
);
assertTrue(
- s.find("select c from ContainerX c, Simple s where c.manyToMany[2] = s")
- .size() == 1
+ s.createQuery( "select c from ContainerX c, Simple s where c.manyToMany[2] = s" ).list()
+ .size() == 1
);
assertTrue(
- s.find("select c from ContainerX c, Simple s where s = c.oneToMany[2]")
- .size() == 1
+ s.createQuery( "select c from ContainerX c, Simple s where s = c.oneToMany[2]" ).list()
+ .size() == 1
);
assertTrue(
- s.find("select c from ContainerX c, Simple s where s = c.manyToMany[2]")
- .size() == 1
+ s.createQuery( "select c from ContainerX c, Simple s where s = c.manyToMany[2]" ).list()
+ .size() == 1
);
assertTrue(
- s.find("select c from ContainerX c where c.oneToMany[0].name = 's'")
- .size() == 1
+ s.createQuery( "select c from ContainerX c where c.oneToMany[0].name = 's'" ).list()
+ .size() == 1
);
assertTrue(
- s.find("select c from ContainerX c where c.manyToMany[0].name = 's'")
- .size() == 1
+ s.createQuery( "select c from ContainerX c where c.manyToMany[0].name = 's'" ).list()
+ .size() == 1
);
assertTrue(
- s.find("select c from ContainerX c where 's' = c.oneToMany[2 - 2].name")
- .size() == 1
+ s.createQuery( "select c from ContainerX c where 's' = c.oneToMany[2 - 2].name" ).list()
+ .size() == 1
);
assertTrue(
- s.find("select c from ContainerX c where 's' = c.manyToMany[(3+1)/4-1].name")
- .size() == 1
+ s.createQuery( "select c from ContainerX c where 's' = c.manyToMany[(3+1)/4-1].name" ).list()
+ .size() == 1
);
assertTrue(
- s.find("select c from ContainerX c where c.oneToMany[ c.manyToMany[0].count ].name = 's'")
- .size() == 1
+ s.createQuery( "select c from ContainerX c where c.oneToMany[ c.manyToMany[0].count ].name = 's'" )
+ .list()
+ .size() == 1
);
assertTrue(
- s.find("select c from ContainerX c where c.manyToMany[ c.oneToMany[0].count ].name = 's'")
- .size() == 1
+ s.createQuery( "select c from ContainerX c where c.manyToMany[ c.oneToMany[0].count ].name = 's'" )
+ .list()
+ .size() == 1
);
if ( ! ( getDialect() instanceof MySQLDialect ) && !(getDialect() instanceof org.hibernate.dialect.TimesTenDialect) ) {
assertTrue(
- s.find("select c from ContainerX c where c.manyToMany[ maxindex(c.manyToMany) ].count = 2")
- .size() == 1
+ s.createQuery( "select c from ContainerX c where c.manyToMany[ maxindex(c.manyToMany) ].count = 2" )
+ .list()
+ .size() == 1
);
}
assertTrue( s.contains(cd) );
if ( !(getDialect() instanceof MySQLDialect) && !(getDialect() instanceof HSQLDialect) ) {
- s.filter( c.getBag(), "where 0 in elements(this.bag)" );
- s.filter( c.getBag(), "where 0 in elements(this.lazyBag)" );
+ s.createFilter( c.getBag(), "where 0 in elements(this.bag)" ).list();
+ s.createFilter( c.getBag(), "where 0 in elements(this.lazyBag)" ).list();
}
- s.find("select count(comp.name) from ContainerX c join c.components comp");
+ s.createQuery( "select count(comp.name) from ContainerX c join c.components comp" ).list();
s.delete(cd);
s.delete(c);
s.delete(s1);
@@ -521,19 +524,19 @@
assertTrue( "1-1 update", c.getCount()==32 );
assertTrue(
"1-1 query",
- s.find("from Child c where c.parent.count=66").size()==1
+ s.createQuery( "from Child c where c.parent.count=66" ).list().size()==1
);
assertTrue(
"1-1 query",
- ( (Object[]) s.find("from Parent p join p.child c where p.count=66").get(0) ).length==2
+ ( (Object[]) s.createQuery( "from Parent p join p.child c where p.count=66" ).list().get(0) ).length==2
);
- s.find("select c, c.parent from Child c order by c.parent.count");
- s.find("select c, c.parent from Child c where c.parent.count=66 order by c.parent.count");
- s.iterate("select c, c.parent, c.parent.count from Child c order by c.parent.count");
- assertTrue(
- "1-1 query",
- s.find("FROM Parent AS p WHERE p.count = ?", new Integer(66), Hibernate.INTEGER).size()==1
- );
+ s.createQuery( "select c, c.parent from Child c order by c.parent.count" ).list();
+ s.createQuery( "select c, c.parent from Child c where c.parent.count=66 order by c.parent.count" ).list();
+ s.createQuery( "select c, c.parent, c.parent.count from Child c order by c.parent.count" ).iterate();
+ List result = s.createQuery( "FROM Parent AS p WHERE p.count = ?" )
+ .setParameter( 0, new Integer(66), Hibernate.INTEGER )
+ .list();
+ assertEquals( "1-1 query", 1, result.size() );
s.delete(c); s.delete(p);
t.commit();
s.close();
@@ -566,7 +569,6 @@
}
public void testManyToMany() throws Exception {
-
Session s = openSession();
Transaction t = s.beginTransaction();
Container c = new Container();
@@ -606,9 +608,9 @@
assertTrue( c.getManyToMany().size()==1 );
c1 = (Contained) s.load( Contained.class, new Long(c1.getId()) );
assertTrue( c1.getBag().size()==0 );
- assertTrue( s.delete("from ContainerX c")==1 );
- assertTrue( s.delete("from Contained")==1 );
- assertTrue( s.delete("from Simple")==2 );
+ assertEquals( 1, doDelete( s, "from ContainerX c" ) );
+ assertEquals( 1, doDelete( s, "from Contained" ) );
+ assertEquals( 2, doDelete( s, "from Simple" ) );
t.commit();
s.close();
}
@@ -657,7 +659,9 @@
t = s.beginTransaction();
Long count = (Long) s.createQuery("select count(*) from ContainerX as c join c.components as ce join ce.simple as s where ce.name='foo'").uniqueResult();
assertTrue( count.intValue()==1 );
- List res = s.find("select c, s from ContainerX as c join c.components as ce join ce.simple as s where ce.name='foo'");
+ List res = s.createQuery(
+ "select c, s from ContainerX as c join c.components as ce join ce.simple as s where ce.name='foo'"
+ ).list();
assertTrue(res.size()==1);
t.commit();
s.close();
@@ -734,9 +738,9 @@
c.getManyToMany().clear();
c.getComposites().clear();
c.getComponents().clear();
- s.delete("from Simple");
- s.delete("from Many");
- s.delete("from One");
+ doDelete( s, "from Simple" );
+ doDelete( s, "from Many" );
+ doDelete( s, "from One" );
t.commit();
s.close();
@@ -761,23 +765,24 @@
cic.setOne( new One() );
list.add(cic);
Session s = openSession();
+ s.beginTransaction();
s.save(c);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
s=openSession();
- c = (Container) s.iterate("from ContainerX c").next();
+ s.beginTransaction();
+ c = (Container) s.createQuery( "from ContainerX c" ).iterate().next();
cic = (Container.ContainerInnerClass) c.getCascades().iterator().next();
assertTrue( cic.getMany()!=null && cic.getOne()!=null );
assertTrue( c.getCascades().size()==1 );
s.delete(c);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
c = new Container();
s = openSession();
+ s.beginTransaction();
s.save(c);
list = new ArrayList();
c.setCascades(list);
@@ -785,23 +790,21 @@
cic.setMany( new Many() );
cic.setOne( new One() );
list.add(cic);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
s=openSession();
- c = (Container) s.iterate("from ContainerX c").next();
+ s.beginTransaction();
+ c = (Container) s.createQuery( "from ContainerX c" ).iterate().next();
cic = (Container.ContainerInnerClass) c.getCascades().iterator().next();
assertTrue( cic.getMany()!=null && cic.getOne()!=null );
assertTrue( c.getCascades().size()==1 );
s.delete(c);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
}
public void testBag() throws Exception {
-
Session s = openSession();
Transaction t = s.beginTransaction();
Container c = new Container();
@@ -822,14 +825,14 @@
s = openSession();
t = s.beginTransaction();
- c = (Container) s.find("from ContainerX c").get(0);
+ c = (Container) s.createQuery( "from ContainerX c" ).list().get(0);
c.getLazyBag().size();
t.commit();
s.close();
s = openSession();
t = s.beginTransaction();
- c = (Container) s.find("from ContainerX c").get(0);
+ c = (Container) s.createQuery( "from ContainerX c" ).list().get(0);
Contained c3 = new Contained();
//c.getBag().add(c3);
//c3.getBag().add(c);
@@ -840,7 +843,7 @@
s = openSession();
t = s.beginTransaction();
- c = (Container) s.find("from ContainerX c").get(0);
+ c = (Container) s.createQuery( "from ContainerX c" ).list().get(0);
Contained c4 = new Contained();
c.getLazyBag().add(c4);
c4.getLazyBag().add(c);
@@ -851,7 +854,7 @@
s = openSession();
t = s.beginTransaction();
- c = (Container) s.find("from ContainerX c").get(0);
+ c = (Container) s.createQuery( "from ContainerX c" ).list().get(0);
Iterator i = c.getBag().iterator();
int j=0;
while ( i.hasNext() ) {
@@ -873,7 +876,6 @@
s.delete( s.load(Contained.class, new Long( c3.getId() ) ) );
t.commit();
s.close();
-
}
public void testCircularCascade() throws Exception {
@@ -913,15 +915,17 @@
assertTrue( c.getOther().getClazz()==Qux.class);
assertTrue( c.getOther().getOther().getOther()==c);
assertTrue( c.getAnyEntity()==c.getOther() );
- assertTrue( s.delete("from Universe")==3 );
+ assertEquals( 3, doDelete( s, "from Universe" ) );
tx.commit();
s.close();
}
public void testDeleteEmpty() throws Exception {
Session s = openSession();
- assertTrue( s.delete("from Simple")==0 );
- assertTrue( s.delete("from Universe")==0 );
+ s.beginTransaction();
+ assertEquals( 0, doDelete( s, "from Simple" ) );
+ assertEquals( 0, doDelete( s, "from Universe" ) );
+ s.getTransaction().commit();
s.close();
}
@@ -1004,26 +1008,26 @@
public void testObjectType() throws Exception {
Session s = openSession();
+ s.beginTransaction();
Parent g = new Parent();
Foo foo = new Foo();
g.setAny(foo);
s.save(g);
s.save(foo);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
+
s = openSession();
+ s.beginTransaction();
g = (Parent) s.load( Parent.class, new Long( g.getId() ) );
assertTrue( g.getAny()!=null && g.getAny() instanceof FooProxy );
s.delete( g.getAny() );
s.delete(g);
- s.flush();
- s.connection().commit();
+ s.getTransaction().commit();
s.close();
}
public void testLoadAfterNonExists() throws HibernateException, SQLException {
-
Session session = openSession();
if ( (getDialect() instanceof MySQLDialect) ) {
session.connection().setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
@@ -1038,8 +1042,9 @@
// this is correct
}
- // Next, lets create that entity under the covers
+ // Next, lets create that entity "under the covers"
Session anotherSession = getSessions().openSession();
+ anotherSession.beginTransaction();
Simple myNewSimple = new Simple();
myNewSimple.setName("My under the radar Simple entity");
myNewSimple.setAddress("SessionCacheTest.testLoadAfterNonExists");
@@ -1047,29 +1052,19 @@
myNewSimple.setDate( new Date() );
myNewSimple.setPay( new Float(100000000) );
anotherSession.save( myNewSimple, new Long(-1) );
- anotherSession.flush();
- anotherSession.connection().commit();
+ anotherSession.getTransaction().commit();
anotherSession.close();
- // Verify that the original session is still able to see the new entry...
- //try {
- session.load( Simple.class, new Long(-1) );
- /*fail();
- }
- catch(ObjectNotFoundException onfe) {
- }*/
-
- // Now, lets clear the original session at which point it should be able to see
- // the new entity
+ // Now, lets make sure the original session can see the created row...
session.clear();
try {
- Simple dummy = (Simple) session.load( Simple.class, new Long(-1) );
+ Simple dummy = (Simple) session.get( Simple.class, new Long(-1) );
assertNotNull("Unable to locate entity Simple with id = -1", dummy);
}
catch(ObjectNotFoundException onfe) {
fail("Unable to locate entity Simple with id = -1");
}
- session.connection().commit();
+ session.getTransaction().commit();
session.close();
}
Modified: core/trunk/testsuite/src/test/java/org/hibernate/test/legacy/SQLFunctionsTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/legacy/SQLFunctionsTest.java 2009-05-11 21:12:30 UTC (rev 16535)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/legacy/SQLFunctionsTest.java 2009-05-11 21:13:36 UTC (rev 16536)
@@ -59,7 +59,7 @@
Session s = openSession();
Transaction t = s.beginTransaction();
- Iterator iter = s.iterate("select max(s.count) from Simple s");
+ Iterator iter = s.createQuery( "select max(s.count) from Simple s" ).iterate();
if ( getDialect() instanceof MySQLDialect ) assertTrue( iter.hasNext() && iter.next()==null );
@@ -72,20 +72,20 @@
// Test to make sure allocating an specified object operates correctly.
assertTrue(
- s.find("select new org.hibernate.test.legacy.S(s.count, s.address) from Simple s").size() == 1
+ s.createQuery( "select new org.hibernate.test.legacy.S(s.count, s.address) from Simple s" ).list().size() == 1
);
// Quick check the base dialect functions operate correctly
assertTrue(
- s.find("select max(s.count) from Simple s").size() == 1
+ s.createQuery( "select max(s.count) from Simple s" ).list().size() == 1
);
assertTrue(
- s.find("select count(*) from Simple s").size() == 1
+ s.createQuery( "select count(*) from Simple s" ).list().size() == 1
);
if ( getDialect() instanceof Oracle9iDialect ) {
// Check Oracle Dialect mix of dialect functions - no args (no parenthesis and single arg functions
- java.util.List rset = s.find("select s.name, sysdate(), trunc(s.pay), round(s.pay) from Simple s");
+ List rset = s.createQuery( "select s.name, sysdate(), trunc(s.pay), round(s.pay) from Simple s" ).list();
assertNotNull("Name string should have been returned",(((Object[])rset.get(0))[0]));
assertNotNull("Todays Date should have been returned",(((Object[])rset.get(0))[1]));
assertEquals("trunc(45.8) result was incorrect ", new Float(45), ( (Object[]) rset.get(0) )[2] );
@@ -95,24 +95,29 @@
s.update(simple);
// Test type conversions while using nested functions (Float to Int).
- rset = s.find("select abs(round(s.pay)) from Simple s");
+ rset = s.createQuery( "select abs(round(s.pay)) from Simple s" ).list();
assertEquals("abs(round(-45.8)) result was incorrect ", new Float(46), rset.get(0));
// Test a larger depth 3 function example - Not a useful combo other than for testing
assertTrue(
- s.find("select trunc(round(sysdate())) from Simple s").size() == 1
+ s.createQuery( "select trunc(round(sysdate())) from Simple s" ).list().size() == 1
);
// Test the oracle standard NVL funtion as a test of multi-param functions...
simple.setPay(null);
s.update(simple);
- Integer value = (Integer) s.find("select MOD( NVL(s.pay, 5000), 2 ) from Simple as s where s.id = 10").get(0);
+ Integer value = (Integer) s.createQuery(
+ "select MOD( NVL(s.pay, 5000), 2 ) from Simple as s where s.id = 10"
+ ).list()
+ .get(0);
assertTrue( 0 == value.intValue() );
}
if ( (getDialect() instanceof HSQLDialect) ) {
// Test the hsql standard MOD funtion as a test of multi-param functions...
- Integer value = (Integer) s.find("select MOD(s.count, 2) from Simple as s where s.id = 10" ).get(0);
+ Integer value = (Integer) s.createQuery( "select MOD(s.count, 2) from Simple as s where s.id = 10" )
+ .list()
+ .get(0);
assertTrue( 0 == value.intValue() );
}
@@ -358,32 +363,35 @@
s.save(simple, new Long(10) );
if ( getDialect() instanceof DB2Dialect) {
- s.find("from Simple s where repeat('foo', 3) = 'foofoofoo'");
- s.find("from Simple s where repeat(s.name, 3) = 'foofoofoo'");
- s.find("from Simple s where repeat( lower(s.name), 3 + (1-1) / 2) = 'foofoofoo'");
+ s.createQuery( "from Simple s where repeat('foo', 3) = 'foofoofoo'" ).list();
+ s.createQuery( "from Simple s where repeat(s.name, 3) = 'foofoofoo'" ).list();
+ s.createQuery( "from Simple s where repeat( lower(s.name), 3 + (1-1) / 2) = 'foofoofoo'" ).list();
}
assertTrue(
- s.find("from Simple s where upper( s.name ) ='SIMPLE 1'").size()==1
+ s.createQuery( "from Simple s where upper( s.name ) ='SIMPLE 1'" ).list().size()==1
);
if ( !(getDialect() instanceof HSQLDialect) ) {
assertTrue(
- s.find("from Simple s where not( upper( s.name ) ='yada' or 1=2 or 'foo'='bar' or not('foo'='foo') or 'foo' like 'bar' )").size()==1
+ s.createQuery(
+ "from Simple s where not( upper( s.name ) ='yada' or 1=2 or 'foo'='bar' or not('foo'='foo') or 'foo' like 'bar' )"
+ ).list()
+ .size()==1
);
}
if ( !(getDialect() instanceof MySQLDialect) && !(getDialect() instanceof SybaseDialect) && !(getDialect() instanceof SQLServerDialect) && !(getDialect() instanceof MckoiDialect) && !(getDialect() instanceof InterbaseDialect) && !(getDialect() instanceof TimesTenDialect) ) { //My SQL has a funny concatenation operator
assertTrue(
- s.find("from Simple s where lower( s.name || ' foo' ) ='simple 1 foo'").size()==1
+ s.createQuery( "from Simple s where lower( s.name || ' foo' ) ='simple 1 foo'" ).list().size()==1
);
}
if ( (getDialect() instanceof SybaseDialect) ) {
assertTrue(
- s.find("from Simple s where lower( s.name + ' foo' ) ='simple 1 foo'").size()==1
+ s.createQuery( "from Simple s where lower( s.name + ' foo' ) ='simple 1 foo'" ).list().size()==1
);
}
if ( (getDialect() instanceof MckoiDialect) || (getDialect() instanceof TimesTenDialect)) {
assertTrue(
- s.find("from Simple s where lower( concat(s.name, ' foo') ) ='simple 1 foo'").size()==1
+ s.createQuery( "from Simple s where lower( concat(s.name, ' foo') ) ='simple 1 foo'" ).list().size()==1
);
}
@@ -394,44 +402,61 @@
s.save( other, new Long(20) );
//s.find("from Simple s where s.name ## 'cat|rat|bag'");
assertTrue(
- s.find("from Simple s where upper( s.other.name ) ='SIMPLE 2'").size()==1
+ s.createQuery( "from Simple s where upper( s.other.name ) ='SIMPLE 2'" ).list().size()==1
);
assertTrue(
- s.find("from Simple s where not ( upper( s.other.name ) ='SIMPLE 2' )").size()==0
+ s.createQuery( "from Simple s where not ( upper( s.other.name ) ='SIMPLE 2' )" ).list().size()==0
);
assertTrue(
- s.find("select distinct s from Simple s where ( ( s.other.count + 3 ) = (15*2)/2 and s.count = 69) or ( ( s.other.count + 2 ) / 7 ) = 2").size()==1
+ s.createQuery(
+ "select distinct s from Simple s where ( ( s.other.count + 3 ) = (15*2)/2 and s.count = 69) or ( ( s.other.count + 2 ) / 7 ) = 2"
+ ).list()
+ .size()==1
);
assertTrue(
- s.find("select s from Simple s where ( ( s.other.count + 3 ) = (15*2)/2 and s.count = 69) or ( ( s.other.count + 2 ) / 7 ) = 2 order by s.other.count").size()==1
+ s.createQuery(
+ "select s from Simple s where ( ( s.other.count + 3 ) = (15*2)/2 and s.count = 69) or ( ( s.other.count + 2 ) / 7 ) = 2 order by s.other.count"
+ ).list()
+ .size()==1
);
Simple min = new Simple();
min.setCount(-1);
s.save(min, new Long(30) );
if ( ! (getDialect() instanceof MySQLDialect) && ! (getDialect() instanceof HSQLDialect) ) { //My SQL has no subqueries
assertTrue(
- s.find("from Simple s where s.count > ( select min(sim.count) from Simple sim )").size()==2
+ s.createQuery( "from Simple s where s.count > ( select min(sim.count) from Simple sim )" )
+ .list()
+ .size()==2
);
t.commit();
t = s.beginTransaction();
assertTrue(
- s.find("from Simple s where s = some( select sim from Simple sim where sim.count>=0 ) and s.count >= 0").size()==2
+ s.createQuery(
+ "from Simple s where s = some( select sim from Simple sim where sim.count>=0 ) and s.count >= 0"
+ ).list()
+ .size()==2
);
assertTrue(
- s.find("from Simple s where s = some( select sim from Simple sim where sim.other.count=s.other.count ) and s.other.count > 0").size()==1
+ s.createQuery(
+ "from Simple s where s = some( select sim from Simple sim where sim.other.count=s.other.count ) and s.other.count > 0"
+ ).list()
+ .size()==1
);
}
- Iterator iter = s.iterate("select sum(s.count) from Simple s group by s.count having sum(s.count) > 10");
+ Iterator iter = s.createQuery( "select sum(s.count) from Simple s group by s.count having sum(s.count) > 10" )
+ .iterate();
assertTrue( iter.hasNext() );
assertEquals( new Long(12), iter.next() );
assertTrue( !iter.hasNext() );
if ( ! (getDialect() instanceof MySQLDialect) ) {
- iter = s.iterate("select s.count from Simple s group by s.count having s.count = 12");
+ iter = s.createQuery( "select s.count from Simple s group by s.count having s.count = 12" ).iterate();
assertTrue( iter.hasNext() );
}
- s.iterate("select s.id, s.count, count(t), max(t.date) from Simple s, Simple t where s.count = t.count group by s.id, s.count order by s.count");
+ s.createQuery(
+ "select s.id, s.count, count(t), max(t.date) from Simple s, Simple t where s.count = t.count group by s.id, s.count order by s.count"
+ ).iterate();
Query q = s.createQuery("from Simple s");
q.setMaxResults(10);
@@ -594,7 +619,7 @@
s = openSession();
t = s.beginTransaction();
- List result = s.find(query);
+ List result = s.createQuery( query ).list();
assertTrue( result.size() == 1 );
assertTrue(result.get(0) instanceof Simple);
s.delete( result.get(0) );
Modified: core/trunk/testsuite/src/test/java/org/hibernate/test/stateless/fetching/StatelessSessionFetchingTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/stateless/fetching/StatelessSessionFetchingTest.java 2009-05-11 21:12:30 UTC (rev 16535)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/stateless/fetching/StatelessSessionFetchingTest.java 2009-05-11 21:13:36 UTC (rev 16536)
@@ -28,7 +28,6 @@
import org.hibernate.junit.functional.FunctionalTestCase;
import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
import org.hibernate.cfg.Configuration;
-import org.hibernate.cfg.ImprovedNamingStrategy;
import org.hibernate.cfg.DefaultNamingStrategy;
import org.hibernate.util.StringHelper;
import org.hibernate.Session;
15 years, 6 months
Hibernate SVN: r16535 - in core/trunk: testsuite/src/test/java/org/hibernate/test/sql/hand and 1 other directories.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2009-05-11 17:12:30 -0400 (Mon, 11 May 2009)
New Revision: 16535
Added:
core/trunk/testsuite/src/test/java/org/hibernate/test/sql/hand/Group.java
Modified:
core/trunk/core/src/main/java/org/hibernate/loader/custom/sql/SQLQueryReturnProcessor.java
core/trunk/testsuite/src/test/java/org/hibernate/test/sql/hand/Person.java
core/trunk/testsuite/src/test/java/org/hibernate/test/sql/hand/query/NativeSQLQueries.hbm.xml
core/trunk/testsuite/src/test/java/org/hibernate/test/sql/hand/query/NativeSQLQueriesTest.java
Log:
HHH-2745 - NullPointerException when eager fetching joined many-to-many with native SQL query
Modified: core/trunk/core/src/main/java/org/hibernate/loader/custom/sql/SQLQueryReturnProcessor.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/loader/custom/sql/SQLQueryReturnProcessor.java 2009-05-11 20:36:29 UTC (rev 16534)
+++ core/trunk/core/src/main/java/org/hibernate/loader/custom/sql/SQLQueryReturnProcessor.java 2009-05-11 21:12:30 UTC (rev 16535)
@@ -397,7 +397,7 @@
alias2CollectionSuffix.put( alias, suffix );
collectionPropertyResultMaps.put( alias, propertyResults );
- if ( collectionPersister.isOneToMany() ) {
+ if ( collectionPersister.isOneToMany() || collectionPersister.isManyToMany() ) {
SQLLoadable persister = ( SQLLoadable ) collectionPersister.getElementPersister();
addPersister( alias, filter( propertyResults ), persister );
}
Added: core/trunk/testsuite/src/test/java/org/hibernate/test/sql/hand/Group.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/sql/hand/Group.java (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/sql/hand/Group.java 2009-05-11 21:12:30 UTC (rev 16535)
@@ -0,0 +1,67 @@
+/*
+ * Copyright (c) 2009, 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.sql.hand;
+
+import java.util.List;
+import java.util.ArrayList;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+public class Group {
+ private Long id;
+ private List persons = new ArrayList();
+ private String name;
+
+ public Group() {
+ }
+
+ public Group(String name) {
+ this.name = name;
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public List getPersons() {
+ return persons;
+ }
+
+ public void setPersons(List persons) {
+ this.persons = persons;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+}
Modified: core/trunk/testsuite/src/test/java/org/hibernate/test/sql/hand/Person.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/sql/hand/Person.java 2009-05-11 20:36:29 UTC (rev 16534)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/sql/hand/Person.java 2009-05-11 21:12:30 UTC (rev 16535)
@@ -1,37 +1,61 @@
-//$Id: Person.java 11486 2007-05-08 21:57:24Z steve.ebersole(a)jboss.com $
+/*
+ * Copyright (c) 2009, 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.sql.hand;
/**
* @author Gavin King
*/
public class Person {
- private long id;
+ private Long id;
private String name;
public Person(String name) {
this.name = name;
}
-
- public Person() {}
-
-/**
+
+ public Person() {
+ }
+
+ /**
* @return Returns the id.
*/
- public long getId() {
+ public Long getId() {
return id;
}
+
/**
* @param id The id to set.
*/
- public void setId(long id) {
+ public void setId(Long id) {
this.id = id;
}
+
/**
* @return Returns the name.
*/
public String getName() {
return name;
}
+
/**
* @param name The name to set.
*/
Modified: core/trunk/testsuite/src/test/java/org/hibernate/test/sql/hand/query/NativeSQLQueries.hbm.xml
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/sql/hand/query/NativeSQLQueries.hbm.xml 2009-05-11 20:36:29 UTC (rev 16534)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/sql/hand/query/NativeSQLQueries.hbm.xml 2009-05-11 21:12:30 UTC (rev 16535)
@@ -28,8 +28,20 @@
<generator class="increment"/>
</id>
<property name="name" column="NAME" not-null="true"/>
-
</class>
+
+ <class name="Group" table="GROUPP">
+ <id name="id" unsaved-value="0" column="ID">
+ <generator class="increment"/>
+ </id>
+ <property name="name" column="NAME" not-null="true"/>
+ <list name="persons" table="GROUP_PERSON"
+ cascade="none" inverse="false" lazy="true">
+ <key column="GROUP_ID" />
+ <list-index column="POS" />
+ <many-to-many class="Person" column="PERSON_ID" />
+ </list>
+ </class>
<class name="Employment" table="EMPLOYMENT">
<id name="employmentId" unsaved-value="0" column="EMPID">
@@ -259,4 +271,32 @@
LEFT OUTER JOIN EMPLOYMENT emp ON org.ORGID = emp.EMPLOYER
</sql-query>
+ <sql-query name="manyToManyFetch">
+ <![CDATA[
+ SELECT groupp.ID as group_id,
+ groupp.NAME as group_name,
+ group_person.PERSON_ID as group_person_personId,
+ group_person.GROUP_ID as group_person_groupId,
+ group_person.POS as group_person_pos,
+ person.PERID as person_id,
+ person.NAME as person_name
+ FROM GROUPP groupp,
+ GROUP_PERSON group_person,
+ PERSON person
+ WHERE groupp.ID = group_person.GROUP_ID
+ and person.PERID = group_person.PERSON_ID
+ ]]>
+ <return alias="groupp" class="Group">
+ <return-property name="id" column="group_id" />
+ <return-property name="name" column="group_name" />
+ </return>
+ <return-join alias="group_person" property="groupp.persons">
+ <return-property name="key" column="group_person_groupId" />
+ <return-property name="index" column="group_person_pos" />
+ <return-property name="element" column="person_id" />
+ <return-property name="element.id" column="person_id" />
+ <return-property name="element.name" column="person_name" />
+ </return-join>
+ </sql-query>
+
</hibernate-mapping>
\ No newline at end of file
Modified: core/trunk/testsuite/src/test/java/org/hibernate/test/sql/hand/query/NativeSQLQueriesTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/sql/hand/query/NativeSQLQueriesTest.java 2009-05-11 20:36:29 UTC (rev 16534)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/sql/hand/query/NativeSQLQueriesTest.java 2009-05-11 21:12:30 UTC (rev 16535)
@@ -23,6 +23,7 @@
import org.hibernate.test.sql.hand.Dimension;
import org.hibernate.test.sql.hand.SpaceShip;
import org.hibernate.test.sql.hand.Speech;
+import org.hibernate.test.sql.hand.Group;
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment;
import org.hibernate.junit.functional.FunctionalTestCase;
@@ -610,6 +611,63 @@
}
}
+ public void testAddJoinForManyToMany() {
+ Session s = openSession();
+ Transaction t = s.beginTransaction();
+ Person gavin = new Person( "Gavin" );
+ Person max = new Person( "Max" );
+ Person pete = new Person( "Pete" );
+
+ Group hibernate = new Group( "Hibernate" );
+ Group seam = new Group( "Seam" );
+
+ s.persist( gavin );
+ s.persist( max );
+ s.persist( pete );
+ s.persist( seam );
+ s.persist( hibernate );
+
+ hibernate.getPersons().add( gavin );
+ hibernate.getPersons().add( max );
+ seam.getPersons().add( gavin );
+ seam.getPersons().add( pete );
+
+ s.flush();
+ s.clear();
+
+ // todo : see http://opensource.atlassian.com/projects/hibernate/browse/HHH-3908
+// String sqlStr = "SELECT {groupp.*} , {gp.*} " +
+// "FROM GROUPP groupp, GROUP_PERSON gp, PERSON person WHERE groupp.ID = gp.GROUP_ID and person.PERID = gp.PERSON_ID";
+//
+// List l = s.createSQLQuery( sqlStr )
+// .addEntity("groupp", Group.class)
+// .addJoin("gp","groupp.persons")
+// .list();
+ List l = s.getNamedQuery( "manyToManyFetch" ).list();
+ //assertEquals( 2, l.size() );
+
+ t.commit();
+ s.close();
+
+ s = openSession();
+ t = s.beginTransaction();
+
+ seam.getPersons().remove( gavin );
+ seam.getPersons().remove( pete );
+
+ hibernate.getPersons().remove( gavin );
+ hibernate.getPersons().remove( max );
+
+ s.delete( seam );
+ s.delete( hibernate );
+ s.delete( gavin );
+ s.delete( max );
+ s.delete( pete );
+
+ t.commit();
+ s.close();
+ }
+
private static class UpperCasedAliasToEntityMapResultTransformer extends BasicTransformerAdapter implements Serializable {
public Object transformTuple(Object[] tuple, String[] aliases) {
Map result = new HashMap( tuple.length );
15 years, 6 months
Hibernate SVN: r16534 - core/branches/Branch_3_3/parent.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2009-05-11 16:36:29 -0400 (Mon, 11 May 2009)
New Revision: 16534
Modified:
core/branches/Branch_3_3/parent/pom.xml
Log:
upgrade maven-javadoc-plugin
Modified: core/branches/Branch_3_3/parent/pom.xml
===================================================================
--- core/branches/Branch_3_3/parent/pom.xml 2009-05-11 14:10:17 UTC (rev 16533)
+++ core/branches/Branch_3_3/parent/pom.xml 2009-05-11 20:36:29 UTC (rev 16534)
@@ -174,7 +174,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
- <version>2.4</version>
+ <version>2.5</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
15 years, 6 months
Hibernate SVN: r16533 - core/trunk/annotations/src/test/java/org/hibernate/test/annotations/manytoone.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2009-05-11 10:10:17 -0400 (Mon, 11 May 2009)
New Revision: 16533
Modified:
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/manytoone/Frame.java
Log:
JBPAPP-1075 Removed @Column( unique = true ) - it is not needed for this test and causes problems with Oracle
Modified: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/manytoone/Frame.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/manytoone/Frame.java 2009-05-11 13:19:42 UTC (rev 16532)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/manytoone/Frame.java 2009-05-11 14:10:17 UTC (rev 16533)
@@ -21,7 +21,6 @@
private Long id;
@OneToMany( mappedBy = "frame" )
private Set<Lens> lenses;
- @Column( unique = true )
private String name;
@Formula("lower(name)")
private String lowerName;
15 years, 6 months
Hibernate SVN: r16532 - core/trunk/annotations/src/test/java/org/hibernate/test/annotations/manytomany.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2009-05-11 09:19:42 -0400 (Mon, 11 May 2009)
New Revision: 16532
Modified:
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/manytomany/ManyToManyTest.java
Log:
JBPAPP-1075 removed obsolete @RequiresDialect annotation
Modified: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/manytomany/ManyToManyTest.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/manytomany/ManyToManyTest.java 2009-05-11 13:17:21 UTC (rev 16531)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/manytomany/ManyToManyTest.java 2009-05-11 13:19:42 UTC (rev 16532)
@@ -7,15 +7,12 @@
import java.util.Date;
import java.util.HashSet;
import java.util.Iterator;
-import java.util.List;
import java.util.Set;
import org.hibernate.Hibernate;
import org.hibernate.JDBCException;
import org.hibernate.Session;
import org.hibernate.Transaction;
-import org.hibernate.dialect.HSQLDialect;
-import org.hibernate.test.annotations.RequiresDialect;
import org.hibernate.test.annotations.TestCase;
/**
@@ -81,7 +78,6 @@
s.close();
}
- @RequiresDialect(HSQLDialect.class)
public void testDefaultCompositePk() throws Exception {
Session s;
Transaction tx;
@@ -424,7 +420,6 @@
s.close();
}
- @RequiresDialect(HSQLDialect.class)
public void testCompositePk() throws Exception {
Session s;
Transaction tx;
15 years, 6 months