Hibernate SVN: r18483 - in core/trunk/entitymanager/src: test/java/org/hibernate/ejb/criteria/basic and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2010-01-09 12:04:55 -0500 (Sat, 09 Jan 2010)
New Revision: 18483
Added:
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/criteria/basic/PredicateTest.java
Modified:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/CompoundPredicate.java
Log:
HHH-4772 - Empty conjunction/disjunction in criteria does not follow spec rules
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/CompoundPredicate.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/CompoundPredicate.java 2010-01-09 16:44:59 UTC (rev 18482)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/CompoundPredicate.java 2010-01-09 17:04:55 UTC (rev 18483)
@@ -115,6 +115,11 @@
}
public String render(CriteriaQueryCompiler.RenderingContext renderingContext) {
+ if ( getExpressions().size() == 0 ) {
+ return getOperator() == Predicate.BooleanOperator.AND
+ ? "true"
+ : "false";
+ }
if ( getExpressions().size() == 1 ) {
return ( (Renderable) getExpressions().get(0) ).render( renderingContext );
}
Added: core/trunk/entitymanager/src/test/java/org/hibernate/ejb/criteria/basic/PredicateTest.java
===================================================================
--- core/trunk/entitymanager/src/test/java/org/hibernate/ejb/criteria/basic/PredicateTest.java (rev 0)
+++ core/trunk/entitymanager/src/test/java/org/hibernate/ejb/criteria/basic/PredicateTest.java 2010-01-09 17:04:55 UTC (rev 18483)
@@ -0,0 +1,67 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.ejb.criteria.basic;
+
+import javax.persistence.EntityManager;
+import javax.persistence.criteria.CriteriaBuilder;
+import javax.persistence.criteria.CriteriaQuery;
+import javax.persistence.criteria.Root;
+
+import org.hibernate.ejb.metamodel.AbstractMetamodelSpecificTest;
+import org.hibernate.ejb.metamodel.Order;
+
+/**
+ * Test the various predicates.
+ *
+ * @author Steve Ebersole
+ */
+public class PredicateTest extends AbstractMetamodelSpecificTest {
+ public void testEmptyConjunction() {
+ // yes this is a retarded case, but explicitly allowed in the JPA spec
+ CriteriaBuilder builder = factory.getCriteriaBuilder();
+ EntityManager em = getOrCreateEntityManager();
+ em.getTransaction().begin();
+ CriteriaQuery<Order> orderCriteria = builder.createQuery(Order.class);
+ Root<Order> orderRoot = orderCriteria.from(Order.class);
+ orderCriteria.select(orderRoot);
+ orderCriteria.where( builder.isTrue( builder.conjunction() ) );
+ em.createQuery( orderCriteria ).getResultList();
+ em.getTransaction().commit();
+ em.close();
+ }
+
+ public void testEmptyDisjunction() {
+ // yes this is a retarded case, but explicitly allowed in the JPA spec
+ CriteriaBuilder builder = factory.getCriteriaBuilder();
+ EntityManager em = getOrCreateEntityManager();
+ em.getTransaction().begin();
+ CriteriaQuery<Order> orderCriteria = builder.createQuery(Order.class);
+ Root<Order> orderRoot = orderCriteria.from(Order.class);
+ orderCriteria.select(orderRoot);
+ orderCriteria.where( builder.isFalse( builder.disjunction() ) );
+ em.createQuery( orderCriteria ).getResultList();
+ em.getTransaction().commit();
+ em.close();
+ }
+}
15 years
Hibernate SVN: r18482 - in core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria: expression and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2010-01-09 11:44:59 -0500 (Sat, 09 Jan 2010)
New Revision: 18482
Modified:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/ValueHandlerFactory.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/LiteralExpression.java
Log:
HHH-4774 - Do not handle literals using parameters in JPA criteria select
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/ValueHandlerFactory.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/ValueHandlerFactory.java 2010-01-09 16:24:44 UTC (rev 18481)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/ValueHandlerFactory.java 2010-01-09 16:44:59 UTC (rev 18482)
@@ -54,6 +54,18 @@
}
}
+ public static boolean isCharacter(Class type) {
+ return String.class.isAssignableFrom( type )
+ || Character.class.isAssignableFrom( type )
+ || Character.TYPE.equals( type );
+ }
+
+ public static boolean isCharacter(Object value) {
+ return String.class.isInstance( value )
+ || Character.class.isInstance( value )
+ || Character.TYPE.isInstance( value );
+ }
+
public static boolean isNumeric(Class type) {
return Number.class.isAssignableFrom( type )
|| Byte.TYPE.equals( type )
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/LiteralExpression.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/LiteralExpression.java 2010-01-09 16:24:44 UTC (rev 18481)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/LiteralExpression.java 2010-01-09 16:44:59 UTC (rev 18482)
@@ -88,8 +88,17 @@
return ':' + parameterName;
}
+ @SuppressWarnings({ "unchecked" })
public String renderProjection(CriteriaQueryCompiler.RenderingContext renderingContext) {
- return render( renderingContext );
+ // some drivers/servers do not like parameters in the select clause
+ final ValueHandlerFactory.ValueHandler handler =
+ ValueHandlerFactory.determineAppropriateHandler( literal.getClass() );
+ if ( ! ValueHandlerFactory.isCharacter( literal ) ) {
+ return '\'' + handler.render( literal ) + '\'';
+ }
+ else {
+ return handler.render( literal );
+ }
}
@Override
15 years
Hibernate SVN: r18481 - in core/trunk/entitymanager/src: main/java/org/hibernate/ejb/criteria/path and 1 other directories.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2010-01-09 11:24:44 -0500 (Sat, 09 Jan 2010)
New Revision: 18481
Added:
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/criteria/subquery/CorrelatedSubqueryTest.java
Modified:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/CriteriaSubqueryImpl.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/FromImplementor.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/QueryStructure.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/path/AbstractFromImpl.java
Log:
HHH-4768 - Bug in how Criteria Subquery correlations are handled
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/CriteriaSubqueryImpl.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/CriteriaSubqueryImpl.java 2010-01-09 15:49:30 UTC (rev 18480)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/CriteriaSubqueryImpl.java 2010-01-09 16:24:44 UTC (rev 18481)
@@ -26,11 +26,9 @@
import java.io.Serializable;
import java.util.List;
import java.util.Set;
-import java.util.HashSet;
import javax.persistence.criteria.AbstractQuery;
import javax.persistence.criteria.CollectionJoin;
import javax.persistence.criteria.Expression;
-import javax.persistence.criteria.Fetch;
import javax.persistence.criteria.Join;
import javax.persistence.criteria.ListJoin;
import javax.persistence.criteria.MapJoin;
@@ -53,18 +51,6 @@
private final AbstractQuery<?> parent;
private final QueryStructure<T> queryStructure;
- private Set<Join<?, ?>> correlatedJoins = new HashSet<Join<?,?>>();
-
- private final FromImplementor.JoinScope joinScope = new FromImplementor.JoinScope() {
- public void addJoin(Join join) {
- correlatedJoins.add( join );
- }
-
- public void addFetch(Fetch fetch) {
- throw new UnsupportedOperationException( "Cannot define fetch from a subquery correlation" );
- }
- };
-
public CriteriaSubqueryImpl(
CriteriaBuilderImpl criteriaBuilder,
Class<T> javaType,
@@ -75,15 +61,6 @@
}
/**
- * Get the scope used to scope joins to this subquery.
- *
- * @return The subquery's join scope.
- */
- public FromImplementor.JoinScope getJoinScope() {
- return joinScope;
- }
-
- /**
* {@inheritDoc}
*/
public AbstractQuery<?> getParent() {
@@ -235,49 +212,61 @@
* {@inheritDoc}
*/
public Set<Join<?, ?>> getCorrelatedJoins() {
- return correlatedJoins;
+ return queryStructure.collectCorrelatedJoins();
}
/**
* {@inheritDoc}
*/
public <Y> Root<Y> correlate(Root<Y> source) {
- return ( ( RootImpl<Y> ) source ).correlateTo( this );
+ final RootImpl<Y> correlation = ( ( RootImpl<Y> ) source ).correlateTo( this );
+ queryStructure.addCorrelationRoot( correlation );
+ return correlation;
}
/**
* {@inheritDoc}
*/
public <X, Y> Join<X, Y> correlate(Join<X, Y> source) {
- return ( (JoinImplementor<X,Y>) source ).correlateTo( this );
+ final JoinImplementor<X,Y> correlation = ( (JoinImplementor<X,Y>) source ).correlateTo( this );
+ queryStructure.addCorrelationRoot( correlation );
+ return correlation;
}
/**
* {@inheritDoc}
*/
public <X, Y> CollectionJoin<X, Y> correlate(CollectionJoin<X, Y> source) {
- return ( (CollectionJoinImplementor<X,Y>) source ).correlateTo( this );
+ final CollectionJoinImplementor<X,Y> correlation = ( (CollectionJoinImplementor<X,Y>) source ).correlateTo( this );
+ queryStructure.addCorrelationRoot( correlation );
+ return correlation;
}
/**
* {@inheritDoc}
*/
public <X, Y> SetJoin<X, Y> correlate(SetJoin<X, Y> source) {
- return ( (SetJoinImplementor<X,Y>) source ).correlateTo( this );
+ final SetJoinImplementor<X,Y> correlation = ( (SetJoinImplementor<X,Y>) source ).correlateTo( this );
+ queryStructure.addCorrelationRoot( correlation );
+ return correlation;
}
/**
* {@inheritDoc}
*/
public <X, Y> ListJoin<X, Y> correlate(ListJoin<X, Y> source) {
- return ( (ListJoinImplementor<X,Y>) source ).correlateTo( this );
+ final ListJoinImplementor<X,Y> correlation = ( (ListJoinImplementor<X,Y>) source ).correlateTo( this );
+ queryStructure.addCorrelationRoot( correlation );
+ return correlation;
}
/**
* {@inheritDoc}
*/
public <X, K, V> MapJoin<X, K, V> correlate(MapJoin<X, K, V> source) {
- return ( (MapJoinImplementor<X, K, V>) source ).correlateTo( this );
+ final MapJoinImplementor<X, K, V> correlation = ( (MapJoinImplementor<X, K, V>) source ).correlateTo( this );
+ queryStructure.addCorrelationRoot( correlation );
+ return correlation;
}
/**
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/FromImplementor.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/FromImplementor.java 2010-01-09 15:49:30 UTC (rev 18480)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/FromImplementor.java 2010-01-09 16:24:44 UTC (rev 18481)
@@ -37,14 +37,8 @@
public void prepareAlias(CriteriaQueryCompiler.RenderingContext renderingContext);
public String renderTableExpression(CriteriaQueryCompiler.RenderingContext renderingContext);
- /**
- * Helper contract used to define who/what keeps track of joins and fetches made from this <tt>FROM</tt>.
- */
- public static interface JoinScope<X> extends Serializable {
- public void addJoin(Join<X, ?> join);
- public void addFetch(Fetch<X,?> fetch);
- }
public FromImplementor<Z,X> correlateTo(CriteriaSubqueryImpl subquery);
- public void prepareCorrelationDelegate(JoinScope<X> joinScope, FromImplementor<Z,X> parent);
+ public void prepareCorrelationDelegate(FromImplementor<Z,X> parent);
+ public FromImplementor<Z, X> getCorrelationParent();
}
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/QueryStructure.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/QueryStructure.java 2010-01-09 15:49:30 UTC (rev 18480)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/QueryStructure.java 2010-01-09 16:24:44 UTC (rev 18481)
@@ -60,15 +60,18 @@
public class QueryStructure<T> implements Serializable {
private final AbstractQuery<T> owner;
private final CriteriaBuilderImpl criteriaBuilder;
+ private final boolean isSubQuery;
public QueryStructure(AbstractQuery<T> owner, CriteriaBuilderImpl criteriaBuilder) {
this.owner = owner;
this.criteriaBuilder = criteriaBuilder;
+ this.isSubQuery = Subquery.class.isInstance( owner );
}
private boolean distinct;
private Selection<? extends T> selection;
private Set<Root<?>> roots = new HashSet<Root<?>>();
+ private Set<FromImplementor> correlationRoots;
private Predicate restriction;
private List<Expression<?>> groupings = Collections.emptyList();
private Predicate having;
@@ -148,6 +151,36 @@
}
+ // CORRELATION ROOTS ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+ public void addCorrelationRoot(FromImplementor fromImplementor) {
+ if ( !isSubQuery ) {
+ throw new IllegalStateException( "Query is not identified as sub-query" );
+ }
+ if ( correlationRoots == null ) {
+ correlationRoots = new HashSet<FromImplementor>();
+ }
+ correlationRoots.add( fromImplementor );
+ }
+
+ public Set<Join<?, ?>> collectCorrelatedJoins() {
+ if ( !isSubQuery ) {
+ throw new IllegalStateException( "Query is not identified as sub-query" );
+ }
+ final Set<Join<?, ?>> correlatedJoins;
+ if ( correlationRoots != null ) {
+ correlatedJoins = new HashSet<Join<?,?>>();
+ for ( FromImplementor<?,?> correlationRoot : correlationRoots ) {
+ correlatedJoins.addAll( correlationRoot.getJoins() );
+ }
+ }
+ else {
+ correlatedJoins = Collections.emptySet();
+ }
+ return correlatedJoins;
+ }
+
+
// RESTRICTIONS ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
public Predicate getRestriction() {
@@ -213,28 +246,14 @@
jpaqlQuery.append( "distinct " );
}
if ( getSelection() == null ) {
- // we should have only a single root (query validation should have checked this...)
- final Root root = getRoots().iterator().next();
- jpaqlQuery.append( ( (Renderable) root ).renderProjection( renderingContext) );
+ jpaqlQuery.append( locateImplicitSelection().renderProjection( renderingContext ) );
}
else {
jpaqlQuery.append( ( (Renderable) getSelection() ).renderProjection( renderingContext ) );
}
- jpaqlQuery.append( " from " );
- String sep = "";
- for ( Root root : getRoots() ) {
- ( (FromImplementor) root ).prepareAlias( renderingContext );
- jpaqlQuery.append( sep );
- jpaqlQuery.append( ( (FromImplementor) root ).renderTableExpression( renderingContext ) );
- sep = ", ";
- }
+ renderFromClause( jpaqlQuery, renderingContext );
- for ( Root root : getRoots() ) {
- renderJoins( jpaqlQuery, renderingContext, root.getJoins() );
- renderFetches( jpaqlQuery, renderingContext, root.getFetches() );
- }
-
if ( getRestriction() != null) {
jpaqlQuery.append( " where " )
.append( ( (Renderable) getRestriction() ).render( renderingContext ) );
@@ -242,7 +261,7 @@
if ( ! getGroupings().isEmpty() ) {
jpaqlQuery.append( " group by " );
- sep = "";
+ String sep = "";
for ( Expression grouping : getGroupings() ) {
jpaqlQuery.append( sep )
.append( ( (Renderable) grouping ).render( renderingContext ) );
@@ -256,7 +275,71 @@
}
}
+ private FromImplementor locateImplicitSelection() {
+ FromImplementor implicitSelection = null;
+
+ if ( ! isSubQuery ) {
+ // we should have only a single root (query validation should have checked this...)
+ implicitSelection = (FromImplementor) getRoots().iterator().next();
+ }
+ else {
+ // we should only have a single "root" which can act as the implicit selection
+ final Set<Join<?, ?>> correlatedJoins = collectCorrelatedJoins();
+ if ( correlatedJoins != null ) {
+ if ( correlatedJoins.size() == 1 ) {
+ implicitSelection = (FromImplementor) correlatedJoins.iterator().next();
+ }
+ }
+ }
+
+ if ( implicitSelection == null ) {
+ throw new IllegalStateException( "No explicit selection and an implicit one cold not be determined" );
+ }
+
+ return implicitSelection;
+ }
+
@SuppressWarnings({ "unchecked" })
+ private void renderFromClause(StringBuilder jpaqlQuery, CriteriaQueryCompiler.RenderingContext renderingContext) {
+ jpaqlQuery.append( " from " );
+ String sep = "";
+ for ( Root root : getRoots() ) {
+ ( (FromImplementor) root ).prepareAlias( renderingContext );
+ jpaqlQuery.append( sep );
+ jpaqlQuery.append( ( (FromImplementor) root ).renderTableExpression( renderingContext ) );
+ sep = ", ";
+ }
+
+ for ( Root root : getRoots() ) {
+ renderJoins( jpaqlQuery, renderingContext, root.getJoins() );
+ renderFetches( jpaqlQuery, renderingContext, root.getFetches() );
+ }
+
+ if ( isSubQuery ) {
+ if ( correlationRoots != null ) {
+ for ( FromImplementor<?,?> correlationRoot : correlationRoots ) {
+ final FromImplementor correlationParent = correlationRoot.getCorrelationParent();
+ correlationParent.prepareAlias( renderingContext );
+ final String correlationRootAlias = correlationParent.getAlias();
+ for ( Join<?,?> correlationJoin : correlationRoot.getJoins() ) {
+ final JoinImplementor correlationJoinImpl = (JoinImplementor) correlationJoin;
+ // IMPL NOTE: reuse the sep from above!
+ jpaqlQuery.append( sep );
+ correlationJoinImpl.prepareAlias( renderingContext );
+ jpaqlQuery.append( correlationRootAlias )
+ .append( '.' )
+ .append( correlationJoinImpl.getAttribute().getName() )
+ .append( " as " )
+ .append( correlationJoinImpl.getAlias() );
+ sep = ", ";
+ renderJoins( jpaqlQuery, renderingContext, correlationJoinImpl.getJoins() );
+ }
+ }
+ }
+ }
+ }
+
+ @SuppressWarnings({ "unchecked" })
private void renderJoins(
StringBuilder jpaqlQuery,
CriteriaQueryCompiler.RenderingContext renderingContext,
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/path/AbstractFromImpl.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/path/AbstractFromImpl.java 2010-01-09 15:49:30 UTC (rev 18480)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/path/AbstractFromImpl.java 2010-01-09 16:24:44 UTC (rev 18481)
@@ -102,10 +102,21 @@
*/
public void prepareAlias(CriteriaQueryCompiler.RenderingContext renderingContext) {
if ( getAlias() == null ) {
- setAlias( renderingContext.generateAlias() );
+ if ( isCorrelated() ) {
+ setAlias( getCorrelationParent().getAlias() );
+ }
+ else {
+ setAlias( renderingContext.generateAlias() );
+ }
}
}
+ @Override
+ public String renderProjection(CriteriaQueryCompiler.RenderingContext renderingContext) {
+ prepareAlias( renderingContext );
+ return getAlias();
+ }
+
/**
* {@inheritDoc}
*/
@@ -137,8 +148,24 @@
// CORRELATION ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- private From<Z,X> correlationParent;
- private JoinScope<X> joinScope = new JoinScope<X>() {
+ // IMPL NOTE : another means from handling correlations is to create a series of
+ // specialized From implementations that represent the correlation roots. While
+ // that may be cleaner code-wise, it is certainly means creating a lot of "extra"
+ // classes since we'd need one for each Subquery#correlate method
+
+ private FromImplementor<Z,X> correlationParent;
+
+ private JoinScope<X> joinScope = new BasicJoinScope();
+
+ /**
+ * Helper contract used to define who/what keeps track of joins and fetches made from this <tt>FROM</tt>.
+ */
+ public static interface JoinScope<X> extends Serializable {
+ public void addJoin(Join<X, ?> join);
+ public void addFetch(Fetch<X,?> fetch);
+ }
+
+ protected class BasicJoinScope implements JoinScope<X> {
public void addJoin(Join<X, ?> join) {
if ( joins == null ) {
joins = new LinkedHashSet<Join<X,?>>();
@@ -152,8 +179,21 @@
}
fetches.add( fetch );
}
- };
+ }
+ protected class CorrelationJoinScope implements JoinScope<X> {
+ public void addJoin(Join<X, ?> join) {
+ if ( joins == null ) {
+ joins = new LinkedHashSet<Join<X,?>>();
+ }
+ joins.add( join );
+ }
+
+ public void addFetch(Fetch<X, ?> fetch) {
+ throw new UnsupportedOperationException( "Cannot define fetch from a subquery correlation" );
+ }
+ }
+
/**
* {@inheritDoc}
*/
@@ -164,7 +204,7 @@
/**
* {@inheritDoc}
*/
- public From<Z,X> getCorrelationParent() {
+ public FromImplementor<Z,X> getCorrelationParent() {
return correlationParent;
}
@@ -174,17 +214,21 @@
@SuppressWarnings({ "unchecked" })
public FromImplementor<Z, X> correlateTo(CriteriaSubqueryImpl subquery) {
final FromImplementor<Z, X> correlationDelegate = createCorrelationDelegate();
- correlationDelegate.prepareCorrelationDelegate( subquery.getJoinScope(), this );
+ correlationDelegate.prepareCorrelationDelegate( this );
return correlationDelegate;
}
protected abstract FromImplementor<Z, X> createCorrelationDelegate();
- public void prepareCorrelationDelegate(JoinScope<X> joinScope, FromImplementor<Z, X> parent) {
- this.joinScope = joinScope;
+ public void prepareCorrelationDelegate(FromImplementor<Z, X> parent) {
+ this.joinScope = new CorrelationJoinScope();
this.correlationParent = parent;
}
+ @Override
+ public String getAlias() {
+ return isCorrelated() ? getCorrelationParent().getAlias() : super.getAlias();
+ }
// JOINS ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Added: core/trunk/entitymanager/src/test/java/org/hibernate/ejb/criteria/subquery/CorrelatedSubqueryTest.java
===================================================================
--- core/trunk/entitymanager/src/test/java/org/hibernate/ejb/criteria/subquery/CorrelatedSubqueryTest.java (rev 0)
+++ core/trunk/entitymanager/src/test/java/org/hibernate/ejb/criteria/subquery/CorrelatedSubqueryTest.java 2010-01-09 16:24:44 UTC (rev 18481)
@@ -0,0 +1,130 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.ejb.criteria.subquery;
+
+import java.util.List;
+import javax.persistence.EntityManager;
+import javax.persistence.TypedQuery;
+import javax.persistence.criteria.CriteriaBuilder;
+import javax.persistence.criteria.CriteriaQuery;
+import javax.persistence.criteria.Join;
+import javax.persistence.criteria.Root;
+import javax.persistence.criteria.Subquery;
+
+import org.hibernate.ejb.metamodel.AbstractMetamodelSpecificTest;
+import org.hibernate.ejb.metamodel.Customer;
+import org.hibernate.ejb.metamodel.Customer_;
+import org.hibernate.ejb.metamodel.LineItem;
+import org.hibernate.ejb.metamodel.LineItem_;
+import org.hibernate.ejb.metamodel.Order;
+import org.hibernate.ejb.metamodel.Order_;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+public class CorrelatedSubqueryTest extends AbstractMetamodelSpecificTest {
+ public void testBasicCorrelation() {
+ CriteriaBuilder builder = factory.getCriteriaBuilder();
+ EntityManager em = getOrCreateEntityManager();
+ em.getTransaction().begin();
+
+ CriteriaQuery<Customer> criteria = builder.createQuery( Customer.class );
+ Root<Customer> customer = criteria.from( Customer.class );
+ criteria.select( customer );
+ Subquery<Order> orderSubquery = criteria.subquery( Order.class );
+ Root<Customer> customerCorrelationRoot = orderSubquery.correlate( customer );
+ Join<Customer, Order> customerOrderCorrelationJoin = customerCorrelationRoot.join( Customer_.orders );
+ orderSubquery.select( customerOrderCorrelationJoin );
+ criteria.where( builder.not( builder.exists( orderSubquery ) ) );
+ em.createQuery( criteria ).getResultList();
+
+ em.getTransaction().commit();
+ em.close();
+ }
+
+ public void testRestrictedCorrelation() {
+ CriteriaBuilder builder = factory.getCriteriaBuilder();
+ EntityManager em = getOrCreateEntityManager();
+ em.getTransaction().begin();
+
+ CriteriaQuery<Order> criteria = builder.createQuery( Order.class );
+ Root<Order> orderRoot = criteria.from( Order.class );
+ criteria.select( orderRoot );
+ // create correlated subquery
+ Subquery<Customer> customerSubquery = criteria.subquery( Customer.class );
+ Root<Order> orderRootCorrelation = customerSubquery.correlate( orderRoot );
+ Join<Order, Customer> orderCustomerJoin = orderRootCorrelation.join( Order_.customer );
+ customerSubquery.where( builder.like( orderCustomerJoin.get( Customer_.name ), "%Caruso" ) )
+ .select( orderCustomerJoin );
+ criteria.where( builder.exists( customerSubquery ) );
+ em.createQuery( criteria ).getResultList();
+
+ em.getTransaction().commit();
+ em.close();
+ }
+
+ public void testCorrelationExplicitSelectionCorrelation() {
+ CriteriaBuilder builder = factory.getCriteriaBuilder();
+ EntityManager em = getOrCreateEntityManager();
+ em.getTransaction().begin();
+
+ CriteriaQuery<Customer> customerCriteria = builder.createQuery( Customer.class );
+ Root<Customer> customer = customerCriteria.from( Customer.class );
+ Join<Customer, Order> o = customer.join( Customer_.orders );
+ Subquery<Order> sq = customerCriteria.subquery(Order.class);
+ Join<Customer, Order> sqo = sq.correlate(o);
+ Join<Order, LineItem> sql = sqo.join(Order_.lineItems);
+ sq.where( builder.gt(sql.get( LineItem_.quantity), 3) );
+ // use the correlation itself as the subquery selection (initially caused problems wrt aliases)
+ sq.select(sqo);
+ customerCriteria.select(customer).distinct(true);
+ customerCriteria.where(builder.exists(sq));
+ em.createQuery( customerCriteria ).getResultList();
+
+ em.getTransaction().commit();
+ em.close();
+ }
+
+ public void testRestrictedCorrelationNoExplicitSelection() {
+ CriteriaBuilder builder = factory.getCriteriaBuilder();
+ EntityManager em = getOrCreateEntityManager();
+ em.getTransaction().begin();
+
+ CriteriaQuery<Order> criteria = builder.createQuery( Order.class );
+ Root<Order> orderRoot = criteria.from( Order.class );
+ criteria.select( orderRoot );
+ // create correlated subquery
+ Subquery<Customer> customerSubquery = criteria.subquery( Customer.class );
+ Root<Order> orderRootCorrelation = customerSubquery.correlate( orderRoot );
+ Join<Order, Customer> orderCustomerJoin = orderRootCorrelation.join( "customer" );
+ customerSubquery.where( builder.like( orderCustomerJoin.<String>get( "name" ), "%Caruso" ) );
+ criteria.where( builder.exists( customerSubquery ) );
+ em.createQuery( criteria ).getResultList();
+
+ em.getTransaction().commit();
+ em.close();
+ }
+}
15 years
Hibernate SVN: r18480 - in search/trunk/src/test/java/org/hibernate/search/test: batchindexing and 5 other directories.
by hibernate-commits@lists.jboss.org
Author: sannegrinovero
Date: 2010-01-09 10:49:30 -0500 (Sat, 09 Jan 2010)
New Revision: 18480
Modified:
search/trunk/src/test/java/org/hibernate/search/test/SearchTestCase.java
search/trunk/src/test/java/org/hibernate/search/test/batchindexing/IndexingGeneratedCorpusTest.java
search/trunk/src/test/java/org/hibernate/search/test/configuration/ShardsConfigurationTest.java
search/trunk/src/test/java/org/hibernate/search/test/directoryProvider/CustomLockProviderTest.java
search/trunk/src/test/java/org/hibernate/search/test/shards/DirectoryProviderForQueryTest.java
search/trunk/src/test/java/org/hibernate/search/test/similarity/IllegalSimilarityConfigurationTest.java
search/trunk/src/test/java/org/hibernate/search/test/util/FullTextSessionBuilder.java
Log:
HSEARCH-408 more tests cleanup: remove unneeded file operations, prevent some SessionFactories from leaking
Modified: search/trunk/src/test/java/org/hibernate/search/test/SearchTestCase.java
===================================================================
--- search/trunk/src/test/java/org/hibernate/search/test/SearchTestCase.java 2010-01-09 15:23:37 UTC (rev 18479)
+++ search/trunk/src/test/java/org/hibernate/search/test/SearchTestCase.java 2010-01-09 15:49:30 UTC (rev 18480)
@@ -90,7 +90,7 @@
PostInsertEventListener[] listeners = ( ( SessionFactoryImpl ) getSessions() ).getEventListeners()
.getPostInsertEventListeners();
FullTextIndexEventListener listener = null;
- //FIXME this sucks since we mandante the event listener use
+ //FIXME this sucks since we mandate the event listener use
for ( PostInsertEventListener candidate : listeners ) {
if ( candidate instanceof FullTextIndexEventListener ) {
listener = ( FullTextIndexEventListener ) candidate;
Modified: search/trunk/src/test/java/org/hibernate/search/test/batchindexing/IndexingGeneratedCorpusTest.java
===================================================================
--- search/trunk/src/test/java/org/hibernate/search/test/batchindexing/IndexingGeneratedCorpusTest.java 2010-01-09 15:23:37 UTC (rev 18479)
+++ search/trunk/src/test/java/org/hibernate/search/test/batchindexing/IndexingGeneratedCorpusTest.java 2010-01-09 15:49:30 UTC (rev 18480)
@@ -66,6 +66,11 @@
createMany( Dvd.class, DVD_NUM );
createMany( AncientBook.class, ANCIENTBOOK_NUM );
}
+
+ @Override
+ protected void tearDown() {
+ builder.close();
+ }
private void createMany(Class<? extends TitleAble> entityType, int amount ) throws InstantiationException, IllegalAccessException {
FullTextSession fullTextSession = builder.openFullTextSession();
Modified: search/trunk/src/test/java/org/hibernate/search/test/configuration/ShardsConfigurationTest.java
===================================================================
--- search/trunk/src/test/java/org/hibernate/search/test/configuration/ShardsConfigurationTest.java 2010-01-09 15:23:37 UTC (rev 18479)
+++ search/trunk/src/test/java/org/hibernate/search/test/configuration/ShardsConfigurationTest.java 2010-01-09 15:49:30 UTC (rev 18480)
@@ -109,6 +109,11 @@
assertValueIsSet( Document.class, 1, BATCH, MAX_MERGE_DOCS, 11 );
}
+ @Override
+ protected void ensureIndexesAreEmpty() {
+ // skips index emptying to prevent a problem with UselessShardingStrategy
+ }
+
protected Class[] getMappings() {
return new Class[] {
Book.class,
Modified: search/trunk/src/test/java/org/hibernate/search/test/directoryProvider/CustomLockProviderTest.java
===================================================================
--- search/trunk/src/test/java/org/hibernate/search/test/directoryProvider/CustomLockProviderTest.java 2010-01-09 15:23:37 UTC (rev 18479)
+++ search/trunk/src/test/java/org/hibernate/search/test/directoryProvider/CustomLockProviderTest.java 2010-01-09 15:49:30 UTC (rev 18480)
@@ -26,7 +26,6 @@
import junit.framework.TestCase;
-import org.hibernate.search.event.ContextHolder;
import org.hibernate.search.test.util.FullTextSessionBuilder;
/**
Modified: search/trunk/src/test/java/org/hibernate/search/test/shards/DirectoryProviderForQueryTest.java
===================================================================
--- search/trunk/src/test/java/org/hibernate/search/test/shards/DirectoryProviderForQueryTest.java 2010-01-09 15:23:37 UTC (rev 18479)
+++ search/trunk/src/test/java/org/hibernate/search/test/shards/DirectoryProviderForQueryTest.java 2010-01-09 15:49:30 UTC (rev 18480)
@@ -24,35 +24,25 @@
*/
package org.hibernate.search.test.shards;
-import java.io.File;
import java.util.List;
import org.apache.lucene.analysis.StopAnalyzer;
import org.apache.lucene.queryParser.QueryParser;
-
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
-import org.hibernate.search.Environment;
import org.hibernate.search.FullTextQuery;
import org.hibernate.search.FullTextSession;
import org.hibernate.search.Search;
-import org.hibernate.search.store.FSDirectoryProvider;
import org.hibernate.search.test.SearchTestCase;
-import org.hibernate.search.util.FileHelper;
/**
* @author Chase Seibert
*/
public class DirectoryProviderForQueryTest extends SearchTestCase {
-
protected void configure(Configuration cfg) {
super.configure( cfg );
- cfg.setProperty( "hibernate.search.default.directory_provider", FSDirectoryProvider.class.getName() );
- File sub = getBaseIndexDir();
- cfg.setProperty( "hibernate.search.default.indexBase", sub.getAbsolutePath() );
- cfg.setProperty( Environment.ANALYZER_CLASS, StopAnalyzer.class.getName() );
// this strategy allows the caller to use a pre-search filter to define which index to hit
cfg.setProperty( "hibernate.search.Email.sharding_strategy", SpecificShardingStrategy.class.getCanonicalName() );
cfg.setProperty( "hibernate.search.Email.sharding_strategy.nbr_of_shards", "2" );
@@ -97,29 +87,11 @@
s.close();
}
- protected void setUp() throws Exception {
- File sub = getBaseIndexDir();
- sub.mkdir();
- File[] files = sub.listFiles();
- for (File file : files) {
- if ( file.isDirectory() ) {
- FileHelper.delete( file );
- }
- }
- super.setUp(); //we need a fresh session factory each time for index set up
- buildSessionFactory( getMappings(), getAnnotatedPackages(), getXmlFiles() );
- }
-
- protected void tearDown() throws Exception {
- super.tearDown();
- File sub = getBaseIndexDir();
- FileHelper.delete( sub );
- }
-
@SuppressWarnings("unchecked")
protected Class[] getMappings() {
return new Class[] {
Email.class
};
}
+
}
Modified: search/trunk/src/test/java/org/hibernate/search/test/similarity/IllegalSimilarityConfigurationTest.java
===================================================================
--- search/trunk/src/test/java/org/hibernate/search/test/similarity/IllegalSimilarityConfigurationTest.java 2010-01-09 15:23:37 UTC (rev 18479)
+++ search/trunk/src/test/java/org/hibernate/search/test/similarity/IllegalSimilarityConfigurationTest.java 2010-01-09 15:49:30 UTC (rev 18480)
@@ -32,68 +32,88 @@
public void testValidConfiguration() {
boolean configurationIsLegal = true;
+ FullTextSessionBuilder builder = null;
try {
- FullTextSessionBuilder builder = new FullTextSessionBuilder()
+ builder = new FullTextSessionBuilder()
.addAnnotatedClass(Can.class)
.addAnnotatedClass(Trash.class).build();
- builder.close();
} catch (Exception e) {
configurationIsLegal = false;
}
+ finally {
+ if (builder!=null)
+ builder.close();
+ }
assertTrue( "A valid configuration could not be started.", configurationIsLegal );
}
public void testInconsistentSimilarityInClassHierarchy() {
boolean configurationIsLegal = true;
+ FullTextSessionBuilder builder = null;
try {
- FullTextSessionBuilder builder = new FullTextSessionBuilder()
+ builder = new FullTextSessionBuilder()
.addAnnotatedClass( Trash.class )
.addAnnotatedClass( LittleTrash.class ).build();
- builder.close();
} catch (Exception e) {
configurationIsLegal = false;
}
+ finally {
+ if (builder!=null)
+ builder.close();
+ }
assertFalse( "Invalid Similarity declared, should have thrown an exception: same similarity"
+ " must be used across class hierarchy", configurationIsLegal );
}
public void testInconsistentSimilarityInClassSharingAnIndex() {
boolean configurationIsLegal = true;
+ FullTextSessionBuilder builder = null;
try {
- FullTextSessionBuilder builder = new FullTextSessionBuilder()
+ builder = new FullTextSessionBuilder()
.addAnnotatedClass( Trash.class )
.addAnnotatedClass( Sink.class ).build();
- builder.close();
} catch (Exception e) {
configurationIsLegal = false;
}
+ finally {
+ if (builder!=null)
+ builder.close();
+ }
assertFalse( "Invalid Similarity declared, should have thrown an exception: two entities"
+ "sharing the same index are using a different similarity", configurationIsLegal );
}
public void testImplicitSimilarityInheritanceIsValid() {
boolean configurationIsLegal = true;
+ FullTextSessionBuilder builder = null;
try {
- FullTextSessionBuilder builder = new FullTextSessionBuilder()
+ builder = new FullTextSessionBuilder()
.addAnnotatedClass( Trash.class )
.addAnnotatedClass( ProperTrashExtension.class ).build();
- builder.close();
} catch (Exception e) {
configurationIsLegal = false;
}
+ finally {
+ if (builder!=null)
+ builder.close();
+ }
assertTrue( "Valid configuration could not be built", configurationIsLegal );
}
public void testInvalidToOverrideParentsSimilarity() {
boolean configurationIsLegal = true;
+ FullTextSessionBuilder builder = null;
try {
- FullTextSessionBuilder builder = new FullTextSessionBuilder()
+ builder = new FullTextSessionBuilder()
.addAnnotatedClass( Can.class )
.addAnnotatedClass( SmallerCan.class ).build();
- builder.close();
} catch (Exception e) {
configurationIsLegal = false;
}
+ finally {
+ if (builder!=null)
+ builder.close();
+ }
assertFalse( "Invalid Similarity declared, should have thrown an exception: child entity"
+ " is overriding parent's Similarity", configurationIsLegal );
}
Modified: search/trunk/src/test/java/org/hibernate/search/test/util/FullTextSessionBuilder.java
===================================================================
--- search/trunk/src/test/java/org/hibernate/search/test/util/FullTextSessionBuilder.java 2010-01-09 15:23:37 UTC (rev 18479)
+++ search/trunk/src/test/java/org/hibernate/search/test/util/FullTextSessionBuilder.java 2010-01-09 15:49:30 UTC (rev 18480)
@@ -54,6 +54,7 @@
private AnnotationConfiguration cfg;
private SessionFactory sessionFactory;
+ private boolean usingFileSystem = false;
static {
String buildDir = System.getProperty( "build.dir" );
@@ -89,10 +90,12 @@
if ( use ) {
cfg.setProperty( "hibernate.search.default.directory_provider",
RAMDirectoryProvider.class.getName() );
+ usingFileSystem = false;
}
else {
cfg.setProperty( "hibernate.search.default.directory_provider",
FSDirectoryProvider.class.getName() );
+ usingFileSystem = true;
}
return this;
}
@@ -138,7 +141,9 @@
throw new java.lang.IllegalStateException( "sessionFactory not yet built" );
}
sessionFactory.close();
- FileHelper.delete( indexDir );
+ if ( usingFileSystem ) {
+ FileHelper.delete( indexDir );
+ }
sessionFactory = null;
}
15 years
Hibernate SVN: r18479 - in search/trunk/src: test/java/org/hibernate/search/test/directoryProvider and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: sannegrinovero
Date: 2010-01-09 10:23:37 -0500 (Sat, 09 Jan 2010)
New Revision: 18479
Modified:
search/trunk/src/main/java/org/hibernate/search/store/DirectoryProviderHelper.java
search/trunk/src/test/java/org/hibernate/search/test/directoryProvider/CustomLockProviderTest.java
Log:
HSEARCH-441 Custom LockFactory loading should use PluginLoader
Modified: search/trunk/src/main/java/org/hibernate/search/store/DirectoryProviderHelper.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/store/DirectoryProviderHelper.java 2010-01-09 15:23:03 UTC (rev 18478)
+++ search/trunk/src/main/java/org/hibernate/search/store/DirectoryProviderHelper.java 2010-01-09 15:23:37 UTC (rev 18479)
@@ -43,7 +43,7 @@
import org.hibernate.search.SearchException;
import org.hibernate.search.util.FileHelper;
import org.hibernate.search.util.LoggerFactory;
-import org.hibernate.util.ReflectHelper;
+import org.hibernate.search.util.PluginLoader;
/**
* @author Emmanuel Bernard
@@ -161,26 +161,8 @@
return new NoLockFactory();
}
else {
- LockFactoryFactory lockFactoryFactory;
- try {
- Class lockFactoryClass = ReflectHelper.classForName( lockFactoryName, dirConfiguration.getClass() );
- lockFactoryFactory = (LockFactoryFactory) lockFactoryClass.newInstance();
- }
- catch (ClassNotFoundException e) {
- throw new SearchException( "Unable to find LockFactoryFactory class " + lockFactoryName, e );
- }
- catch (IllegalAccessException e) {
- throw new SearchException( "Unable to create instance of LockFactoryFactory class " + lockFactoryName
- + " Be sure to have a no-arg constructor", e );
- }
- catch (InstantiationException e) {
- throw new SearchException( "Unable to create instance of LockFactoryFactory class " + lockFactoryName
- + " Be sure to have a no-arg constructor", e );
- }
- catch (ClassCastException e) {
- throw new SearchException( "Class does not implement LockFactoryFactory: "
- + lockFactoryName, e );
- }
+ LockFactoryFactory lockFactoryFactory = PluginLoader.instanceFromName( LockFactoryFactory.class,
+ lockFactoryName, DirectoryProviderHelper.class, "locking_strategy" );
return lockFactoryFactory.createLockFactory( indexDir, dirConfiguration );
}
}
Modified: search/trunk/src/test/java/org/hibernate/search/test/directoryProvider/CustomLockProviderTest.java
===================================================================
--- search/trunk/src/test/java/org/hibernate/search/test/directoryProvider/CustomLockProviderTest.java 2010-01-09 15:23:03 UTC (rev 18478)
+++ search/trunk/src/test/java/org/hibernate/search/test/directoryProvider/CustomLockProviderTest.java 2010-01-09 15:23:37 UTC (rev 18479)
@@ -26,6 +26,7 @@
import junit.framework.TestCase;
+import org.hibernate.search.event.ContextHolder;
import org.hibernate.search.test.util.FullTextSessionBuilder;
/**
@@ -62,7 +63,7 @@
assertTrue( causeSearch instanceof org.hibernate.search.SearchException );
Throwable causeLockin = causeSearch.getCause();
assertNotNull( causeLockin );
- assertTrue( causeLockin.getMessage().startsWith("Unable to find LockFactory") );
+ assertEquals( "Unable to find locking_strategy implementation class: org.hibernate.NotExistingFactory", causeLockin.getMessage() );
}
}
15 years
Hibernate SVN: r18478 - annotations/branches/v3_4_0_GA_CP/src/main/java/org/hibernate/annotations.
by hibernate-commits@lists.jboss.org
Author: stliu
Date: 2010-01-09 10:23:03 -0500 (Sat, 09 Jan 2010)
New Revision: 18478
Modified:
annotations/branches/v3_4_0_GA_CP/src/main/java/org/hibernate/annotations/MapKey.java
Log:
minor change, correct javadoc spell
Modified: annotations/branches/v3_4_0_GA_CP/src/main/java/org/hibernate/annotations/MapKey.java
===================================================================
--- annotations/branches/v3_4_0_GA_CP/src/main/java/org/hibernate/annotations/MapKey.java 2010-01-09 15:20:24 UTC (rev 18477)
+++ annotations/branches/v3_4_0_GA_CP/src/main/java/org/hibernate/annotations/MapKey.java 2010-01-09 15:23:03 UTC (rev 18478)
@@ -10,7 +10,7 @@
/**
* Define the map key columns as an explicit column holding the map key
- * This is completly different from {@link javax.persistence.MapKey} which use an existing column
+ * This is completely different from {@link javax.persistence.MapKey} which use an existing column
* This annotation and {@link javax.persistence.MapKey} are mutually exclusive
*
* @author Emmanuel Bernard
15 years
Hibernate SVN: r18477 - annotations/branches/v3_4_0_GA_CP/src/test/java/org/hibernate/test/annotations/cid.
by hibernate-commits@lists.jboss.org
Author: stliu
Date: 2010-01-09 10:20:24 -0500 (Sat, 09 Jan 2010)
New Revision: 18477
Modified:
annotations/branches/v3_4_0_GA_CP/src/test/java/org/hibernate/test/annotations/cid/AId.java
annotations/branches/v3_4_0_GA_CP/src/test/java/org/hibernate/test/annotations/cid/ChildPk.java
annotations/branches/v3_4_0_GA_CP/src/test/java/org/hibernate/test/annotations/cid/TvMagazin.java
annotations/branches/v3_4_0_GA_CP/src/test/java/org/hibernate/test/annotations/cid/TvMagazinPk.java
Log:
JBPAPP-3375 HHH-4773 unit tests fail cos db2 doesn't allow primary key column nullable
Modified: annotations/branches/v3_4_0_GA_CP/src/test/java/org/hibernate/test/annotations/cid/AId.java
===================================================================
--- annotations/branches/v3_4_0_GA_CP/src/test/java/org/hibernate/test/annotations/cid/AId.java 2010-01-09 14:35:37 UTC (rev 18476)
+++ annotations/branches/v3_4_0_GA_CP/src/test/java/org/hibernate/test/annotations/cid/AId.java 2010-01-09 15:20:24 UTC (rev 18477)
@@ -14,11 +14,11 @@
public class AId implements Serializable {
@OneToOne
- @JoinColumn( name = "bid" )
+ @JoinColumn( name = "bid",nullable=false )
private B b;
@OneToOne
- @JoinColumn( name = "cid" )
+ @JoinColumn( name = "cid",nullable=false )
private C c;
Modified: annotations/branches/v3_4_0_GA_CP/src/test/java/org/hibernate/test/annotations/cid/ChildPk.java
===================================================================
--- annotations/branches/v3_4_0_GA_CP/src/test/java/org/hibernate/test/annotations/cid/ChildPk.java 2010-01-09 14:35:37 UTC (rev 18476)
+++ annotations/branches/v3_4_0_GA_CP/src/test/java/org/hibernate/test/annotations/cid/ChildPk.java 2010-01-09 15:20:24 UTC (rev 18477)
@@ -17,8 +17,8 @@
public int nthChild;
@ManyToOne()
@JoinColumns({
- @JoinColumn(name = "parentLastName", referencedColumnName = "p_lname"),
- @JoinColumn(name = "parentFirstName", referencedColumnName = "firstName")
+ @JoinColumn(name = "parentLastName", referencedColumnName = "p_lname",nullable=false),
+ @JoinColumn(name = "parentFirstName", referencedColumnName = "firstName",nullable=false)
})
public Parent parent;
Modified: annotations/branches/v3_4_0_GA_CP/src/test/java/org/hibernate/test/annotations/cid/TvMagazin.java
===================================================================
--- annotations/branches/v3_4_0_GA_CP/src/test/java/org/hibernate/test/annotations/cid/TvMagazin.java 2010-01-09 14:35:37 UTC (rev 18476)
+++ annotations/branches/v3_4_0_GA_CP/src/test/java/org/hibernate/test/annotations/cid/TvMagazin.java 2010-01-09 15:20:24 UTC (rev 18477)
@@ -13,7 +13,7 @@
* @author Emmanuel Bernard
*/
@Entity
-@AssociationOverride(name = "id.channel", joinColumns = @JoinColumn(name = "chan_id"))
+@AssociationOverride(name = "id.channel", joinColumns = @JoinColumn(name = "chan_id",nullable=false))
public class TvMagazin {
@EmbeddedId
public TvMagazinPk id;
Modified: annotations/branches/v3_4_0_GA_CP/src/test/java/org/hibernate/test/annotations/cid/TvMagazinPk.java
===================================================================
--- annotations/branches/v3_4_0_GA_CP/src/test/java/org/hibernate/test/annotations/cid/TvMagazinPk.java 2010-01-09 14:35:37 UTC (rev 18476)
+++ annotations/branches/v3_4_0_GA_CP/src/test/java/org/hibernate/test/annotations/cid/TvMagazinPk.java 2010-01-09 15:20:24 UTC (rev 18477)
@@ -2,7 +2,9 @@
package org.hibernate.test.annotations.cid;
import java.io.Serializable;
+
import javax.persistence.Embeddable;
+import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
/**
@@ -11,8 +13,10 @@
@Embeddable
public class TvMagazinPk implements Serializable {
@ManyToOne
+ @JoinColumn(nullable=false)
public Channel channel;
//public String name;
@ManyToOne
+ @JoinColumn(nullable=false)
public Presenter presenter;
}
15 years
Hibernate SVN: r18476 - annotations/branches/v3_4_0_GA_CP/src/test/java/org/hibernate/test/annotations/target.
by hibernate-commits@lists.jboss.org
Author: stliu
Date: 2010-01-09 09:35:37 -0500 (Sat, 09 Jan 2010)
New Revision: 18476
Modified:
annotations/branches/v3_4_0_GA_CP/src/test/java/org/hibernate/test/annotations/target/SizeImpl.java
Log:
JBPAPP-3375 HHH-4773 unit tests fail cos db2 doesn't allow primary key column nullable
Modified: annotations/branches/v3_4_0_GA_CP/src/test/java/org/hibernate/test/annotations/target/SizeImpl.java
===================================================================
--- annotations/branches/v3_4_0_GA_CP/src/test/java/org/hibernate/test/annotations/target/SizeImpl.java 2010-01-09 14:14:34 UTC (rev 18475)
+++ annotations/branches/v3_4_0_GA_CP/src/test/java/org/hibernate/test/annotations/target/SizeImpl.java 2010-01-09 14:35:37 UTC (rev 18476)
@@ -1,6 +1,7 @@
//$Id$
package org.hibernate.test.annotations.target;
+import javax.persistence.Column;
import javax.persistence.Embeddable;
/**
@@ -8,6 +9,7 @@
*/
@Embeddable
public class SizeImpl implements Size {
+ @Column(nullable=false)
private String name;
public String getName() {
15 years
Hibernate SVN: r18475 - search/branches/v3_1_1_GA_CP/src/test/java/org/hibernate/search/test/embedded.
by hibernate-commits@lists.jboss.org
Author: stliu
Date: 2010-01-09 09:14:34 -0500 (Sat, 09 Jan 2010)
New Revision: 18475
Modified:
search/branches/v3_1_1_GA_CP/src/test/java/org/hibernate/search/test/embedded/Product.java
Log:
JBPAPP-3375 HHH-4773 unit tests fail cos db2 doesn't allow primary key column nullable
Modified: search/branches/v3_1_1_GA_CP/src/test/java/org/hibernate/search/test/embedded/Product.java
===================================================================
--- search/branches/v3_1_1_GA_CP/src/test/java/org/hibernate/search/test/embedded/Product.java 2010-01-09 13:54:02 UTC (rev 18474)
+++ search/branches/v3_1_1_GA_CP/src/test/java/org/hibernate/search/test/embedded/Product.java 2010-01-09 14:14:34 UTC (rev 18475)
@@ -33,7 +33,7 @@
@IndexedEmbedded
private Set<Author> authors = new HashSet<Author>();
@ManyToMany(cascade = CascadeType.REMOVE) //just to make the test easier, cascade doesn't really make any business sense
- @MapKey(columns = @Column(name="CUST_NAME") )
+ @MapKey(columns = @Column(name="CUST_NAME",nullable=false) )
@IndexedEmbedded
private Map<String, Order> orders = new HashMap<String, Order>();
15 years
Hibernate SVN: r18474 - annotations/branches/v3_4_0_GA_CP/src/test/java/org/hibernate/test/annotations/collectionelement.
by hibernate-commits@lists.jboss.org
Author: stliu
Date: 2010-01-09 08:54:02 -0500 (Sat, 09 Jan 2010)
New Revision: 18474
Modified:
annotations/branches/v3_4_0_GA_CP/src/test/java/org/hibernate/test/annotations/collectionelement/Boy.java
annotations/branches/v3_4_0_GA_CP/src/test/java/org/hibernate/test/annotations/collectionelement/LocalizedString.java
annotations/branches/v3_4_0_GA_CP/src/test/java/org/hibernate/test/annotations/collectionelement/Matrix.java
Log:
JBPAPP-3375 HHH-4773 unit tests fail cos db2 doesn't allow primary key column nullable
Modified: annotations/branches/v3_4_0_GA_CP/src/test/java/org/hibernate/test/annotations/collectionelement/Boy.java
===================================================================
--- annotations/branches/v3_4_0_GA_CP/src/test/java/org/hibernate/test/annotations/collectionelement/Boy.java 2010-01-09 13:36:10 UTC (rev 18473)
+++ annotations/branches/v3_4_0_GA_CP/src/test/java/org/hibernate/test/annotations/collectionelement/Boy.java 2010-01-09 13:54:02 UTC (rev 18474)
@@ -19,6 +19,7 @@
import org.hibernate.annotations.CollectionOfElements;
import org.hibernate.annotations.IndexColumn;
+import org.hibernate.annotations.MapKey;
/**
* @author Emmanuel Bernard
@@ -74,7 +75,7 @@
public void setNickNames(Set<String> nickName) {
this.nickNames = nickName;
}
-
+ @MapKey(columns=@Column(nullable=false))
@CollectionOfElements
@JoinTable(name = "ScorePerNickName", joinColumns = @JoinColumn(name = "BoyId"))
@Column(name = "score", nullable = false)
Modified: annotations/branches/v3_4_0_GA_CP/src/test/java/org/hibernate/test/annotations/collectionelement/LocalizedString.java
===================================================================
--- annotations/branches/v3_4_0_GA_CP/src/test/java/org/hibernate/test/annotations/collectionelement/LocalizedString.java 2010-01-09 13:36:10 UTC (rev 18473)
+++ annotations/branches/v3_4_0_GA_CP/src/test/java/org/hibernate/test/annotations/collectionelement/LocalizedString.java 2010-01-09 13:54:02 UTC (rev 18474)
@@ -33,7 +33,7 @@
new HashMap<String, String>( 1 );
@CollectionOfElements
- @MapKey( columns = @Column( name = "language_code" ) )
+ @MapKey( columns = @Column( name = "language_code",nullable=false) )
@Fetch( FetchMode.JOIN )
@Filter( name = "selectedLocale",
condition = " language_code = :param " )
Modified: annotations/branches/v3_4_0_GA_CP/src/test/java/org/hibernate/test/annotations/collectionelement/Matrix.java
===================================================================
--- annotations/branches/v3_4_0_GA_CP/src/test/java/org/hibernate/test/annotations/collectionelement/Matrix.java 2010-01-09 13:36:10 UTC (rev 18473)
+++ annotations/branches/v3_4_0_GA_CP/src/test/java/org/hibernate/test/annotations/collectionelement/Matrix.java 2010-01-09 13:54:02 UTC (rev 18474)
@@ -5,6 +5,7 @@
import java.util.SortedMap;
import java.util.TreeMap;
+import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
@@ -24,7 +25,7 @@
@GeneratedValue
private Integer id;
- @MapKey(type = @Type(type="integer") )
+ @MapKey(type = @Type(type="integer"),columns=@Column(name="mapkey",nullable=false) )
@CollectionOfElements
@Sort(type = SortType.NATURAL)
@Type(type = "float")
15 years