Hibernate SVN: r10939 - trunk/Hibernate3/src/org/hibernate/jdbc
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2006-12-07 07:59:08 -0500 (Thu, 07 Dec 2006)
New Revision: 10939
Modified:
trunk/Hibernate3/src/org/hibernate/jdbc/ConnectionManager.java
Log:
bug in borrowed connection releasing
Modified: trunk/Hibernate3/src/org/hibernate/jdbc/ConnectionManager.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/jdbc/ConnectionManager.java 2006-12-07 05:21:17 UTC (rev 10938)
+++ trunk/Hibernate3/src/org/…
[View More]hibernate/jdbc/ConnectionManager.java 2006-12-07 12:59:08 UTC (rev 10939)
@@ -168,8 +168,12 @@
public void releaseBorrowedConnection() {
if ( borrowedConnection != null ) {
- borrowedConnection = null;
- BorrowedConnectionProxy.renderUnuseable( borrowedConnection );
+ try {
+ BorrowedConnectionProxy.renderUnuseable( borrowedConnection );
+ }
+ finally {
+ borrowedConnection = null;
+ }
}
}
[View Less]
18 years, 3 months
Hibernate SVN: r10938 - in branches/Branch_3_2/HibernateExt/metadata/src: java/org/hibernate/annotations java/org/hibernate/cfg java/org/hibernate/cfg/annotations test/org/hibernate/test/annotations test/org/hibernate/test/annotations/target
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2006-12-07 00:21:17 -0500 (Thu, 07 Dec 2006)
New Revision: 10938
Added:
branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/annotations/Target.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/target/
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/target/Brand.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/target/Luggage.java
…
[View More]branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/target/LuggageImpl.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/target/Owner.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/target/OwnerImpl.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/target/Size.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/target/SizeImpl.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/target/TargetTest.java
Modified:
branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/annotations/MapKey.java
branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/annotations/MapKeyManyToMany.java
branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/cfg/AnnotationBinder.java
branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/cfg/PropertyInferredData.java
branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/IdBagBinder.java
branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/MapBinder.java
branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/SimpleValueBinder.java
Log:
ANN-395 ANN-422 support for target definition on regular properties and map keys
Modified: branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/annotations/MapKey.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/annotations/MapKey.java 2006-12-06 13:05:04 UTC (rev 10937)
+++ branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/annotations/MapKey.java 2006-12-07 05:21:17 UTC (rev 10938)
@@ -19,4 +19,9 @@
@Retention(RUNTIME)
public @interface MapKey {
Column[] columns() default {};
+ /**
+ * Represent the key class in a Map
+ * Only useful if the collection does not use generics
+ */
+ Class targetElement() default void.class;
}
Modified: branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/annotations/MapKeyManyToMany.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/annotations/MapKeyManyToMany.java 2006-12-06 13:05:04 UTC (rev 10937)
+++ branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/annotations/MapKeyManyToMany.java 2006-12-07 05:21:17 UTC (rev 10938)
@@ -18,4 +18,9 @@
@Retention(RetentionPolicy.RUNTIME)
public @interface MapKeyManyToMany {
JoinColumn[] joinColumns() default {};
+ /**
+ * Represent the key class in a Map
+ * Only useful if the collection does not use generics
+ */
+ Class targetEntity() default void.class;
}
Added: branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/annotations/Target.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/annotations/Target.java 2006-12-06 13:05:04 UTC (rev 10937)
+++ branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/annotations/Target.java 2006-12-07 05:21:17 UTC (rev 10938)
@@ -0,0 +1,17 @@
+//$Id: $
+package org.hibernate.annotations;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.RetentionPolicy;
+
+/**
+ * Define an explicit target,a voiding reflection and generics resolving
+ *
+ * @author Emmanuel Bernard
+ */
+(a)java.lang.annotation.Target({ElementType.FIELD, ElementType.METHOD})
+@Retention( RetentionPolicy.RUNTIME )
+public @interface Target {
+ Class value();
+}
Modified: branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/cfg/AnnotationBinder.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/cfg/AnnotationBinder.java 2006-12-06 13:05:04 UTC (rev 10937)
+++ branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/cfg/AnnotationBinder.java 2006-12-07 05:21:17 UTC (rev 10938)
@@ -88,6 +88,7 @@
import org.hibernate.annotations.TypeDefs;
import org.hibernate.annotations.Where;
import org.hibernate.annotations.Index;
+import org.hibernate.annotations.Target;
import org.hibernate.cfg.annotations.CollectionBinder;
import org.hibernate.cfg.annotations.EntityBinder;
import org.hibernate.cfg.annotations.Nullability;
@@ -962,24 +963,27 @@
.equals( void.class ) ) {
return true;
}
- if ( p.isAnnotationPresent( OneToMany.class ) && !p.getAnnotation( OneToMany.class )
+ else if ( p.isAnnotationPresent( OneToMany.class ) && !p.getAnnotation( OneToMany.class )
.targetEntity()
.equals( void.class ) ) {
return true;
}
- if ( p.isAnnotationPresent( ManyToOne.class ) && !p.getAnnotation( ManyToOne.class )
+ else if ( p.isAnnotationPresent( ManyToOne.class ) && !p.getAnnotation( ManyToOne.class )
.targetEntity()
.equals( void.class ) ) {
return true;
}
- if ( p.isAnnotationPresent( ManyToMany.class ) && !p.getAnnotation( ManyToMany.class )
+ else if ( p.isAnnotationPresent( ManyToMany.class ) && !p.getAnnotation( ManyToMany.class )
.targetEntity()
.equals( void.class ) ) {
return true;
}
- if (p.isAnnotationPresent( Type.class ) ) {
+ else if (p.isAnnotationPresent( Type.class ) ) {
return true;
}
+ else if ( p.isAnnotationPresent( Target.class ) ) {
+ return true;
+ }
return false;
}
@@ -988,7 +992,9 @@
String propertyAccessor, ExtendedMappings mappings
) {
boolean hasIdentifier = false;
- PropertyData propertyAnnotatedElement = new PropertyInferredData( property, propertyAccessor );
+ PropertyData propertyAnnotatedElement = new PropertyInferredData(
+ property, propertyAccessor,
+ mappings.getReflectionManager() );
if ( ! mustBeSkipped( propertyAnnotatedElement.getProperty(), mappings ) ) {
/*
* put element annotated by @Id in front
Modified: branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/cfg/PropertyInferredData.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/cfg/PropertyInferredData.java 2006-12-06 13:05:04 UTC (rev 10937)
+++ branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/cfg/PropertyInferredData.java 2006-12-07 05:21:17 UTC (rev 10938)
@@ -2,9 +2,12 @@
package org.hibernate.cfg;
import org.hibernate.MappingException;
+import org.hibernate.AssertionFailure;
import org.hibernate.annotations.AccessType;
+import org.hibernate.annotations.Target;
import org.hibernate.reflection.XClass;
import org.hibernate.reflection.XProperty;
+import org.hibernate.reflection.ReflectionManager;
/**
* Retrieve all inferred data from an annnoted element
@@ -16,13 +19,15 @@
private final String defaultAccess;
private final XProperty property;
+ private final ReflectionManager reflectionManager;
/**
* Take the annoted element for lazy process
*/
- public PropertyInferredData(XProperty property, String propertyAccessor) {
+ public PropertyInferredData(XProperty property, String propertyAccessor, ReflectionManager reflectionManager) {
this.property = property;
this.defaultAccess = propertyAccessor;
+ this.reflectionManager = reflectionManager;
}
public String getDefaultAccess() throws MappingException {
@@ -37,19 +42,29 @@
}
public XClass getPropertyClass() throws MappingException {
- return property.getType();
+ if ( property.isAnnotationPresent( Target.class ) ) {
+ return reflectionManager.toXClass( property.getAnnotation( Target.class ).value() );
+ }
+ else {
+ return property.getType();
+ }
}
public XClass getClassOrElement() throws MappingException {
- return property.getClassOrElementClass();
+ if ( property.isAnnotationPresent( Target.class ) ) {
+ return reflectionManager.toXClass( property.getAnnotation( Target.class ).value() );
+ }
+ else {
+ return property.getClassOrElementClass();
+ }
}
public String getClassOrElementName() throws MappingException {
- return property.getClassOrElementClass().getName();
+ return getClassOrElement().getName();
}
public String getTypeName() throws MappingException {
- return property.getType().getName();
+ return getPropertyClass().getName();
}
public XProperty getProperty() {
Modified: branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/IdBagBinder.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/IdBagBinder.java 2006-12-06 13:05:04 UTC (rev 10937)
+++ branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/IdBagBinder.java 2006-12-07 05:21:17 UTC (rev 10938)
@@ -45,7 +45,8 @@
SimpleValueBinder simpleValue = new SimpleValueBinder();
PropertyData propertyData = new WrappedInferredData(
- new PropertyInferredData(property, null), //default access should not be useful
+ new PropertyInferredData(property, null, //default access should not be useful
+ mappings.getReflectionManager() ),
"id" );
Ejb3Column[] idColumns = Ejb3Column.buildColumnFromAnnotation(
collectionIdAnn.columns(),
Modified: branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/MapBinder.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/MapBinder.java 2006-12-06 13:05:04 UTC (rev 10937)
+++ branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/MapBinder.java 2006-12-07 05:21:17 UTC (rev 10938)
@@ -7,11 +7,13 @@
import java.util.Random;
import javax.persistence.AttributeOverride;
import javax.persistence.AttributeOverrides;
+import javax.persistence.MapKey;
import org.hibernate.AnnotationException;
import org.hibernate.AssertionFailure;
import org.hibernate.FetchMode;
import org.hibernate.MappingException;
+import org.hibernate.annotations.MapKeyManyToMany;
import org.hibernate.cfg.AnnotatedClassType;
import org.hibernate.cfg.AnnotationBinder;
import org.hibernate.cfg.BinderHelper;
@@ -40,6 +42,7 @@
import org.hibernate.mapping.Value;
import org.hibernate.reflection.XClass;
import org.hibernate.reflection.XProperty;
+import org.hibernate.reflection.ReflectionManager;
import org.hibernate.sql.Template;
import org.hibernate.util.StringHelper;
@@ -109,14 +112,30 @@
else {
//this is a true Map mapping
//TODO ugly copy/pastle from CollectionBinder.bindManyToManySecondPass
- String mapKeyType = property.getMapKey().getName();
+ String mapKeyType;
+ Class target = void.class;
+ /*
+ * target has priority over reflection for the map key type
+ */
+ if ( property.isAnnotationPresent( org.hibernate.annotations.MapKey.class ) ) {
+ ReflectionManager reflectionManager = mappings.getReflectionManager();
+ target = property.getAnnotation( org.hibernate.annotations.MapKey.class ).targetElement();
+ }
+ else if ( property.isAnnotationPresent( MapKeyManyToMany.class ) ) {
+ target = property.getAnnotation( MapKeyManyToMany.class ).targetEntity();
+ }
+ if ( ! void.class.equals( target ) ) {
+ mapKeyType = target.getName();
+ }
+ else {
+ mapKeyType = property.getMapKey().getName();
+ }
PersistentClass collectionEntity = (PersistentClass) persistentClasses.get( mapKeyType );
boolean isIndexOfEntities = collectionEntity != null;
ManyToOne element = null;
org.hibernate.mapping.Map mapValue = (org.hibernate.mapping.Map) this.collection;
if ( isIndexOfEntities ) {
- element =
- new ManyToOne( mapValue.getCollectionTable() );
+ element = new ManyToOne( mapValue.getCollectionTable() );
mapValue.setIndex( element );
element.setReferencedEntityName( mapKeyType );
//element.setFetchMode( fetchMode );
Modified: branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/SimpleValueBinder.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/SimpleValueBinder.java 2006-12-06 13:05:04 UTC (rev 10937)
+++ branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/SimpleValueBinder.java 2006-12-07 05:21:17 UTC (rev 10938)
@@ -83,10 +83,10 @@
if ( property.isAnnotationPresent( Temporal.class ) ) {
Temporal ann = property.getAnnotation( Temporal.class );
boolean isDate;
- if ( mappings.getReflectionManager().equals( property.getType(), Date.class ) ) {
+ if ( mappings.getReflectionManager().equals( returnedClassOrElement, Date.class ) ) {
isDate = true;
}
- else if ( mappings.getReflectionManager().equals( property.getType(), Calendar.class ) ) {
+ else if ( mappings.getReflectionManager().equals( returnedClassOrElement, Calendar.class ) ) {
isDate = false;
}
else {
Added: branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/target/Brand.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/target/Brand.java 2006-12-06 13:05:04 UTC (rev 10937)
+++ branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/target/Brand.java 2006-12-07 05:21:17 UTC (rev 10938)
@@ -0,0 +1,56 @@
+//$Id: $
+package org.hibernate.test.annotations.target;
+
+import java.util.Map;
+import java.util.HashMap;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.GeneratedValue;
+import javax.persistence.ManyToMany;
+
+import org.hibernate.annotations.MapKey;
+import org.hibernate.annotations.CollectionOfElements;
+import org.hibernate.annotations.MapKeyManyToMany;
+
+/**
+ * @author Emmanuel Bernard
+ */
+@Entity
+public class Brand {
+ @Id
+ @GeneratedValue
+ private Long id;
+
+ @ManyToMany(targetEntity = LuggageImpl.class)
+ @MapKey(targetElement = SizeImpl.class)
+ private Map<Size, Luggage> luggagesBySize = new HashMap<Size, Luggage>();
+
+ @CollectionOfElements(targetElement = SizeImpl.class)
+ @MapKeyManyToMany(targetEntity = LuggageImpl.class)
+ private Map<Luggage, Size> sizePerLuggage = new HashMap<Luggage, Size>();
+
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public Map<Size, Luggage> getLuggagesBySize() {
+ return luggagesBySize;
+ }
+
+ public void setLuggagesBySize(Map<Size, Luggage> luggagesBySize) {
+ this.luggagesBySize = luggagesBySize;
+ }
+
+ public Map<Luggage, Size> getSizePerLuggage() {
+ return sizePerLuggage;
+ }
+
+ public void setSizePerLuggage(Map<Luggage, Size> sizePerLuggage) {
+ this.sizePerLuggage = sizePerLuggage;
+ }
+}
Added: branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/target/Luggage.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/target/Luggage.java 2006-12-06 13:05:04 UTC (rev 10937)
+++ branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/target/Luggage.java 2006-12-07 05:21:17 UTC (rev 10938)
@@ -0,0 +1,17 @@
+//$Id: $
+package org.hibernate.test.annotations.target;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public interface Luggage {
+ double getHeight();
+ double getWidth();
+
+ void setHeight(double height);
+ void setWidth(double width);
+
+ Owner getOwner();
+
+ void setOwner(Owner owner);
+}
Added: branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/target/LuggageImpl.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/target/LuggageImpl.java 2006-12-06 13:05:04 UTC (rev 10937)
+++ branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/target/LuggageImpl.java 2006-12-07 05:21:17 UTC (rev 10938)
@@ -0,0 +1,57 @@
+//$Id: $
+package org.hibernate.test.annotations.target;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.GeneratedValue;
+import javax.persistence.ManyToOne;
+import javax.persistence.Embedded;
+
+import org.hibernate.annotations.Target;
+
+/**
+ * @author Emmanuel Bernard
+ */
+@Entity
+public class LuggageImpl implements Luggage {
+ private Long id;
+ private double height;
+ private double width;
+ private Owner owner;
+
+ @Embedded
+ @Target(OwnerImpl.class)
+ public Owner getOwner() {
+ return owner;
+ }
+
+ public void setOwner(Owner owner) {
+ this.owner = owner;
+ }
+
+ @Id
+ @GeneratedValue
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public double getHeight() {
+ return height;
+ }
+
+ public void setHeight(double height) {
+ this.height = height;
+ }
+
+ public double getWidth() {
+ return width;
+ }
+
+ public void setWidth(double width) {
+ this.width = width;
+ }
+}
Added: branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/target/Owner.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/target/Owner.java 2006-12-06 13:05:04 UTC (rev 10937)
+++ branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/target/Owner.java 2006-12-07 05:21:17 UTC (rev 10938)
@@ -0,0 +1,12 @@
+//$Id: $
+package org.hibernate.test.annotations.target;
+
+import java.util.Map;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public interface Owner {
+ String getName();
+ void setName(String name);
+}
Added: branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/target/OwnerImpl.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/target/OwnerImpl.java 2006-12-06 13:05:04 UTC (rev 10937)
+++ branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/target/OwnerImpl.java 2006-12-07 05:21:17 UTC (rev 10938)
@@ -0,0 +1,24 @@
+//$Id: $
+package org.hibernate.test.annotations.target;
+
+import java.util.Map;
+import java.util.HashMap;
+import javax.persistence.Embeddable;
+import org.hibernate.annotations.MapKey;
+import javax.persistence.ManyToMany;
+
+/**
+ * @author Emmanuel Bernard
+ */
+@Embeddable
+public class OwnerImpl implements Owner {
+ private String name;
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+}
Added: branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/target/Size.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/target/Size.java 2006-12-06 13:05:04 UTC (rev 10937)
+++ branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/target/Size.java 2006-12-07 05:21:17 UTC (rev 10938)
@@ -0,0 +1,10 @@
+//$Id: $
+package org.hibernate.test.annotations.target;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public interface Size {
+ String getName();
+ void setName(String name);
+}
Added: branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/target/SizeImpl.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/target/SizeImpl.java 2006-12-06 13:05:04 UTC (rev 10937)
+++ branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/target/SizeImpl.java 2006-12-07 05:21:17 UTC (rev 10938)
@@ -0,0 +1,20 @@
+//$Id: $
+package org.hibernate.test.annotations.target;
+
+import javax.persistence.Embeddable;
+
+/**
+ * @author Emmanuel Bernard
+ */
+@Embeddable
+public class SizeImpl implements Size {
+ private String name;
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+}
Added: branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/target/TargetTest.java
===================================================================
--- branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/target/TargetTest.java 2006-12-06 13:05:04 UTC (rev 10937)
+++ branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/target/TargetTest.java 2006-12-07 05:21:17 UTC (rev 10938)
@@ -0,0 +1,82 @@
+//$Id: $
+package org.hibernate.test.annotations.target;
+
+import org.hibernate.test.annotations.TestCase;
+import org.hibernate.Session;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class TargetTest extends TestCase {
+
+ public void testTargetOnEmbedded() throws Exception {
+ Session s = openSession();
+ s.getTransaction().begin();
+ Luggage l = new LuggageImpl();
+ l.setHeight( 12 );
+ l.setWidth( 12 );
+ Owner o = new OwnerImpl();
+ o.setName( "Emmanuel" );
+ l.setOwner( o );
+ s.persist( l );
+ s.flush();
+ s.clear();
+ l = (Luggage) s.get(LuggageImpl.class, ( (LuggageImpl) l).getId() );
+ assertEquals( "Emmanuel", l.getOwner().getName() );
+ s.getTransaction().rollback();
+ s.close();
+ }
+
+ public void testTargetOnMapKey() throws Exception {
+ Session s = openSession();
+ s.getTransaction().begin();
+ Luggage l = new LuggageImpl();
+ l.setHeight( 12 );
+ l.setWidth( 12 );
+ Size size = new SizeImpl();
+ size.setName( "S" );
+ Owner o = new OwnerImpl();
+ o.setName( "Emmanuel" );
+ l.setOwner( o );
+ s.persist( l );
+ Brand b = new Brand();
+ s.persist( b );
+ b.getLuggagesBySize().put( size, l );
+ s.flush();
+ s.clear();
+ b = (Brand) s.get(Brand.class, b.getId() );
+ assertEquals( "S", b.getLuggagesBySize().keySet().iterator().next().getName() );
+ s.getTransaction().rollback();
+ s.close();
+ }
+
+ public void testTargetOnMapKeyManyToMany() throws Exception {
+ Session s = openSession();
+ s.getTransaction().begin();
+ Luggage l = new LuggageImpl();
+ l.setHeight( 12 );
+ l.setWidth( 12 );
+ Size size = new SizeImpl();
+ size.setName( "S" );
+ Owner o = new OwnerImpl();
+ o.setName( "Emmanuel" );
+ l.setOwner( o );
+ s.persist( l );
+ Brand b = new Brand();
+ s.persist( b );
+ b.getSizePerLuggage().put( l, size );
+ s.flush();
+ s.clear();
+ b = (Brand) s.get(Brand.class, b.getId() );
+ assertEquals( 12d, b.getSizePerLuggage().keySet().iterator().next().getWidth() );
+ s.getTransaction().rollback();
+ s.close();
+ }
+
+ protected Class[] getMappings() {
+ return new Class[] {
+ LuggageImpl.class,
+ Brand.class
+ };
+ }
+}
[View Less]
18 years, 3 months
Hibernate SVN: r10937 - in branches/Branch_3_2/Hibernate3: src/org/hibernate/dialect src/org/hibernate/hql/ast/exec test/org/hibernate/test test/org/hibernate/test/hql
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2006-12-06 08:05:04 -0500 (Wed, 06 Dec 2006)
New Revision: 10937
Modified:
branches/Branch_3_2/Hibernate3/src/org/hibernate/dialect/Cache71Dialect.java
branches/Branch_3_2/Hibernate3/src/org/hibernate/dialect/Dialect.java
branches/Branch_3_2/Hibernate3/src/org/hibernate/dialect/MySQLDialect.java
branches/Branch_3_2/Hibernate3/src/org/hibernate/hql/ast/exec/AbstractStatementExecutor.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/…
[View More]test/TestCase.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/hql/BulkManipulationTest.java
Log:
HHH-2221 : MySQL and temporary table creation
Modified: branches/Branch_3_2/Hibernate3/src/org/hibernate/dialect/Cache71Dialect.java
===================================================================
--- branches/Branch_3_2/Hibernate3/src/org/hibernate/dialect/Cache71Dialect.java 2006-12-06 13:04:31 UTC (rev 10936)
+++ branches/Branch_3_2/Hibernate3/src/org/hibernate/dialect/Cache71Dialect.java 2006-12-06 13:05:04 UTC (rev 10937)
@@ -451,8 +451,8 @@
return "create global temporary table";
}
- public boolean performTemporaryTableDDLInIsolation() {
- return false;
+ public Boolean performTemporaryTableDDLInIsolation() {
+ return Boolean.FALSE;
}
public String getCreateTemporaryTablePostfix() {
Modified: branches/Branch_3_2/Hibernate3/src/org/hibernate/dialect/Dialect.java
===================================================================
--- branches/Branch_3_2/Hibernate3/src/org/hibernate/dialect/Dialect.java 2006-12-06 13:04:31 UTC (rev 10936)
+++ branches/Branch_3_2/Hibernate3/src/org/hibernate/dialect/Dialect.java 2006-12-06 13:05:04 UTC (rev 10937)
@@ -943,14 +943,30 @@
}
/**
- * Does the dialect require that temporary table DDL statements
- * occur in isolation from other statements?
- * todo : perhaps have this return java.lang.Boolean instead where null means to use the value returned by the driver.
- *
- * @return
+ * Does the dialect require that temporary table DDL statements occur in
+ * isolation from other statements? This would be the case if the creation
+ * would cause any current transaction to get committed implicitly.
+ * <p/>
+ * JDBC defines a standard way to query for this information via the
+ * {@link java.sql.DatabaseMetaData#dataDefinitionCausesTransactionCommit()}
+ * method. However, that does not distinguish between temporary table
+ * DDL and other forms of DDL; MySQL, for example, reports DDL causing a
+ * transaction commit via its driver, even though that is not the case for
+ * temporary table DDL.
+ * <p/>
+ * Possible return values and their meanings:<ul>
+ * <li>{@link Boolean#TRUE} - Unequivocally, perform the temporary table DDL
+ * in isolation.</li>
+ * <li>{@link Boolean#FALSE} - Unequivocally, do <b>not</b> perform the
+ * temporary table DDL in isolation.</li>
+ * <li><i>null</i> - defer to the JDBC driver response in regards to
+ * {@link java.sql.DatabaseMetaData#dataDefinitionCausesTransactionCommit()}</li>
+ * </ul>
+ *
+ * @return see the result matrix above.
*/
- public boolean performTemporaryTableDDLInIsolation() {
- return false;
+ public Boolean performTemporaryTableDDLInIsolation() {
+ return null;
}
/**
Modified: branches/Branch_3_2/Hibernate3/src/org/hibernate/dialect/MySQLDialect.java
===================================================================
--- branches/Branch_3_2/Hibernate3/src/org/hibernate/dialect/MySQLDialect.java 2006-12-06 13:04:31 UTC (rev 10936)
+++ branches/Branch_3_2/Hibernate3/src/org/hibernate/dialect/MySQLDialect.java 2006-12-06 13:05:04 UTC (rev 10937)
@@ -324,4 +324,8 @@
public boolean supportsRowValueConstructorSyntax() {
return true;
}
+
+ public Boolean performTemporaryTableDDLInIsolation() {
+ return Boolean.FALSE;
+ }
}
\ No newline at end of file
Modified: branches/Branch_3_2/Hibernate3/src/org/hibernate/hql/ast/exec/AbstractStatementExecutor.java
===================================================================
--- branches/Branch_3_2/Hibernate3/src/org/hibernate/hql/ast/exec/AbstractStatementExecutor.java 2006-12-06 13:04:31 UTC (rev 10936)
+++ branches/Branch_3_2/Hibernate3/src/org/hibernate/hql/ast/exec/AbstractStatementExecutor.java 2006-12-06 13:05:04 UTC (rev 10937)
@@ -130,7 +130,7 @@
}
}
};
- if ( getFactory().getSettings().isDataDefinitionImplicitCommit() || getFactory().getDialect().performTemporaryTableDDLInIsolation() ) {
+ if ( shouldIsolateTemporaryTableDDL() ) {
if ( getFactory().getSettings().isDataDefinitionInTransactionSupported() ) {
Isolater.doIsolatedWork( work, session );
}
@@ -168,7 +168,8 @@
}
}
};
- if ( getFactory().getSettings().isDataDefinitionImplicitCommit() || getFactory().getDialect().performTemporaryTableDDLInIsolation() ) {
+
+ if ( shouldIsolateTemporaryTableDDL() ) {
if ( getFactory().getSettings().isDataDefinitionInTransactionSupported() ) {
Isolater.doIsolatedWork( work, session );
}
@@ -213,4 +214,14 @@
( ( EventSource ) session ).getActionQueue().addAction( action );
}
}
+
+ protected boolean shouldIsolateTemporaryTableDDL() {
+ Boolean dialectVote = getFactory().getDialect().performTemporaryTableDDLInIsolation();
+ if ( dialectVote != null ) {
+ return dialectVote.booleanValue();
+ }
+ else {
+ return getFactory().getSettings().isDataDefinitionImplicitCommit();
+ }
+ }
}
Modified: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/TestCase.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/TestCase.java 2006-12-06 13:04:31 UTC (rev 10936)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/TestCase.java 2006-12-06 13:05:04 UTC (rev 10937)
@@ -629,6 +629,11 @@
return true;
}
+ protected boolean supportsSubqueryOnMutatingTable() {
+ // I only know of MySQL having this limitation...
+ return dialectIsNot( MySQLDialect.class );
+ }
+
private boolean dialectIs(Class dialectClass) {
return dialectClass.isInstance( getDialect() );
}
Modified: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/hql/BulkManipulationTest.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/hql/BulkManipulationTest.java 2006-12-06 13:04:31 UTC (rev 10936)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/hql/BulkManipulationTest.java 2006-12-06 13:05:04 UTC (rev 10937)
@@ -12,7 +12,6 @@
import org.hibernate.Transaction;
import org.hibernate.classic.Session;
import org.hibernate.dialect.MySQLDialect;
-import org.hibernate.engine.SessionFactoryImplementor;
import org.hibernate.hql.ast.HqlSqlWalker;
import org.hibernate.id.IdentifierGenerator;
import org.hibernate.persister.entity.EntityPersister;
@@ -520,15 +519,17 @@
count = s.createQuery( updateQryString ).executeUpdate();
assertEquals( 1, count );
// many-to-many test
- updateQryString = "update SimpleEntityWithAssociation e " +
- "set e.name = 'updated' " +
- "where exists (" +
- " select a.id " +
- " from e.manyToManyAssociatedEntities a " +
- " where a.name = 'many-to-many-association' " +
- ")";
- count = s.createQuery( updateQryString ).executeUpdate();
- assertEquals( 1, count );
+ if ( supportsSubqueryOnMutatingTable() ) {
+ updateQryString = "update SimpleEntityWithAssociation e " +
+ "set e.name = 'updated' " +
+ "where exists (" +
+ " select a.id " +
+ " from e.manyToManyAssociatedEntities a " +
+ " where a.name = 'many-to-many-association' " +
+ ")";
+ count = s.createQuery( updateQryString ).executeUpdate();
+ assertEquals( 1, count );
+ }
s.delete( entity.getManyToManyAssociatedEntities().iterator().next() );
s.delete( entity );
t.commit();
@@ -915,8 +916,10 @@
assertEquals( "incorrect delete count", 1, count );
// HHH-873...
- count = s.createQuery( "delete from User u where u not in (select u from User u)" ).executeUpdate();
- assertEquals( 0, count );
+ if ( supportsSubqueryOnMutatingTable() ) {
+ count = s.createQuery( "delete from User u where u not in (select u from User u)" ).executeUpdate();
+ assertEquals( 0, count );
+ }
count = s.createQuery( "delete Animal a" ).executeUpdate();
assertEquals( "Incorrect delete count", 4, count );
[View Less]
18 years, 3 months
Hibernate SVN: r10936 - in trunk/Hibernate3: src/org/hibernate/dialect src/org/hibernate/hql/ast/exec test/org/hibernate/test test/org/hibernate/test/hql
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2006-12-06 08:04:31 -0500 (Wed, 06 Dec 2006)
New Revision: 10936
Modified:
trunk/Hibernate3/src/org/hibernate/dialect/Cache71Dialect.java
trunk/Hibernate3/src/org/hibernate/dialect/Dialect.java
trunk/Hibernate3/src/org/hibernate/dialect/MySQLDialect.java
trunk/Hibernate3/src/org/hibernate/hql/ast/exec/AbstractStatementExecutor.java
trunk/Hibernate3/test/org/hibernate/test/TestCase.java
trunk/Hibernate3/test/org/hibernate/test/hql/…
[View More]BulkManipulationTest.java
Log:
HHH-2221 : MySQL and temporary table creation
Modified: trunk/Hibernate3/src/org/hibernate/dialect/Cache71Dialect.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/dialect/Cache71Dialect.java 2006-12-05 22:43:52 UTC (rev 10935)
+++ trunk/Hibernate3/src/org/hibernate/dialect/Cache71Dialect.java 2006-12-06 13:04:31 UTC (rev 10936)
@@ -451,8 +451,8 @@
return "create global temporary table";
}
- public boolean performTemporaryTableDDLInIsolation() {
- return false;
+ public Boolean performTemporaryTableDDLInIsolation() {
+ return Boolean.FALSE;
}
public String getCreateTemporaryTablePostfix() {
Modified: trunk/Hibernate3/src/org/hibernate/dialect/Dialect.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/dialect/Dialect.java 2006-12-05 22:43:52 UTC (rev 10935)
+++ trunk/Hibernate3/src/org/hibernate/dialect/Dialect.java 2006-12-06 13:04:31 UTC (rev 10936)
@@ -943,14 +943,30 @@
}
/**
- * Does the dialect require that temporary table DDL statements
- * occur in isolation from other statements?
- * todo : perhaps have this return java.lang.Boolean instead where null means to use the value returned by the driver.
- *
- * @return
+ * Does the dialect require that temporary table DDL statements occur in
+ * isolation from other statements? This would be the case if the creation
+ * would cause any current transaction to get committed implicitly.
+ * <p/>
+ * JDBC defines a standard way to query for this information via the
+ * {@link java.sql.DatabaseMetaData#dataDefinitionCausesTransactionCommit()}
+ * method. However, that does not distinguish between temporary table
+ * DDL and other forms of DDL; MySQL, for example, reports DDL causing a
+ * transaction commit via its driver, even though that is not the case for
+ * temporary table DDL.
+ * <p/>
+ * Possible return values and their meanings:<ul>
+ * <li>{@link Boolean#TRUE} - Unequivocally, perform the temporary table DDL
+ * in isolation.</li>
+ * <li>{@link Boolean#FALSE} - Unequivocally, do <b>not</b> perform the
+ * temporary table DDL in isolation.</li>
+ * <li><i>null</i> - defer to the JDBC driver response in regards to
+ * {@link java.sql.DatabaseMetaData#dataDefinitionCausesTransactionCommit()}</li>
+ * </ul>
+ *
+ * @return see the result matrix above.
*/
- public boolean performTemporaryTableDDLInIsolation() {
- return false;
+ public Boolean performTemporaryTableDDLInIsolation() {
+ return null;
}
/**
Modified: trunk/Hibernate3/src/org/hibernate/dialect/MySQLDialect.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/dialect/MySQLDialect.java 2006-12-05 22:43:52 UTC (rev 10935)
+++ trunk/Hibernate3/src/org/hibernate/dialect/MySQLDialect.java 2006-12-06 13:04:31 UTC (rev 10936)
@@ -324,4 +324,8 @@
public boolean supportsRowValueConstructorSyntax() {
return true;
}
+
+ public Boolean performTemporaryTableDDLInIsolation() {
+ return Boolean.FALSE;
+ }
}
\ No newline at end of file
Modified: trunk/Hibernate3/src/org/hibernate/hql/ast/exec/AbstractStatementExecutor.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/hql/ast/exec/AbstractStatementExecutor.java 2006-12-05 22:43:52 UTC (rev 10935)
+++ trunk/Hibernate3/src/org/hibernate/hql/ast/exec/AbstractStatementExecutor.java 2006-12-06 13:04:31 UTC (rev 10936)
@@ -130,7 +130,7 @@
}
}
};
- if ( getFactory().getSettings().isDataDefinitionImplicitCommit() || getFactory().getDialect().performTemporaryTableDDLInIsolation() ) {
+ if ( shouldIsolateTemporaryTableDDL() ) {
if ( getFactory().getSettings().isDataDefinitionInTransactionSupported() ) {
Isolater.doIsolatedWork( work, session );
}
@@ -168,7 +168,8 @@
}
}
};
- if ( getFactory().getSettings().isDataDefinitionImplicitCommit() || getFactory().getDialect().performTemporaryTableDDLInIsolation() ) {
+
+ if ( shouldIsolateTemporaryTableDDL() ) {
if ( getFactory().getSettings().isDataDefinitionInTransactionSupported() ) {
Isolater.doIsolatedWork( work, session );
}
@@ -213,4 +214,14 @@
( ( EventSource ) session ).getActionQueue().addAction( action );
}
}
+
+ protected boolean shouldIsolateTemporaryTableDDL() {
+ Boolean dialectVote = getFactory().getDialect().performTemporaryTableDDLInIsolation();
+ if ( dialectVote != null ) {
+ return dialectVote.booleanValue();
+ }
+ else {
+ return getFactory().getSettings().isDataDefinitionImplicitCommit();
+ }
+ }
}
Modified: trunk/Hibernate3/test/org/hibernate/test/TestCase.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/TestCase.java 2006-12-05 22:43:52 UTC (rev 10935)
+++ trunk/Hibernate3/test/org/hibernate/test/TestCase.java 2006-12-06 13:04:31 UTC (rev 10936)
@@ -624,6 +624,11 @@
return true;
}
+ protected boolean supportsSubqueryOnMutatingTable() {
+ // I only know of MySQL having this limitation...
+ return dialectIsNot( MySQLDialect.class );
+ }
+
private boolean dialectIs(Class dialectClass) {
return dialectClass.isInstance( getDialect() );
}
Modified: trunk/Hibernate3/test/org/hibernate/test/hql/BulkManipulationTest.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/hql/BulkManipulationTest.java 2006-12-05 22:43:52 UTC (rev 10935)
+++ trunk/Hibernate3/test/org/hibernate/test/hql/BulkManipulationTest.java 2006-12-06 13:04:31 UTC (rev 10936)
@@ -12,7 +12,6 @@
import org.hibernate.Transaction;
import org.hibernate.classic.Session;
import org.hibernate.dialect.MySQLDialect;
-import org.hibernate.engine.SessionFactoryImplementor;
import org.hibernate.hql.ast.HqlSqlWalker;
import org.hibernate.id.IdentifierGenerator;
import org.hibernate.persister.entity.EntityPersister;
@@ -520,15 +519,17 @@
count = s.createQuery( updateQryString ).executeUpdate();
assertEquals( 1, count );
// many-to-many test
- updateQryString = "update SimpleEntityWithAssociation e " +
- "set e.name = 'updated' " +
- "where exists (" +
- " select a.id " +
- " from e.manyToManyAssociatedEntities a " +
- " where a.name = 'many-to-many-association' " +
- ")";
- count = s.createQuery( updateQryString ).executeUpdate();
- assertEquals( 1, count );
+ if ( supportsSubqueryOnMutatingTable() ) {
+ updateQryString = "update SimpleEntityWithAssociation e " +
+ "set e.name = 'updated' " +
+ "where exists (" +
+ " select a.id " +
+ " from e.manyToManyAssociatedEntities a " +
+ " where a.name = 'many-to-many-association' " +
+ ")";
+ count = s.createQuery( updateQryString ).executeUpdate();
+ assertEquals( 1, count );
+ }
s.delete( entity.getManyToManyAssociatedEntities().iterator().next() );
s.delete( entity );
t.commit();
@@ -915,8 +916,10 @@
assertEquals( "incorrect delete count", 1, count );
// HHH-873...
- count = s.createQuery( "delete from User u where u not in (select u from User u)" ).executeUpdate();
- assertEquals( 0, count );
+ if ( supportsSubqueryOnMutatingTable() ) {
+ count = s.createQuery( "delete from User u where u not in (select u from User u)" ).executeUpdate();
+ assertEquals( 0, count );
+ }
count = s.createQuery( "delete Animal a" ).executeUpdate();
assertEquals( "Incorrect delete count", 4, count );
[View Less]
18 years, 3 months
Hibernate SVN: r10935 - branches/Branch_3_2/HibernateExt/ejb/src/java/org/hibernate/ejb/packaging
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2006-12-05 17:43:52 -0500 (Tue, 05 Dec 2006)
New Revision: 10935
Modified:
branches/Branch_3_2/HibernateExt/ejb/src/java/org/hibernate/ejb/packaging/PersistenceXmlLoader.java
Log:
EJB-256 avoid locking when tomcat and windows is used
Modified: branches/Branch_3_2/HibernateExt/ejb/src/java/org/hibernate/ejb/packaging/PersistenceXmlLoader.java
===================================================================
--- branches/Branch_3_2/HibernateExt/ejb/src/java/org/…
[View More]hibernate/ejb/packaging/PersistenceXmlLoader.java 2006-12-05 20:36:35 UTC (rev 10934)
+++ branches/Branch_3_2/HibernateExt/ejb/src/java/org/hibernate/ejb/packaging/PersistenceXmlLoader.java 2006-12-05 22:43:52 UTC (rev 10935)
@@ -3,6 +3,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
+import java.net.URLConnection;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@@ -40,7 +41,12 @@
}
private static Document loadURL(URL configURL, EntityResolver resolver) throws Exception {
- InputStream is = configURL != null ? configURL.openStream() : null;
+ InputStream is = null;
+ if (configURL != null) {
+ URLConnection conn = configURL.openConnection();
+ conn.setUseCaches( false ); //avoid JAR locking on Windows and Tomcat
+ is = conn.getInputStream();
+ }
if ( is == null ) {
throw new IOException( "Failed to obtain InputStream from url: " + configURL );
}
[View Less]
18 years, 3 months
Hibernate SVN: r10934 - branches/Branch_3_2/Hibernate3/src/org/hibernate/hql/ast/tree
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2006-12-05 15:36:35 -0500 (Tue, 05 Dec 2006)
New Revision: 10934
Modified:
branches/Branch_3_2/Hibernate3/src/org/hibernate/hql/ast/tree/DotNode.java
Log:
(follow-on) HHH-2257 : implicit joins and shallow queries
Modified: branches/Branch_3_2/Hibernate3/src/org/hibernate/hql/ast/tree/DotNode.java
===================================================================
--- branches/Branch_3_2/Hibernate3/src/org/hibernate/hql/ast/tree/DotNode.java 2006-12-…
[View More]05 20:36:11 UTC (rev 10933)
+++ branches/Branch_3_2/Hibernate3/src/org/hibernate/hql/ast/tree/DotNode.java 2006-12-05 20:36:35 UTC (rev 10934)
@@ -286,10 +286,11 @@
private void dereferenceEntity(EntityType entityType, boolean implicitJoin, String classAlias, boolean generateJoin, AST parent) throws SemanticException {
checkForCorrelatedSubquery( "dereferenceEntity" );
- // two general cases we check here:
+ // three general cases we check here:
// 1) is our parent a DotNode as well? If so, our property reference is
// being further de-referenced...
- // 2) we were asked to generate any needed joins (generateJoins==true) *OR*
+ // 2) is this a DML statement
+ // 3) we were asked to generate any needed joins (generateJoins==true) *OR*
// the current parser state indicates to use an INNER JOIN for implicit joins
//
// The "implicit join" portion of the second condition was done to account for
@@ -310,6 +311,9 @@
property = parentAsDotNode.propertyName;
joinIsNeeded = generateJoin && !isReferenceToPrimaryKey( parentAsDotNode.propertyName, entityType );
}
+ else if ( ! getWalker().isSelectStatement() ) {
+ joinIsNeeded = false;
+ }
else {
// otherwise we need to generate the join if we were asked to, or
// if the current implicit join type is INNER JOINs
[View Less]
18 years, 3 months
Hibernate SVN: r10933 - trunk/Hibernate3/src/org/hibernate/hql/ast/tree
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2006-12-05 15:36:11 -0500 (Tue, 05 Dec 2006)
New Revision: 10933
Modified:
trunk/Hibernate3/src/org/hibernate/hql/ast/tree/DotNode.java
Log:
(follow-on) HHH-2257 : implicit joins and shallow queries
Modified: trunk/Hibernate3/src/org/hibernate/hql/ast/tree/DotNode.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/hql/ast/tree/DotNode.java 2006-12-05 19:43:04 UTC (rev 10932)
+++ trunk/…
[View More]Hibernate3/src/org/hibernate/hql/ast/tree/DotNode.java 2006-12-05 20:36:11 UTC (rev 10933)
@@ -285,11 +285,11 @@
private void dereferenceEntity(EntityType entityType, boolean implicitJoin, String classAlias, boolean generateJoin, AST parent) throws SemanticException {
checkForCorrelatedSubquery( "dereferenceEntity" );
-
- // two general cases we check here:
+ // three general cases we check here:
// 1) is our parent a DotNode as well? If so, our property reference is
// being further de-referenced...
- // 2) we were asked to generate any needed joins (generateJoins==true) *OR*
+ // 2) is this a DML statement
+ // 3) we were asked to generate any needed joins (generateJoins==true) *OR*
// the current parser state indicates to use an INNER JOIN for implicit joins
//
// The "implicit join" portion of the second condition was done to account for
@@ -310,6 +310,9 @@
property = parentAsDotNode.propertyName;
joinIsNeeded = generateJoin && !isReferenceToPrimaryKey( parentAsDotNode.propertyName, entityType );
}
+ else if ( ! getWalker().isSelectStatement() ) {
+ joinIsNeeded = false;
+ }
else {
// otherwise we need to generate the join if we were asked to, or
// if the current implicit join type is INNER JOINs
[View Less]
18 years, 3 months
Hibernate SVN: r10932 - in trunk/Hibernate3: src/org/hibernate/hql/ast/tree test/org/hibernate/test/hql
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2006-12-05 14:43:04 -0500 (Tue, 05 Dec 2006)
New Revision: 10932
Added:
trunk/Hibernate3/test/org/hibernate/test/hql/ComponentContainer.hbm.xml
trunk/Hibernate3/test/org/hibernate/test/hql/ComponentContainer.java
Modified:
trunk/Hibernate3/src/org/hibernate/hql/ast/tree/DotNode.java
trunk/Hibernate3/test/org/hibernate/test/hql/HQLTest.java
trunk/Hibernate3/test/org/hibernate/test/hql/QueryTranslatorTestCase.java
Log:
HHH-2284 : HQL + sub-…
[View More]component references
Modified: trunk/Hibernate3/src/org/hibernate/hql/ast/tree/DotNode.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/hql/ast/tree/DotNode.java 2006-12-05 19:42:41 UTC (rev 10931)
+++ trunk/Hibernate3/src/org/hibernate/hql/ast/tree/DotNode.java 2006-12-05 19:43:04 UTC (rev 10932)
@@ -521,10 +521,9 @@
}
}
else {
- // Handle "select foo.component from Foo foo", or even "where foo.component = bar.component"
- AST lhs = getFirstChild();
- AST rhs = lhs.getNextSibling();
- propertyPath = rhs.getText();
+ if ( log.isDebugEnabled() ) {
+ log.debug( "terminal propertyPath = [" + propertyPath + "]" );
+ }
}
}
Added: trunk/Hibernate3/test/org/hibernate/test/hql/ComponentContainer.hbm.xml
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/hql/ComponentContainer.hbm.xml 2006-12-05 19:42:41 UTC (rev 10931)
+++ trunk/Hibernate3/test/org/hibernate/test/hql/ComponentContainer.hbm.xml 2006-12-05 19:43:04 UTC (rev 10932)
@@ -0,0 +1,21 @@
+<?xml version="1.0"?>
+<!DOCTYPE hibernate-mapping SYSTEM "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
+
+<hibernate-mapping package="org.hibernate.test.hql" default-access="field">
+
+ <class name="ComponentContainer" table="HQL_COMP_CONT">
+ <id name="id" type="long" column="ID">
+ <generator class="increment" />
+ </id>
+ <component name="address" class="ComponentContainer$Address">
+ <property name="street" type="string" column="STREET_ADDR" />
+ <property name="city" type="string" column="CITY_ADDR" />
+ <property name="state" type="string" column="STATE_ADDR" />
+ <component name="zip" class="ComponentContainer$Address$Zip">
+ <property name="code" type="int" column="ZIP_CODE_ADDR" />
+ <property name="plus4" type="int" column="ZIP_PLUS4_ADDR" />
+ </component>
+ </component>
+ </class>
+
+</hibernate-mapping>
Added: trunk/Hibernate3/test/org/hibernate/test/hql/ComponentContainer.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/hql/ComponentContainer.java 2006-12-05 19:42:41 UTC (rev 10931)
+++ trunk/Hibernate3/test/org/hibernate/test/hql/ComponentContainer.java 2006-12-05 19:43:04 UTC (rev 10932)
@@ -0,0 +1,107 @@
+package org.hibernate.test.hql;
+
+/**
+ * {@inheritDoc}
+ *
+ * @author Steve Ebersole
+ */
+public class ComponentContainer {
+
+ private Long id;
+ private ComponentContainer.Address address;
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public ComponentContainer.Address getAddress() {
+ return address;
+ }
+
+ public void setAddress(ComponentContainer.Address address) {
+ this.address = address;
+ }
+
+ public static class Address {
+ private String street;
+ private String city;
+ private String state;
+ private ComponentContainer.Address.Zip zip;
+
+ public Address() {
+ }
+
+ public Address(String street, String city, String state, ComponentContainer.Address.Zip zip) {
+ this.street = street;
+ this.city = city;
+ this.state = state;
+ this.zip = zip;
+ }
+
+ public String getStreet() {
+ return street;
+ }
+
+ public void setStreet(String street) {
+ this.street = street;
+ }
+
+ public String getCity() {
+ return city;
+ }
+
+ public void setCity(String city) {
+ this.city = city;
+ }
+
+ public String getState() {
+ return state;
+ }
+
+ public void setState(String state) {
+ this.state = state;
+ }
+
+ public ComponentContainer.Address.Zip getZip() {
+ return zip;
+ }
+
+ public void setZip(ComponentContainer.Address.Zip zip) {
+ this.zip = zip;
+ }
+
+ public static class Zip {
+ private int code;
+ private int plus4;
+
+ public Zip() {
+ }
+
+ public Zip(int code, int plus4) {
+ this.code = code;
+ this.plus4 = plus4;
+ }
+
+ public int getCode() {
+ return code;
+ }
+
+ public void setCode(int code) {
+ this.code = code;
+ }
+
+ public int getPlus4() {
+ return plus4;
+ }
+
+ public void setPlus4(int plus4) {
+ this.plus4 = plus4;
+ }
+ }
+ }
+
+}
Modified: trunk/Hibernate3/test/org/hibernate/test/hql/HQLTest.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/hql/HQLTest.java 2006-12-05 19:42:41 UTC (rev 10931)
+++ trunk/Hibernate3/test/org/hibernate/test/hql/HQLTest.java 2006-12-05 19:43:04 UTC (rev 10932)
@@ -52,6 +52,12 @@
//FAILING TESTS:
+ public void testSubComponentReferences() {
+ assertTranslation( "select c.address.zip.code from ComponentContainer c" );
+ assertTranslation( "select c.address.zip from ComponentContainer c" );
+ assertTranslation( "select c.address from ComponentContainer c" );
+ }
+
public void testManyToAnyReferences() {
assertTranslation( "from PropertySet p where p.someSpecificProperty.id is not null" );
assertTranslation( "from PropertySet p join p.generalProperties gp where gp.id is not null" );
Modified: trunk/Hibernate3/test/org/hibernate/test/hql/QueryTranslatorTestCase.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/hql/QueryTranslatorTestCase.java 2006-12-05 19:42:41 UTC (rev 10931)
+++ trunk/Hibernate3/test/org/hibernate/test/hql/QueryTranslatorTestCase.java 2006-12-05 19:43:04 UTC (rev 10932)
@@ -500,6 +500,7 @@
"hql/EntityWithCrazyCompositeKey.hbm.xml",
"hql/CrazyIdFieldNames.hbm.xml",
"hql/SimpleEntityWithAssociation.hbm.xml",
+ "hql/ComponentContainer.hbm.xml",
"batchfetch/ProductLine.hbm.xml",
"cid/Customer.hbm.xml",
"cid/Order.hbm.xml",
[View Less]
18 years, 3 months
Hibernate SVN: r10931 - in branches/Branch_3_2/Hibernate3: src/org/hibernate/hql/ast/tree test/org/hibernate/test/hql
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2006-12-05 14:42:41 -0500 (Tue, 05 Dec 2006)
New Revision: 10931
Added:
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/hql/ComponentContainer.hbm.xml
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/hql/ComponentContainer.java
Modified:
branches/Branch_3_2/Hibernate3/src/org/hibernate/hql/ast/tree/DotNode.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/hql/HQLTest.java
branches/Branch_3_2/Hibernate3/test/org/…
[View More]hibernate/test/hql/QueryTranslatorTestCase.java
Log:
HHH-2284 : HQL + sub-component references
Modified: branches/Branch_3_2/Hibernate3/src/org/hibernate/hql/ast/tree/DotNode.java
===================================================================
--- branches/Branch_3_2/Hibernate3/src/org/hibernate/hql/ast/tree/DotNode.java 2006-12-05 19:05:47 UTC (rev 10930)
+++ branches/Branch_3_2/Hibernate3/src/org/hibernate/hql/ast/tree/DotNode.java 2006-12-05 19:42:41 UTC (rev 10931)
@@ -5,7 +5,6 @@
import org.hibernate.engine.JoinSequence;
import org.hibernate.hql.CollectionProperties;
import org.hibernate.hql.antlr.SqlTokenTypes;
-import org.hibernate.hql.antlr.HqlSqlTokenTypes;
import org.hibernate.hql.ast.util.ASTPrinter;
import org.hibernate.hql.ast.util.ASTUtil;
import org.hibernate.hql.ast.util.ColumnHelper;
@@ -522,10 +521,9 @@
}
}
else {
- // Handle "select foo.component from Foo foo", or even "where foo.component = bar.component"
- AST lhs = getFirstChild();
- AST rhs = lhs.getNextSibling();
- propertyPath = rhs.getText();
+ if ( log.isDebugEnabled() ) {
+ log.debug( "terminal propertyPath = [" + propertyPath + "]" );
+ }
}
}
Added: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/hql/ComponentContainer.hbm.xml
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/hql/ComponentContainer.hbm.xml 2006-12-05 19:05:47 UTC (rev 10930)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/hql/ComponentContainer.hbm.xml 2006-12-05 19:42:41 UTC (rev 10931)
@@ -0,0 +1,21 @@
+<?xml version="1.0"?>
+<!DOCTYPE hibernate-mapping SYSTEM "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
+
+<hibernate-mapping package="org.hibernate.test.hql" default-access="field">
+
+ <class name="ComponentContainer" table="HQL_COMP_CONT">
+ <id name="id" type="long" column="ID">
+ <generator class="increment" />
+ </id>
+ <component name="address" class="ComponentContainer$Address">
+ <property name="street" type="string" column="STREET_ADDR" />
+ <property name="city" type="string" column="CITY_ADDR" />
+ <property name="state" type="string" column="STATE_ADDR" />
+ <component name="zip" class="ComponentContainer$Address$Zip">
+ <property name="code" type="int" column="ZIP_CODE_ADDR" />
+ <property name="plus4" type="int" column="ZIP_PLUS4_ADDR" />
+ </component>
+ </component>
+ </class>
+
+</hibernate-mapping>
Added: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/hql/ComponentContainer.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/hql/ComponentContainer.java 2006-12-05 19:05:47 UTC (rev 10930)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/hql/ComponentContainer.java 2006-12-05 19:42:41 UTC (rev 10931)
@@ -0,0 +1,107 @@
+package org.hibernate.test.hql;
+
+/**
+ * {@inheritDoc}
+ *
+ * @author Steve Ebersole
+ */
+public class ComponentContainer {
+
+ private Long id;
+ private ComponentContainer.Address address;
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public ComponentContainer.Address getAddress() {
+ return address;
+ }
+
+ public void setAddress(ComponentContainer.Address address) {
+ this.address = address;
+ }
+
+ public static class Address {
+ private String street;
+ private String city;
+ private String state;
+ private ComponentContainer.Address.Zip zip;
+
+ public Address() {
+ }
+
+ public Address(String street, String city, String state, ComponentContainer.Address.Zip zip) {
+ this.street = street;
+ this.city = city;
+ this.state = state;
+ this.zip = zip;
+ }
+
+ public String getStreet() {
+ return street;
+ }
+
+ public void setStreet(String street) {
+ this.street = street;
+ }
+
+ public String getCity() {
+ return city;
+ }
+
+ public void setCity(String city) {
+ this.city = city;
+ }
+
+ public String getState() {
+ return state;
+ }
+
+ public void setState(String state) {
+ this.state = state;
+ }
+
+ public ComponentContainer.Address.Zip getZip() {
+ return zip;
+ }
+
+ public void setZip(ComponentContainer.Address.Zip zip) {
+ this.zip = zip;
+ }
+
+ public static class Zip {
+ private int code;
+ private int plus4;
+
+ public Zip() {
+ }
+
+ public Zip(int code, int plus4) {
+ this.code = code;
+ this.plus4 = plus4;
+ }
+
+ public int getCode() {
+ return code;
+ }
+
+ public void setCode(int code) {
+ this.code = code;
+ }
+
+ public int getPlus4() {
+ return plus4;
+ }
+
+ public void setPlus4(int plus4) {
+ this.plus4 = plus4;
+ }
+ }
+ }
+
+}
Modified: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/hql/HQLTest.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/hql/HQLTest.java 2006-12-05 19:05:47 UTC (rev 10930)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/hql/HQLTest.java 2006-12-05 19:42:41 UTC (rev 10931)
@@ -52,6 +52,12 @@
//FAILING TESTS:
+ public void testSubComponentReferences() {
+ assertTranslation( "select c.address.zip.code from ComponentContainer c" );
+ assertTranslation( "select c.address.zip from ComponentContainer c" );
+ assertTranslation( "select c.address from ComponentContainer c" );
+ }
+
public void testManyToAnyReferences() {
assertTranslation( "from PropertySet p where p.someSpecificProperty.id is not null" );
assertTranslation( "from PropertySet p join p.generalProperties gp where gp.id is not null" );
Modified: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/hql/QueryTranslatorTestCase.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/hql/QueryTranslatorTestCase.java 2006-12-05 19:05:47 UTC (rev 10930)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/hql/QueryTranslatorTestCase.java 2006-12-05 19:42:41 UTC (rev 10931)
@@ -500,6 +500,7 @@
"hql/EntityWithCrazyCompositeKey.hbm.xml",
"hql/CrazyIdFieldNames.hbm.xml",
"hql/SimpleEntityWithAssociation.hbm.xml",
+ "hql/ComponentContainer.hbm.xml",
"batchfetch/ProductLine.hbm.xml",
"cid/Customer.hbm.xml",
"cid/Order.hbm.xml",
[View Less]
18 years, 3 months
Hibernate SVN: r10930 - in trunk/Hibernate3: src/org/hibernate/hql/ast/tree test/org/hibernate/test/hql
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2006-12-05 14:05:47 -0500 (Tue, 05 Dec 2006)
New Revision: 10930
Modified:
trunk/Hibernate3/src/org/hibernate/hql/ast/tree/DotNode.java
trunk/Hibernate3/test/org/hibernate/test/hql/ASTParserLoadingTest.java
trunk/Hibernate3/test/org/hibernate/test/hql/QueryTranslatorTestCase.java
Log:
HHH-2257 : implicit joins and shallow queries
Modified: trunk/Hibernate3/src/org/hibernate/hql/ast/tree/DotNode.java
=============================================…
[View More]======================
--- trunk/Hibernate3/src/org/hibernate/hql/ast/tree/DotNode.java 2006-12-05 19:04:53 UTC (rev 10929)
+++ trunk/Hibernate3/src/org/hibernate/hql/ast/tree/DotNode.java 2006-12-05 19:05:47 UTC (rev 10930)
@@ -286,26 +286,34 @@
private void dereferenceEntity(EntityType entityType, boolean implicitJoin, String classAlias, boolean generateJoin, AST parent) throws SemanticException {
checkForCorrelatedSubquery( "dereferenceEntity" );
- // Only join to the entity table if:
- // 1) we were instructed to generate any needed joins (generateJoins==true)
- // AND
- // 2) EITHER:
- // A) our parent represents a further dereference of this entity to anything
- // other than the entity's id property
- // OR
- // B) this node is in any clause, other than the select clause (unless that
- // select clause is part of a scalar query :/ )
+ // two general cases we check here:
+ // 1) is our parent a DotNode as well? If so, our property reference is
+ // being further de-referenced...
+ // 2) we were asked to generate any needed joins (generateJoins==true) *OR*
+ // the current parser state indicates to use an INNER JOIN for implicit joins
+ //
+ // The "implicit join" portion of the second condition was done to account for
+ // situations like HHH-2257 to make sure that iterate() and list() return
+ // consistent results. Previously the join would be skipped on "shallow queries"
+ // (aka, iterate()) for performance reasons, but that can lead to incorrect
+ // results since INNER JOINs do place extra restrications on the returned
+ // results.
DotNode parentAsDotNode = null;
String property = propertyName;
final boolean joinIsNeeded;
if ( isDotNode( parent ) ) {
+ // our parent is another dot node, meaning we are being further dereferenced.
+ // thus we need to generate a join unless the parent refers to the associated
+ // entity's PK (because 'our' table would know the FK).
parentAsDotNode = ( DotNode ) parent;
property = parentAsDotNode.propertyName;
joinIsNeeded = generateJoin && !isReferenceToPrimaryKey( parentAsDotNode.propertyName, entityType );
}
else {
- joinIsNeeded = generateJoin && ( !getWalker().isInSelect() || !getWalker().isShallowQuery() );
+ // otherwise we need to generate the join if we were asked to, or
+ // if the current implicit join type is INNER JOINs
+ joinIsNeeded = generateJoin || getWalker().getImpliedJoinType() == JoinFragment.INNER_JOIN;
}
if ( joinIsNeeded ) {
Modified: trunk/Hibernate3/test/org/hibernate/test/hql/ASTParserLoadingTest.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/hql/ASTParserLoadingTest.java 2006-12-05 19:04:53 UTC (rev 10929)
+++ trunk/Hibernate3/test/org/hibernate/test/hql/ASTParserLoadingTest.java 2006-12-05 19:05:47 UTC (rev 10930)
@@ -76,6 +76,7 @@
return new String[] {
"hql/Animal.hbm.xml",
"hql/FooBarCopy.hbm.xml",
+ "hql/SimpleEntityWithAssociation.hbm.xml",
"batchfetch/ProductLine.hbm.xml",
"cid/Customer.hbm.xml",
"cid/Order.hbm.xml",
@@ -93,6 +94,94 @@
cfg.setProperty( Environment.GENERATE_STATISTICS, "true" );
}
+ public void testImplicitJoinsInDifferentClauses() {
+ // HHH-2257 :
+ // both the classic and ast translators output the same syntactically valid sql
+ // for all of these cases; the issue is that shallow (iterate) and
+ // non-shallow (list/scroll) queries return different results because the
+ // shallow skips the inner join which "weeds out" results from the non-shallow queries.
+ // The results were initially different depending upon the clause(s) in which the
+ // implicit join occurred
+ Session s = openSession();
+ s.beginTransaction();
+ SimpleEntityWithAssociation owner = new SimpleEntityWithAssociation( "owner" );
+ SimpleAssociatedEntity e1 = new SimpleAssociatedEntity( "thing one", owner );
+ SimpleAssociatedEntity e2 = new SimpleAssociatedEntity( "thing two" );
+ s.save( e1 );
+ s.save( e2 );
+ s.save( owner );
+ s.getTransaction().commit();
+ s.close();
+
+ checkCounts( "select e.owner from SimpleAssociatedEntity e", 1, "implicit-join in select clause" );
+ checkCounts( "select e.id, e.owner from SimpleAssociatedEntity e", 1, "implicit-join in select clause" );
+ checkCounts( "from SimpleAssociatedEntity e order by e.owner", 1, "implicit-join in order-by clause" );
+ checkCounts( "select e.owner.id, count(*) from SimpleAssociatedEntity e group by e.owner", 1, "implicit-join in select and group-by clauses" );
+
+ s = openSession();
+ s.beginTransaction();
+ s.delete( e1 );
+ s.delete( e2 );
+ s.delete( owner );
+ s.getTransaction().commit();
+ s.close();
+ }
+
+ private void checkCounts(String hql, int expected, String testCondition) {
+ Session s = openSession();
+ s.beginTransaction();
+ int count = determineCount( s.createQuery( hql ).list().iterator() );
+ assertEquals( "list() [" + testCondition + "]", expected, count );
+ count = determineCount( s.createQuery( hql ).iterate() );
+ assertEquals( "iterate() [" + testCondition + "]", expected, count );
+ s.getTransaction().commit();
+ s.close();
+ }
+
+ public void testImplicitSelectEntityAssociationInShallowQuery() {
+ // HHH-2257 :
+ // both the classic and ast translators output the same syntactically valid sql.
+ // the issue is that shallow and non-shallow queries return different
+ // results because the shallow skips the inner join which "weeds out" results
+ // from the non-shallow queries...
+ Session s = openSession();
+ s.beginTransaction();
+ SimpleEntityWithAssociation owner = new SimpleEntityWithAssociation( "owner" );
+ SimpleAssociatedEntity e1 = new SimpleAssociatedEntity( "thing one", owner );
+ SimpleAssociatedEntity e2 = new SimpleAssociatedEntity( "thing two" );
+ s.save( e1 );
+ s.save( e2 );
+ s.save( owner );
+ s.getTransaction().commit();
+ s.close();
+
+ s = openSession();
+ s.beginTransaction();
+ int count = determineCount( s.createQuery( "select e.id, e.owner from SimpleAssociatedEntity e" ).list().iterator() );
+ assertEquals( 1, count ); // thing two would be removed from the result due to the inner join
+ count = determineCount( s.createQuery( "select e.id, e.owner from SimpleAssociatedEntity e" ).iterate() );
+ assertEquals( 1, count );
+ s.getTransaction().commit();
+ s.close();
+
+ s = openSession();
+ s.beginTransaction();
+ s.delete( e1 );
+ s.delete( e2 );
+ s.delete( owner );
+ s.getTransaction().commit();
+ s.close();
+ }
+
+ private int determineCount(Iterator iterator) {
+ int count = 0;
+ while( iterator.hasNext() ) {
+ count++;
+ iterator.next();
+ }
+ return count;
+ }
+
public void testNestedComponentIsNull() {
// (1) From MapTest originally...
// (2) Was then moved into HQLTest...
Modified: trunk/Hibernate3/test/org/hibernate/test/hql/QueryTranslatorTestCase.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/hql/QueryTranslatorTestCase.java 2006-12-05 19:04:53 UTC (rev 10929)
+++ trunk/Hibernate3/test/org/hibernate/test/hql/QueryTranslatorTestCase.java 2006-12-05 19:05:47 UTC (rev 10930)
@@ -498,6 +498,8 @@
return new String[] {
"hql/Animal.hbm.xml",
"hql/EntityWithCrazyCompositeKey.hbm.xml",
+ "hql/CrazyIdFieldNames.hbm.xml",
+ "hql/SimpleEntityWithAssociation.hbm.xml",
"batchfetch/ProductLine.hbm.xml",
"cid/Customer.hbm.xml",
"cid/Order.hbm.xml",
@@ -528,7 +530,6 @@
"legacy/UpDown.hbm.xml",
"compositeelement/Parent.hbm.xml",
"onetoone/joined/Person.hbm.xml",
- "hql/CrazyIdFieldNames.hbm.xml",
"any/Properties.hbm.xml"
};
}
[View Less]
18 years, 3 months