Hibernate SVN: r17536 - beanvalidation/trunk/validation-api/src/main/java/javax/validation.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2009-09-24 10:56:15 -0400 (Thu, 24 Sep 2009)
New Revision: 17536
Modified:
beanvalidation/trunk/validation-api/src/main/java/javax/validation/ConstraintViolationException.java
Log:
remove unnecessary generics
Modified: beanvalidation/trunk/validation-api/src/main/java/javax/validation/ConstraintViolationException.java
===================================================================
--- beanvalidation/trunk/validation-api/src/main/java/javax/validation/ConstraintViolationException.java 2009-09-24 14:36:36 UTC (rev 17535)
+++ beanvalidation/trunk/validation-api/src/main/java/javax/validation/ConstraintViolationException.java 2009-09-24 14:56:15 UTC (rev 17536)
@@ -33,7 +33,7 @@
* @param message error message
* @param constraintViolations Set of ConstraintViolation
*/
- public <T> ConstraintViolationException(String message,
+ public ConstraintViolationException(String message,
Set<ConstraintViolation<?>> constraintViolations) {
super( message );
this.constraintViolations = constraintViolations;
@@ -44,7 +44,7 @@
*
* @param constraintViolations Set of ConstraintViolation
*/
- public <T> ConstraintViolationException(Set<ConstraintViolation<?>> constraintViolations) {
+ public ConstraintViolationException(Set<ConstraintViolation<?>> constraintViolations) {
super();
this.constraintViolations = constraintViolations;
}
16 years
Hibernate SVN: r17535 - search/branches/Branch_3_0_1_GA_CP/src/test/org/hibernate/search/test.
by hibernate-commits@lists.jboss.org
Author: jcosta(a)redhat.com
Date: 2009-09-24 10:36:36 -0400 (Thu, 24 Sep 2009)
New Revision: 17535
Modified:
search/branches/Branch_3_0_1_GA_CP/src/test/org/hibernate/search/test/TransactionTest.java
Log:
HSEARCH-400 - Added s.connection().setAutoCommit( true ); to the connection in the last scenario of the test
Modified: search/branches/Branch_3_0_1_GA_CP/src/test/org/hibernate/search/test/TransactionTest.java
===================================================================
--- search/branches/Branch_3_0_1_GA_CP/src/test/org/hibernate/search/test/TransactionTest.java 2009-09-23 16:25:07 UTC (rev 17534)
+++ search/branches/Branch_3_0_1_GA_CP/src/test/org/hibernate/search/test/TransactionTest.java 2009-09-24 14:36:36 UTC (rev 17535)
@@ -40,6 +40,7 @@
assertEquals( "rollback() should not index", 3, getDocumentNumber() );
s = getSessions().openSession();
+ s.connection().setAutoCommit( true ); // www.hibernate.org/403.html
s.persist(
new Document( "Java Persistence with Hibernate", "Object/relational mapping with Hibernate", "blah blah blah" )
);
16 years
Hibernate SVN: r17534 - core/trunk/annotations/src/main/java/org/hibernate/cfg/beanvalidation.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2009-09-23 12:25:07 -0400 (Wed, 23 Sep 2009)
New Revision: 17534
Modified:
core/trunk/annotations/src/main/java/org/hibernate/cfg/beanvalidation/BeanValidationEventListener.java
Log:
Fix unsafe use and copy data to Set<ConstraintViolation<?>>
Modified: core/trunk/annotations/src/main/java/org/hibernate/cfg/beanvalidation/BeanValidationEventListener.java
===================================================================
--- core/trunk/annotations/src/main/java/org/hibernate/cfg/beanvalidation/BeanValidationEventListener.java 2009-09-23 16:12:46 UTC (rev 17533)
+++ core/trunk/annotations/src/main/java/org/hibernate/cfg/beanvalidation/BeanValidationEventListener.java 2009-09-23 16:25:07 UTC (rev 17534)
@@ -2,6 +2,7 @@
import java.util.Properties;
import java.util.Set;
+import java.util.HashSet;
import java.util.concurrent.ConcurrentHashMap;
import javax.validation.ConstraintViolation;
import javax.validation.ConstraintViolationException;
@@ -67,15 +68,16 @@
.getValidator();
final Class<?>[] groups = groupsPerOperation.get( operation );
if ( groups.length > 0 ) {
- final Set<ConstraintViolation<T>> constraintViolations =
- validator.validate( object, groups );
- //FIXME CV should no longer be generics
- Object unsafeViolations = constraintViolations;
+ final Set<ConstraintViolation<T>> constraintViolations = validator.validate( object, groups );
if (constraintViolations.size() > 0 ) {
- //FIXME add Set<ConstraintViolation<?>>
+ Set<ConstraintViolation<?>> propagatedViolations =
+ new HashSet<ConstraintViolation<?>>( constraintViolations.size() );
+ for ( ConstraintViolation<?> violation : constraintViolations) {
+ propagatedViolations.add(violation);
+ }
throw new ConstraintViolationException(
"Invalid object at " + operation.getName() + " time for groups " + toString( groups ),
- (Set<ConstraintViolation<?>>) unsafeViolations);
+ propagatedViolations);
}
}
}
16 years
Hibernate SVN: r17533 - in search/trunk/src: test/java/org/hibernate/search/test/embedded and 1 other directories.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2009-09-23 12:12:46 -0400 (Wed, 23 Sep 2009)
New Revision: 17533
Added:
search/trunk/src/test/java/org/hibernate/search/test/embedded/nested/
search/trunk/src/test/java/org/hibernate/search/test/embedded/nested/Address.java
search/trunk/src/test/java/org/hibernate/search/test/embedded/nested/Attribute.java
search/trunk/src/test/java/org/hibernate/search/test/embedded/nested/AttributeValue.java
search/trunk/src/test/java/org/hibernate/search/test/embedded/nested/NestedEmbeddedTest.java
search/trunk/src/test/java/org/hibernate/search/test/embedded/nested/Person.java
search/trunk/src/test/java/org/hibernate/search/test/embedded/nested/Place.java
search/trunk/src/test/java/org/hibernate/search/test/embedded/nested/Product.java
Modified:
search/trunk/src/main/java/org/hibernate/search/engine/DocumentBuilderContainedEntity.java
Log:
HSEARCH-391 - HSEARCH-391 - made sure the top level indexed entity gets found by recusively calling processContainedInInstances.
Refactored the code by splitting out more methods
Modified: search/trunk/src/main/java/org/hibernate/search/engine/DocumentBuilderContainedEntity.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/engine/DocumentBuilderContainedEntity.java 2009-09-23 10:21:55 UTC (rev 17532)
+++ search/trunk/src/main/java/org/hibernate/search/engine/DocumentBuilderContainedEntity.java 2009-09-23 16:12:46 UTC (rev 17533)
@@ -66,7 +66,7 @@
protected final PropertiesMetadata metadata = new PropertiesMetadata();
protected final XClass beanClass;
protected Set<Class<?>> mappedSubclasses = new HashSet<Class<?>>();
- protected ReflectionManager reflectionManager; //available only during initializationa and post-initialization
+ protected ReflectionManager reflectionManager; //available only during initialization and post-initialization
protected int level = 0;
protected int maxLevel = Integer.MAX_VALUE;
protected final ScopedAnalyzer analyzer = new ScopedAnalyzer();
@@ -122,28 +122,28 @@
private void initializeClass(XClass clazz, PropertiesMetadata propertiesMetadata, boolean isRoot, String prefix,
Set<XClass> processedClasses, InitContext context) {
List<XClass> hierarchy = new ArrayList<XClass>();
- for ( XClass currClass = clazz; currClass != null; currClass = currClass.getSuperclass() ) {
- hierarchy.add( currClass );
+ for ( XClass currentClass = clazz; currentClass != null; currentClass = currentClass.getSuperclass() ) {
+ hierarchy.add( currentClass );
}
/*
* Iterate the class hierarchy top down. This allows to override the default analyzer for the properties if the class holds one
*/
for ( int index = hierarchy.size() - 1; index >= 0; index-- ) {
- XClass currClass = hierarchy.get( index );
+ XClass currentClass = hierarchy.get( index );
- initalizeClassLevelAnnotations( currClass, propertiesMetadata, isRoot, prefix, context );
+ initializeClassLevelAnnotations( currentClass, propertiesMetadata, isRoot, prefix, context );
// rejecting non properties (ie regular methods) because the object is loaded from Hibernate,
// so indexing a non property does not make sense
- List<XProperty> methods = currClass.getDeclaredProperties( XClass.ACCESS_PROPERTY );
+ List<XProperty> methods = currentClass.getDeclaredProperties( XClass.ACCESS_PROPERTY );
for ( XProperty method : methods ) {
initializeMemberLevelAnnotations(
method, propertiesMetadata, isRoot, prefix, processedClasses, context
);
}
- List<XProperty> fields = currClass.getDeclaredProperties( XClass.ACCESS_FIELD );
+ List<XProperty> fields = currentClass.getDeclaredProperties( XClass.ACCESS_FIELD );
for ( XProperty field : fields ) {
initializeMemberLevelAnnotations(
field, propertiesMetadata, isRoot, prefix, processedClasses, context
@@ -162,7 +162,7 @@
* @param prefix The current prefix used for the <code>Document</code> field names.
* @param context Handle to default configuration settings.
*/
- private void initalizeClassLevelAnnotations(XClass clazz, PropertiesMetadata propertiesMetadata, boolean isRoot, String prefix, InitContext context) {
+ private void initializeClassLevelAnnotations(XClass clazz, PropertiesMetadata propertiesMetadata, boolean isRoot, String prefix, InitContext context) {
// check for a class level specified analyzer
Analyzer analyzer = getAnalyzer( clazz, context );
@@ -176,8 +176,8 @@
// Check for any ClassBridges annotation.
ClassBridges classBridgesAnn = clazz.getAnnotation( ClassBridges.class );
if ( classBridgesAnn != null ) {
- ClassBridge[] cbs = classBridgesAnn.value();
- for ( ClassBridge cb : cbs ) {
+ ClassBridge[] classBridges = classBridgesAnn.value();
+ for ( ClassBridge cb : classBridges ) {
bindClassBridgeAnnotation( prefix, propertiesMetadata, cb, context );
}
}
@@ -256,15 +256,15 @@
}
private void checkForAnalyzerDiscriminator(XAnnotatedElement annotatedElement, PropertiesMetadata propertiesMetadata) {
- AnalyzerDiscriminator discriminiatorAnn = annotatedElement.getAnnotation( AnalyzerDiscriminator.class );
- if ( discriminiatorAnn != null ) {
+ AnalyzerDiscriminator discriminatorAnn = annotatedElement.getAnnotation( AnalyzerDiscriminator.class );
+ if ( discriminatorAnn != null ) {
if ( propertiesMetadata.discriminator != null ) {
throw new SearchException(
"Multiple AnalyzerDiscriminator defined in the same class hierarchy: " + beanClass.getName()
);
}
- Class<? extends Discriminator> discriminatorClass = discriminiatorAnn.impl();
+ Class<? extends Discriminator> discriminatorClass = discriminatorAnn.impl();
try {
propertiesMetadata.discriminator = discriminatorClass.newInstance();
}
@@ -372,7 +372,7 @@
String localPrefix = buildEmbeddedPrefix( prefix, embeddedAnn, member );
initializeClass( elementClass, metadata, false, localPrefix, processedClasses, context );
/**
- * We will only index the "expected" type but that's OK, HQL cannot do downcasting either
+ * We will only index the "expected" type but that's OK, HQL cannot do down-casting either
*/
if ( member.isArray() ) {
propertiesMetadata.embeddedContainers.add( PropertiesMetadata.Container.ARRAY );
@@ -596,8 +596,6 @@
return strategy;
}
-
- //TODO could we use T instead of EntityClass?
public void addWorkToQueue(Class<T> entityClass, T entity, Serializable id, WorkType workType, List<LuceneWork> queue, SearchFactoryImplementor searchFactoryImplementor) {
/**
* When references are changed, either null or another one, we expect dirty checking to be triggered (both sides
@@ -605,75 +603,101 @@
* When the internal object is changed, we apply the {Add|Update}Work on containedIns
*/
if ( workType.searchForContainers() ) {
- processContainedIn( entity, queue, metadata, searchFactoryImplementor );
+ processContainedInInstances( entity, queue, metadata, searchFactoryImplementor );
}
}
- private void processContainedIn(Object instance, List<LuceneWork> queue, PropertiesMetadata metadata, SearchFactoryImplementor searchFactoryImplementor) {
+ /**
+ * If we have a work instance we have to check whether the intance to be indexed is contained in any other indexed entities.
+ *
+ * @param instance The instance to be indexed
+ * @param queue the current work queue
+ * @param metadata metadata
+ * @param searchFactoryImplementor the current session
+ */
+ private <T> void processContainedInInstances(Object instance, List<LuceneWork> queue, PropertiesMetadata metadata, SearchFactoryImplementor searchFactoryImplementor) {
for ( int i = 0; i < metadata.containedInGetters.size(); i++ ) {
XMember member = metadata.containedInGetters.get( i );
Object value = ReflectionHelper.getMemberValue( instance, member );
+
if ( value == null ) {
continue;
}
if ( member.isArray() ) {
- for ( Object arrayValue : ( Object[] ) value ) {
- //highly inneficient but safe wrt the actual targeted class
- Class<?> valueClass = Hibernate.getClass( arrayValue );
- DocumentBuilderIndexedEntity<?> builderIndexedEntity = searchFactoryImplementor.getDocumentBuilderIndexedEntity(
- valueClass
- );
- if ( builderIndexedEntity == null ) {
- continue;
- }
- processContainedInValue(
- arrayValue, queue, valueClass,
- builderIndexedEntity, searchFactoryImplementor
- );
+ @SuppressWarnings("unchecked")
+ T[] array = ( T[] ) value;
+ for ( T arrayValue : array ) {
+ processSingleContainedInInstance( queue, searchFactoryImplementor, arrayValue );
}
}
else if ( member.isCollection() ) {
- Collection collection;
- if ( Map.class.equals( member.getCollectionClass() ) ) {
- //hum
- collection = ( ( Map ) value ).values();
+ Collection<T> collection = getActualCollection( member, value );
+ for ( T collectionValue : collection ) {
+ processSingleContainedInInstance( queue, searchFactoryImplementor, collectionValue );
}
- else {
- collection = ( Collection ) value;
- }
- for ( Object collectionValue : collection ) {
- //highly inneficient but safe wrt the actual targeted class
- Class<?> valueClass = Hibernate.getClass( collectionValue );
- DocumentBuilderIndexedEntity<?> builderIndexedEntity = searchFactoryImplementor.getDocumentBuilderIndexedEntity(
- valueClass
- );
- if ( builderIndexedEntity == null ) {
- continue;
- }
- processContainedInValue(
- collectionValue, queue, valueClass,
- builderIndexedEntity, searchFactoryImplementor
- );
- }
}
else {
- Class<?> valueClass = Hibernate.getClass( value );
- DocumentBuilderIndexedEntity<?> builderIndexedEntity = searchFactoryImplementor.getDocumentBuilderIndexedEntity(
- valueClass
- );
- if ( builderIndexedEntity == null ) {
- continue;
- }
- processContainedInValue( value, queue, valueClass, builderIndexedEntity, searchFactoryImplementor );
+ processSingleContainedInInstance( queue, searchFactoryImplementor, value );
}
}
- //an embedded cannot have a useful @ContainedIn (no shared reference)
- //do not walk through them
}
- private void processContainedInValue(Object value, List<LuceneWork> queue, Class<?> valueClass,
- DocumentBuilderIndexedEntity builderIndexedEntity, SearchFactoryImplementor searchFactoryImplementor) {
+ /**
+ * A {@code XMember } instance treats a map as a collection as well in which case the map values are returned as
+ * collection.
+ *
+ * @param member The member instance
+ * @param value The value
+ *
+ * @return The {@code value} casted to collection or in case of {@code value} being a map the map values as collection.
+ */
+ private <T> Collection<T> getActualCollection(XMember member, Object value) {
+ Collection<T> collection;
+ if ( Map.class.equals( member.getCollectionClass() ) ) {
+ //hum
+ @SuppressWarnings("unchecked")
+ Collection<T> tmpCollection = ( ( Map<?, T> ) value ).values();
+ collection = tmpCollection;
+ }
+ else {
+ @SuppressWarnings("unchecked")
+ Collection<T> tmpCollection = ( Collection<T> ) value;
+ collection = tmpCollection;
+ }
+ return collection;
+ }
+
+ private <T> void processSingleContainedInInstance(List<LuceneWork> queue, SearchFactoryImplementor searchFactoryImplementor, T value) {
+ @SuppressWarnings("unchecked")
+ Class<T> valueClass = Hibernate.getClass( value );
+ DocumentBuilderIndexedEntity<T> builderIndexedEntity =
+ searchFactoryImplementor.getDocumentBuilderIndexedEntity( valueClass );
+
+ // it could be we have a nested @IndexedEmbedded chain in which case we have to find the top level @Indexed entities
+ if ( builderIndexedEntity == null ) {
+ DocumentBuilderContainedEntity<T> builderContainedEntity =
+ searchFactoryImplementor.getDocumentBuilderContainedEntity( valueClass );
+ if ( builderContainedEntity != null ) {
+ processContainedInInstances( value, queue, builderContainedEntity.metadata, searchFactoryImplementor );
+ }
+ }
+ else {
+ addWorkForEmbeddedValue( value, queue, valueClass, builderIndexedEntity, searchFactoryImplementor );
+ }
+ }
+
+ /**
+ * Create a {@code LuceneWork} instance of the entity which needs updating due to the embedded instance change.
+ *
+ * @param value The value to index
+ * @param queue The current (Lucene) work queue
+ * @param valueClass The class of the value
+ * @param builderIndexedEntity the document builder for the entity which needs updating due to a update event of the embedded instance
+ * @param searchFactoryImplementor the search factory.
+ */
+ private <T> void addWorkForEmbeddedValue(T value, List<LuceneWork> queue, Class<T> valueClass,
+ DocumentBuilderIndexedEntity<T> builderIndexedEntity, SearchFactoryImplementor searchFactoryImplementor) {
Serializable id = ( Serializable ) ReflectionHelper.getMemberValue( value, builderIndexedEntity.idGetter );
builderIndexedEntity.addWorkToQueue( valueClass, value, id, WorkType.UPDATE, queue, searchFactoryImplementor );
}
@@ -727,7 +751,7 @@
public Discriminator discriminator;
public XMember discriminatorGetter;
public BoostStrategy classBoostStrategy;
-
+
public final List<String> fieldNames = new ArrayList<String>();
public final List<XMember> fieldGetters = new ArrayList<XMember>();
public final List<FieldBridge> fieldBridges = new ArrayList<FieldBridge>();
Added: search/trunk/src/test/java/org/hibernate/search/test/embedded/nested/Address.java
===================================================================
--- search/trunk/src/test/java/org/hibernate/search/test/embedded/nested/Address.java (rev 0)
+++ search/trunk/src/test/java/org/hibernate/search/test/embedded/nested/Address.java 2009-09-23 16:12:46 UTC (rev 17533)
@@ -0,0 +1,87 @@
+// $Id:$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+* http://www.apache.org/licenses/LICENSE-2.0
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.hibernate.search.test.embedded.nested;
+
+import java.util.HashSet;
+import java.util.Set;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.OneToMany;
+
+import org.hibernate.search.annotations.ContainedIn;
+import org.hibernate.search.annotations.Field;
+import org.hibernate.search.annotations.Index;
+
+/**
+ * @author Hardy Ferentschik
+ */
+@Entity
+public class Address {
+ @Id
+ @GeneratedValue
+ private Long id;
+
+ @Field(index = Index.TOKENIZED)
+ private String street;
+
+ @Field(index = Index.TOKENIZED)
+ private String city;
+
+ @ContainedIn
+ @OneToMany(mappedBy = "address")
+ private Set<Place> places;
+
+ public Address(String street, String city) {
+ this();
+ this.street = street;
+ this.city = city;
+ }
+
+ private Address() {
+ places = new HashSet<Place>();
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ public String getStreet() {
+ return street;
+ }
+
+ public String getCity() {
+ return city;
+ }
+
+ public Set<Place> getPlaces() {
+ return places;
+ }
+
+ public void addPlace(Place place) {
+ places.add( place );
+ }
+
+ public void setStreet(String street) {
+ this.street = street;
+ }
+
+ public void setCity(String city) {
+ this.city = city;
+ }
+}
Property changes on: search/trunk/src/test/java/org/hibernate/search/test/embedded/nested/Address.java
___________________________________________________________________
Name: svn:keywords
+ Id
Added: search/trunk/src/test/java/org/hibernate/search/test/embedded/nested/Attribute.java
===================================================================
--- search/trunk/src/test/java/org/hibernate/search/test/embedded/nested/Attribute.java (rev 0)
+++ search/trunk/src/test/java/org/hibernate/search/test/embedded/nested/Attribute.java 2009-09-23 16:12:46 UTC (rev 17533)
@@ -0,0 +1,79 @@
+// $Id:$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+* http://www.apache.org/licenses/LICENSE-2.0
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.hibernate.search.test.embedded.nested;
+
+import java.util.ArrayList;
+import java.util.List;
+import javax.persistence.CascadeType;
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.ManyToOne;
+import javax.persistence.OneToMany;
+
+import org.hibernate.search.annotations.ContainedIn;
+import org.hibernate.search.annotations.IndexedEmbedded;
+
+/**
+ * @author Hardy Ferentschik
+ */
+@Entity
+public class Attribute {
+
+ @Id
+ @GeneratedValue
+ private long id;
+
+ @ManyToOne
+ @ContainedIn
+ private Product product;
+
+ @OneToMany(mappedBy = "attribute", fetch = FetchType.LAZY, cascade = { CascadeType.PERSIST, CascadeType.REMOVE })
+ @IndexedEmbedded
+ private List<AttributeValue> values;
+
+ private Attribute() {
+ values = new ArrayList<AttributeValue>();
+ }
+
+ public Attribute(Product product) {
+ this.product = product;
+ values = new ArrayList<AttributeValue>();
+ }
+
+ public long getId() {
+ return id;
+ }
+
+ public Product getProduct() {
+ return product;
+ }
+
+ public void setProduct(Product product) {
+ this.product = product;
+ }
+
+ public List<AttributeValue> getValues() {
+ return values;
+ }
+
+ public void setValue(AttributeValue value) {
+ values.add( value );
+ }
+}
Property changes on: search/trunk/src/test/java/org/hibernate/search/test/embedded/nested/Attribute.java
___________________________________________________________________
Name: svn:keywords
+ Id
Added: search/trunk/src/test/java/org/hibernate/search/test/embedded/nested/AttributeValue.java
===================================================================
--- search/trunk/src/test/java/org/hibernate/search/test/embedded/nested/AttributeValue.java (rev 0)
+++ search/trunk/src/test/java/org/hibernate/search/test/embedded/nested/AttributeValue.java 2009-09-23 16:12:46 UTC (rev 17533)
@@ -0,0 +1,77 @@
+// $Id:$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+* http://www.apache.org/licenses/LICENSE-2.0
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.hibernate.search.test.embedded.nested;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.ManyToOne;
+
+import org.hibernate.search.annotations.ContainedIn;
+import org.hibernate.search.annotations.Field;
+import org.hibernate.search.annotations.Index;
+import org.hibernate.search.annotations.Store;
+
+/**
+ * @author Hardy Ferentschik
+ */
+@Entity
+public class AttributeValue {
+
+ @Id
+ @GeneratedValue
+ private long id;
+
+ @ManyToOne(targetEntity = Attribute.class, fetch = FetchType.EAGER)
+ @ContainedIn
+ private Attribute attribute;
+
+ @Column(name = "_value")
+ @Field(index = Index.TOKENIZED, store = Store.YES)
+ private String value;
+
+ private AttributeValue() {
+ }
+
+ public AttributeValue(Attribute attribute, String value) {
+ this.attribute = attribute;
+ this.value = value;
+ }
+
+ public long getId() {
+ return id;
+ }
+
+ public String getValue() {
+ return value;
+ }
+
+ public void setValue(String value) {
+ this.value = value;
+ }
+
+ public Attribute getAttribute() {
+ return attribute;
+ }
+
+ public void setAttribute(Attribute attribute) {
+ this.attribute = attribute;
+ }
+}
\ No newline at end of file
Property changes on: search/trunk/src/test/java/org/hibernate/search/test/embedded/nested/AttributeValue.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied: search/trunk/src/test/java/org/hibernate/search/test/embedded/nested/NestedEmbeddedTest.java (from rev 17482, search/trunk/src/test/java/org/hibernate/search/test/embedded/EmbeddedTest.java)
===================================================================
--- search/trunk/src/test/java/org/hibernate/search/test/embedded/nested/NestedEmbeddedTest.java (rev 0)
+++ search/trunk/src/test/java/org/hibernate/search/test/embedded/nested/NestedEmbeddedTest.java 2009-09-23 16:12:46 UTC (rev 17533)
@@ -0,0 +1,138 @@
+//$Id$
+package org.hibernate.search.test.embedded.nested;
+
+import java.util.List;
+
+import org.apache.lucene.analysis.standard.StandardAnalyzer;
+import org.apache.lucene.queryParser.QueryParser;
+import org.apache.lucene.search.Query;
+
+import org.hibernate.Session;
+import org.hibernate.Transaction;
+import org.hibernate.search.FullTextSession;
+import org.hibernate.search.Search;
+import org.hibernate.search.test.SearchTestCase;
+
+
+/**
+ * @author Emmanuel Bernard
+ * @author Hardy Ferentschik
+ */
+public class NestedEmbeddedTest extends SearchTestCase {
+
+ /**
+ * HSEARCH-391
+ *
+ * @throws Exception in case the tests fails
+ */
+ public void testNestedEmbeddedIndexing() throws Exception {
+ Product product = new Product();
+ Attribute attribute = new Attribute( product );
+ product.setAttribute( attribute );
+ AttributeValue value = new AttributeValue( attribute, "foo" );
+ attribute.setValue( value );
+
+ Session s = openSession();
+ Transaction tx = s.beginTransaction();
+ s.persist( product );
+ tx.commit();
+
+ FullTextSession session = Search.getFullTextSession( s );
+ QueryParser parser = new QueryParser( "attributes.values.value", new StandardAnalyzer() );
+ Query query;
+ List<?> result;
+
+
+ query = parser.parse( "foo" );
+ result = session.createFullTextQuery( query ).list();
+ assertEquals( "unable to find property in attribute value", 1, result.size() );
+
+
+ s.clear();
+ tx = s.beginTransaction();
+
+ product = ( Product ) s.get( Product.class, product.getId() );
+ product.getAttributes().get( 0 ).getValues().get( 0 ).setValue( "bar" );
+ tx.commit();
+
+ s.clear();
+
+ session = Search.getFullTextSession( s );
+
+ query = parser.parse( "foo" );
+ result = session.createFullTextQuery( query, Product.class ).list();
+ assertEquals( "change in embedded not reflected in root index", 0, result.size() );
+
+ query = parser.parse( "bar" );
+ result = session.createFullTextQuery( query, Product.class ).list();
+ assertEquals( "change in embedded not reflected in root index", 1, result.size() );
+
+ s.close();
+ }
+
+
+ /**
+ * HSEARCH-391
+ *
+ * @throws Exception in case the tests fails
+ */
+ public void testNestedEmbeddedIndexingWithContainedInOnCollection() throws Exception {
+ Person john = new Person( "John Doe" );
+ Place eiffelTower = new Place( "Eiffel Tower" );
+ Address addressEiffel = new Address( "Avenue Gustave Eiffel", "London" );
+ addressEiffel.addPlace( eiffelTower );
+ eiffelTower.setAddress( addressEiffel );
+ john.addPlaceVisited( eiffelTower );
+ eiffelTower.visitedBy( john );
+
+
+ Session s = openSession();
+ Transaction tx = s.beginTransaction();
+ s.persist( john );
+ tx.commit();
+
+ FullTextSession session = Search.getFullTextSession( s );
+ QueryParser parser = new QueryParser( "placesVisited.address.city", new StandardAnalyzer() );
+ Query query;
+ List<?> result;
+
+
+ query = parser.parse( "London" );
+ result = session.createFullTextQuery( query ).list();
+ assertEquals( "unable to find nested indexed value", 1, result.size() );
+
+
+ s.clear();
+ tx = s.beginTransaction();
+
+ john = ( Person ) s.get( Person.class, john.getId() );
+ john.getPlacesVisited().get( 0 ).getAddress().setCity( "Paris" );
+ tx.commit();
+
+ s.clear();
+
+ john = ( Person ) s.get( Person.class, john.getId() );
+
+ session = Search.getFullTextSession( s );
+
+ query = parser.parse( "London" );
+ result = session.createFullTextQuery( query, Person.class ).list();
+ assertEquals( "change in embedded not reflected in root index", 0, result.size() );
+
+ query = parser.parse( "Paris" );
+ result = session.createFullTextQuery( query, Person.class ).list();
+ assertEquals( "change in embedded not reflected in root index", 1, result.size() );
+
+ s.close();
+ }
+
+ protected void configure(org.hibernate.cfg.Configuration cfg) {
+ super.configure( cfg );
+ }
+
+ protected Class<?>[] getMappings() {
+ return new Class[] {
+ Product.class, Attribute.class, AttributeValue.class, Person.class, Place.class, Address.class
+ };
+ }
+}
\ No newline at end of file
Added: search/trunk/src/test/java/org/hibernate/search/test/embedded/nested/Person.java
===================================================================
--- search/trunk/src/test/java/org/hibernate/search/test/embedded/nested/Person.java (rev 0)
+++ search/trunk/src/test/java/org/hibernate/search/test/embedded/nested/Person.java 2009-09-23 16:12:46 UTC (rev 17533)
@@ -0,0 +1,71 @@
+// $Id:$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+* http://www.apache.org/licenses/LICENSE-2.0
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.hibernate.search.test.embedded.nested;
+
+import java.util.ArrayList;
+import java.util.List;
+import javax.persistence.CascadeType;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.ManyToMany;
+
+import org.hibernate.search.annotations.Indexed;
+import org.hibernate.search.annotations.IndexedEmbedded;
+
+/**
+ * @author Hardy Ferentschik
+ */
+@Entity
+@Indexed
+public class Person {
+ @Id
+ @GeneratedValue
+ private long id;
+
+ String name;
+
+ @IndexedEmbedded
+ @ManyToMany(cascade = { CascadeType.ALL })
+ private List<Place> placesVisited;
+
+ private Person() {
+ placesVisited = new ArrayList<Place>( 0 );
+ }
+
+ public Person(String name) {
+ this();
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public List<Place> getPlacesVisited() {
+ return placesVisited;
+ }
+
+ public void addPlaceVisited(Place place) {
+ placesVisited.add( place );
+ }
+
+ public long getId() {
+ return id;
+ }
+}
Property changes on: search/trunk/src/test/java/org/hibernate/search/test/embedded/nested/Person.java
___________________________________________________________________
Name: svn:keywords
+ Id
Added: search/trunk/src/test/java/org/hibernate/search/test/embedded/nested/Place.java
===================================================================
--- search/trunk/src/test/java/org/hibernate/search/test/embedded/nested/Place.java (rev 0)
+++ search/trunk/src/test/java/org/hibernate/search/test/embedded/nested/Place.java 2009-09-23 16:12:46 UTC (rev 17533)
@@ -0,0 +1,87 @@
+// $Id:$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+* http://www.apache.org/licenses/LICENSE-2.0
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.hibernate.search.test.embedded.nested;
+
+import java.util.HashSet;
+import java.util.Set;
+import javax.persistence.CascadeType;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.ManyToMany;
+import javax.persistence.OneToOne;
+
+import org.hibernate.search.annotations.ContainedIn;
+import org.hibernate.search.annotations.Field;
+import org.hibernate.search.annotations.Index;
+import org.hibernate.search.annotations.IndexedEmbedded;
+
+/**
+ * @author Hardy Ferentschik
+ */
+@Entity
+public class Place {
+ @Id
+ @GeneratedValue
+ private Long id;
+
+ @Field(index = Index.TOKENIZED)
+ private String name;
+
+ @OneToOne(cascade = { CascadeType.PERSIST, CascadeType.REMOVE })
+ @IndexedEmbedded
+ private Address address;
+
+ @ContainedIn
+ @ManyToMany(cascade = { CascadeType.ALL }, mappedBy = "placesVisited")
+ private Set<Person> visitedBy;
+
+ private Place() {
+ this.visitedBy = new HashSet<Person>();
+ }
+
+ public Place(String name) {
+ this();
+ this.name = name;
+ }
+
+ public Address getAddress() {
+ return address;
+ }
+
+ public String getName() {
+
+ return name;
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setAddress(Address address) {
+ this.address = address;
+ }
+
+ public void visitedBy(Person person) {
+ visitedBy.add( person );
+ }
+
+ public Set<Person> getVisitedBy() {
+ return visitedBy;
+ }
+}
Property changes on: search/trunk/src/test/java/org/hibernate/search/test/embedded/nested/Place.java
___________________________________________________________________
Name: svn:keywords
+ Id
Added: search/trunk/src/test/java/org/hibernate/search/test/embedded/nested/Product.java
===================================================================
--- search/trunk/src/test/java/org/hibernate/search/test/embedded/nested/Product.java (rev 0)
+++ search/trunk/src/test/java/org/hibernate/search/test/embedded/nested/Product.java 2009-09-23 16:12:46 UTC (rev 17533)
@@ -0,0 +1,61 @@
+// $Id:$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+* http://www.apache.org/licenses/LICENSE-2.0
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.hibernate.search.test.embedded.nested;
+
+import java.util.ArrayList;
+import java.util.List;
+import javax.persistence.CascadeType;
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.OneToMany;
+
+import org.hibernate.search.annotations.Indexed;
+import org.hibernate.search.annotations.IndexedEmbedded;
+
+/**
+ * @author Hardy Ferentschik
+ */
+@Entity
+@Indexed
+public class Product {
+ @Id
+ @GeneratedValue
+ private long id;
+
+ @OneToMany(mappedBy = "product", fetch = FetchType.LAZY, cascade = { CascadeType.PERSIST, CascadeType.REMOVE })
+ @IndexedEmbedded
+ private List<Attribute> attributes;
+
+ public Product() {
+ attributes = new ArrayList<Attribute>();
+ }
+
+ public long getId() {
+ return id;
+ }
+
+ public List<Attribute> getAttributes() {
+ return attributes;
+ }
+
+ public void setAttribute(Attribute attribute) {
+ attributes.add( attribute );
+ }
+}
Property changes on: search/trunk/src/test/java/org/hibernate/search/test/embedded/nested/Product.java
___________________________________________________________________
Name: svn:keywords
+ Id
16 years
Hibernate SVN: r17532 - validator/trunk/hibernate-validator/src/main/docbook/en-US/modules.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2009-09-23 06:21:55 -0400 (Wed, 23 Sep 2009)
New Revision: 17532
Modified:
validator/trunk/hibernate-validator/src/main/docbook/en-US/modules/customconstraints.xml
validator/trunk/hibernate-validator/src/main/docbook/en-US/modules/usingvalidator.xml
Log:
HV-220 custom constrains changes from Gunnar
Modified: validator/trunk/hibernate-validator/src/main/docbook/en-US/modules/customconstraints.xml
===================================================================
--- validator/trunk/hibernate-validator/src/main/docbook/en-US/modules/customconstraints.xml 2009-09-22 17:43:48 UTC (rev 17531)
+++ validator/trunk/hibernate-validator/src/main/docbook/en-US/modules/customconstraints.xml 2009-09-23 10:21:55 UTC (rev 17532)
@@ -94,6 +94,7 @@
import java.lang.annotation.Target;
import javax.validation.Constraint;
+import javax.validation.ConstraintPayload;
@Target( { METHOD, FIELD, ANNOTATION_TYPE })
@Retention(RUNTIME)
@@ -101,9 +102,11 @@
@Documented
public @interface CheckCase {
- String message() default "{validator.checkcase}";
+ String message() default "{com.mycompany.constraints.checkcase}";
Class<?>[] groups() default {};
+
+ Class<? extends Payload>[] payload() default {};
CaseMode value();
@@ -127,11 +130,17 @@
default to an empty array of type
<classname>Class<?></classname>.</para>
</listitem>
+
+ <listitem>
+ <para>an attribute "payload" that can be used by clients of the Bean
+ Validation API to asign custom payload objects to a constraint. This
+ attribute is not used by the API itself.</para>
+ </listitem>
</itemizedlist>
- <para>Besides those two mandatory attributes we add another one allowing
- for the required case mode to be specified. The name "value" is a
- special one, which can be omitted upon using the annotation, if it is
+ <para>Besides those three mandatory attributes we add another one
+ allowing for the required case mode to be specified. The name "value" is
+ a special one, which can be omitted upon using the annotation, if it is
the only attribute specified, as e.g. in
<code>@CheckCase(CaseMode.UPPER)</code>.</para>
@@ -227,8 +236,7 @@
<para>The passed-in <classname>ConstraintValidatorContext</classname>
could be used to raise any custom validation errors, but as we are fine
- with the default behavior, we can ignore that parameter for now (TODO
- GM: example for usage).</para>
+ with the default behavior, we can ignore that parameter for now.</para>
</section>
<section id="validator-customconstraints-errormessage" revision="1">
@@ -241,7 +249,7 @@
<filename>src/main/resources</filename> with the following
content:</para>
- <programlisting>validator.checkcase=Case mode must be {value}.</programlisting>
+ <programlisting>com.mycompany.constraints.checkcase=Case mode must be {value}.</programlisting>
<para>If a validation error occurs, the validation runtime will use the
default value, that we specified for the message attribute of the
@@ -370,6 +378,7 @@
import java.lang.annotation.Target;
import javax.validation.Constraint;
+import javax.validation.ConstraintPayload;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
@@ -382,10 +391,12 @@
@Documented
public @interface ValidLicensePlate {
- String message() default "{validator.validlicenseplate}";
+ String message() default "{com.mycompany.constraints.validlicenseplate}";
Class<?>[] groups() default {};
+ Class<? extends Payload>[] payload() default {};
+
}</programlisting>
<para>To do so, we just have to annotate the constraint declaration with
@@ -396,8 +407,6 @@
declare a validator within the <classname>@Constraint </classname>meta
annotation.</para>
- <para>TODO GM: Specifying no validator does not yet work.</para>
-
<para>Using the new compound constraint at the
<property>licensePlate</property> field now is fully equivalent to the
previous version, where we declared the three constraints directly at the
@@ -427,10 +436,12 @@
@ReportAsSingleViolation
public @interface ValidLicensePlate {
- String message() default "{validator.validlicenseplate}";
+ String message() default "{com.mycompany.constraints.validlicenseplate}";
Class<?>[] groups() default {};
+ Class<? extends Payload>[] payload() default {};
+
}</programlisting>
</section>
</chapter>
Modified: validator/trunk/hibernate-validator/src/main/docbook/en-US/modules/usingvalidator.xml
===================================================================
--- validator/trunk/hibernate-validator/src/main/docbook/en-US/modules/usingvalidator.xml 2009-09-22 17:43:48 UTC (rev 17531)
+++ validator/trunk/hibernate-validator/src/main/docbook/en-US/modules/usingvalidator.xml 2009-09-23 10:21:55 UTC (rev 17532)
@@ -261,7 +261,7 @@
<property>rentalStation</property> is validated, but also the constraint
on <property>manufacturer</property> from the parent class.</para>
- <para>The same would holds true, if <classname>Car</classname> were an
+ <para>The same would hold true, if <classname>Car</classname> were an
interface implemented by <classname>RentalCar</classname>.</para>
<para>Constraint annotations are aggregated if methods are overridden.
@@ -372,12 +372,8 @@
import java.util.List;
import javax.validation.Valid;
-import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
-import javax.validation.constraints.Size;
-import org.hibernate.validator.constraints.NotEmpty;
-
public class Car {
@NotNull
16 years
Hibernate SVN: r17531 - in core/trunk/annotations/src: test/java/org/hibernate/test/annotations/entity and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2009-09-22 13:43:48 -0400 (Tue, 22 Sep 2009)
New Revision: 17531
Added:
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/entity/FirstName.java
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/entity/LastName.java
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/entity/Name.java
Modified:
core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationBinder.java
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/entity/BasicHibernateAnnotationsTest.java
Log:
HHH-4232 TypeDef support when used on @Embeddable or @MappedSuperClass classes
Modified: core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationBinder.java
===================================================================
--- core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationBinder.java 2009-09-22 17:19:24 UTC (rev 17530)
+++ core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationBinder.java 2009-09-22 17:43:48 UTC (rev 17531)
@@ -429,12 +429,13 @@
//TODO: be more strict with secondarytable allowance (not for ids, not for secondary table join columns etc)
InheritanceState inheritanceState = inheritanceStatePerClass.get( clazzToProcess );
AnnotatedClassType classType = mappings.getClassType( clazzToProcess );
-
+
//Queries declared in MappedSuperclass should be usable in Subclasses
- if ( AnnotatedClassType.EMBEDDABLE_SUPERCLASS.equals( classType )) {
- bindQueries(clazzToProcess, mappings );
+ if ( AnnotatedClassType.EMBEDDABLE_SUPERCLASS.equals( classType ) ) {
+ bindQueries( clazzToProcess, mappings );
+ bindTypeDefs(clazzToProcess, mappings);
}
-
+
if ( AnnotatedClassType.EMBEDDABLE_SUPERCLASS.equals( classType ) //will be processed by their subentities
|| AnnotatedClassType.NONE.equals( classType ) //to be ignored
|| AnnotatedClassType.EMBEDDABLE.equals( classType ) //allow embeddable element declaration
@@ -1942,6 +1943,9 @@
);
List<PropertyData> classElements = new ArrayList<PropertyData>();
XClass returnedClassOrElement = inferredData.getClassOrElement();
+
+ //embeddable elements can have type defs
+ bindTypeDefs(returnedClassOrElement, mappings);
addElementsOfAClass(
classElements,
subHolder,
Modified: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/entity/BasicHibernateAnnotationsTest.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/entity/BasicHibernateAnnotationsTest.java 2009-09-22 17:19:24 UTC (rev 17530)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/entity/BasicHibernateAnnotationsTest.java 2009-09-22 17:43:48 UTC (rev 17531)
@@ -143,6 +143,33 @@
}
+ //Test import of TypeDefs from MappedSuperclass and
+ //Embedded classes
+ public void testImportTypeDefinitions() throws Exception {
+ Name name = new Name();
+ name.setFirstName("SHARATH");
+ LastName lastName = new LastName();
+ lastName.setName("reddy");
+ name.setLastName(lastName);
+ Session s;
+ Transaction tx;
+ s = openSession();
+ tx = s.beginTransaction();
+ s.persist(name);
+ tx.commit();
+ s.close();
+
+ s = openSession();
+ tx = s.beginTransaction();
+ name = (Name) s.get( Name.class, name.getId() );
+ assertNotNull( name );
+ assertEquals( "sharath", name.getFirstName() );
+ assertEquals( "REDDY", name.getLastName().getName() );
+ s.delete(name);
+ tx.commit();
+ s.close();
+ }
+
public void testNonLazy() throws Exception {
Session s;
Transaction tx;
@@ -325,7 +352,8 @@
Tree.class,
Ransom.class,
ZipCode.class,
- Flight.class
+ Flight.class,
+ Name.class
};
}
Added: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/entity/FirstName.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/entity/FirstName.java (rev 0)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/entity/FirstName.java 2009-09-22 17:43:48 UTC (rev 17531)
@@ -0,0 +1,33 @@
+package org.hibernate.test.annotations.entity;
+
+import javax.persistence.MappedSuperclass;
+
+import org.hibernate.annotations.Type;
+import org.hibernate.annotations.TypeDef;
+import org.hibernate.annotations.Parameter;
+
+
+@TypeDef(
+ name = "lowerCase",
+ typeClass = CasterStringType.class,
+ parameters = {
+ @Parameter(name = "cast", value = "lower")
+ }
+)
+
+@MappedSuperclass
+public class FirstName {
+
+ @Type(type="lowerCase")
+ private String firstName;
+
+ public String getFirstName() {
+ return firstName;
+ }
+
+ public void setFirstName(String lowerCaseName) {
+ this.firstName = lowerCaseName;
+ }
+
+
+}
Added: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/entity/LastName.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/entity/LastName.java (rev 0)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/entity/LastName.java 2009-09-22 17:43:48 UTC (rev 17531)
@@ -0,0 +1,33 @@
+package org.hibernate.test.annotations.entity;
+
+import javax.persistence.Embeddable;
+
+import org.hibernate.annotations.Parameter;
+import org.hibernate.annotations.Type;
+import org.hibernate.annotations.TypeDef;
+
+
+@TypeDef(
+ name = "upperCase",
+ typeClass = CasterStringType.class,
+ parameters = {
+ @Parameter(name = "cast", value = "upper")
+ }
+)
+
+@Embeddable
+public class LastName {
+
+ @Type(type="upperCase")
+ private String lastName;
+
+ public String getName() {
+ return lastName;
+ }
+
+ public void setName(String lowerCaseName) {
+ this.lastName = lowerCaseName;
+ }
+
+
+}
Added: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/entity/Name.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/entity/Name.java (rev 0)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/entity/Name.java 2009-09-22 17:43:48 UTC (rev 17531)
@@ -0,0 +1,35 @@
+package org.hibernate.test.annotations.entity;
+
+import javax.persistence.Embedded;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.Transient;
+
+@Entity
+public class Name extends FirstName {
+
+ @Id
+ @GeneratedValue
+ private Integer id;
+
+ @Embedded
+ private LastName lastName;
+
+ public Integer getId() {
+ return id;
+ }
+
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ public LastName getLastName() {
+ return lastName;
+ }
+
+ public void setLastName(LastName val) {
+ this.lastName = val;
+ }
+
+}
16 years
Hibernate SVN: r17530 - in core/trunk/annotations/src: test/java/org/hibernate/test/annotations/query and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2009-09-22 13:19:24 -0400 (Tue, 22 Sep 2009)
New Revision: 17530
Added:
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/query/Darkness.java
Modified:
core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationBinder.java
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/query/Night.java
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/query/QueryAndSQLTest.java
Log:
HHH-4364 support @NamedQuery on a @MappedSuperclass (Sharath Reddy)
Modified: core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationBinder.java
===================================================================
--- core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationBinder.java 2009-09-19 19:59:46 UTC (rev 17529)
+++ core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationBinder.java 2009-09-22 17:19:24 UTC (rev 17530)
@@ -429,6 +429,12 @@
//TODO: be more strict with secondarytable allowance (not for ids, not for secondary table join columns etc)
InheritanceState inheritanceState = inheritanceStatePerClass.get( clazzToProcess );
AnnotatedClassType classType = mappings.getClassType( clazzToProcess );
+
+ //Queries declared in MappedSuperclass should be usable in Subclasses
+ if ( AnnotatedClassType.EMBEDDABLE_SUPERCLASS.equals( classType )) {
+ bindQueries(clazzToProcess, mappings );
+ }
+
if ( AnnotatedClassType.EMBEDDABLE_SUPERCLASS.equals( classType ) //will be processed by their subentities
|| AnnotatedClassType.NONE.equals( classType ) //to be ignored
|| AnnotatedClassType.EMBEDDABLE.equals( classType ) //allow embeddable element declaration
Added: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/query/Darkness.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/query/Darkness.java (rev 0)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/query/Darkness.java 2009-09-22 17:19:24 UTC (rev 17530)
@@ -0,0 +1,13 @@
+package org.hibernate.test.annotations.query;
+
+import javax.persistence.MappedSuperclass;
+
+(a)org.hibernate.annotations.NamedQuery(
+ name = "night.olderThan",
+ query = "select n from Night n where n.date <= :date"
+)
+
+@MappedSuperclass
+public class Darkness {
+
+}
Modified: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/query/Night.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/query/Night.java 2009-09-19 19:59:46 UTC (rev 17529)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/query/Night.java 2009-09-22 17:19:24 UTC (rev 17530)
@@ -21,7 +21,7 @@
query = "select n from Night n where n.duration = :duration",
cacheable = true, cacheRegion = "nightQuery"
)
-public class Night {
+public class Night extends Darkness {
private Integer id;
private long duration;
private Date date;
Modified: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/query/QueryAndSQLTest.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/query/QueryAndSQLTest.java 2009-09-19 19:59:46 UTC (rev 17529)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/query/QueryAndSQLTest.java 2009-09-22 17:19:24 UTC (rev 17530)
@@ -6,6 +6,7 @@
import java.util.GregorianCalendar;
import java.util.List;
+import org.hibernate.MappingException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
@@ -110,6 +111,17 @@
s.close();
}
+ public void testImportQueryFromMappedSuperclass() {
+ Session s = openSession();
+ try {
+ s.getNamedQuery( "night.olderThan" );
+ }
+ catch(MappingException ex) {
+ assertTrue("Query imported from MappedSuperclass", false);
+ }
+ s.close();
+ }
+
public void testSQLQueryWithManyToOne() {
Night n = new Night();
Calendar c = new GregorianCalendar();
16 years
Hibernate SVN: r17529 - in annotations/branches/v3_4_0_GA_CP/src/test/org/hibernate/test/annotations: manytoone and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: stliu
Date: 2009-09-19 15:59:46 -0400 (Sat, 19 Sep 2009)
New Revision: 17529
Modified:
annotations/branches/v3_4_0_GA_CP/src/test/org/hibernate/test/annotations/manytomany/Company.java
annotations/branches/v3_4_0_GA_CP/src/test/org/hibernate/test/annotations/manytomany/Group.java
annotations/branches/v3_4_0_GA_CP/src/test/org/hibernate/test/annotations/manytomany/GroupWithSet.java
annotations/branches/v3_4_0_GA_CP/src/test/org/hibernate/test/annotations/manytomany/ManyToManyTest.java
annotations/branches/v3_4_0_GA_CP/src/test/org/hibernate/test/annotations/manytoone/Frame.java
annotations/branches/v3_4_0_GA_CP/src/test/org/hibernate/test/annotations/manytoone/ManyToOneTest.java
annotations/branches/v3_4_0_GA_CP/src/test/org/hibernate/test/annotations/manytoone/Order.java
Log:
JBPAPP-2789 CLONE -Annotations - Oracle/Sybase - Unique/Primary Key declared twice raises an error
Modified: annotations/branches/v3_4_0_GA_CP/src/test/org/hibernate/test/annotations/manytomany/Company.java
===================================================================
--- annotations/branches/v3_4_0_GA_CP/src/test/org/hibernate/test/annotations/manytomany/Company.java 2009-09-19 19:24:40 UTC (rev 17528)
+++ annotations/branches/v3_4_0_GA_CP/src/test/org/hibernate/test/annotations/manytomany/Company.java 2009-09-19 19:59:46 UTC (rev 17529)
@@ -10,7 +10,7 @@
*/
@MappedSuperclass
public class Company implements Serializable {
- @Column(unique = true) private String name;
+ @Column private String name;
public String getName() {
return name;
Modified: annotations/branches/v3_4_0_GA_CP/src/test/org/hibernate/test/annotations/manytomany/Group.java
===================================================================
--- annotations/branches/v3_4_0_GA_CP/src/test/org/hibernate/test/annotations/manytomany/Group.java 2009-09-19 19:24:40 UTC (rev 17528)
+++ annotations/branches/v3_4_0_GA_CP/src/test/org/hibernate/test/annotations/manytomany/Group.java 2009-09-19 19:59:46 UTC (rev 17529)
@@ -5,12 +5,9 @@
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.Id;
-import javax.persistence.JoinColumn;
-import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;
-import javax.persistence.UniqueConstraint;
import org.hibernate.annotations.Where;
import org.hibernate.annotations.FilterDef;
@@ -38,11 +35,6 @@
}
@ManyToMany(cascade = CascadeType.PERSIST)
- @JoinTable(name = "GROUPS_PERMISSIONS",
- uniqueConstraints = @UniqueConstraint(columnNames = {"group_id", "permission"}),
- joinColumns = @JoinColumn(name = "group_id", referencedColumnName = "id"),
- inverseJoinColumns = @JoinColumn(name = "permission", referencedColumnName = "permission")
- )
@OrderBy("expirationDate")
@Where(clause = "1=1")
@WhereJoinTable(clause = "2=2")
Modified: annotations/branches/v3_4_0_GA_CP/src/test/org/hibernate/test/annotations/manytomany/GroupWithSet.java
===================================================================
--- annotations/branches/v3_4_0_GA_CP/src/test/org/hibernate/test/annotations/manytomany/GroupWithSet.java 2009-09-19 19:24:40 UTC (rev 17528)
+++ annotations/branches/v3_4_0_GA_CP/src/test/org/hibernate/test/annotations/manytomany/GroupWithSet.java 2009-09-19 19:59:46 UTC (rev 17529)
@@ -40,11 +40,6 @@
}
@ManyToMany(cascade = CascadeType.PERSIST)
- @JoinTable(name = "GROUPS_PERMISSIONS",
- uniqueConstraints = @UniqueConstraint(columnNames = {"group_id", "permission"}),
- joinColumns = @JoinColumn(name = "group_id", referencedColumnName = "id"),
- inverseJoinColumns = @JoinColumn(name = "permission", referencedColumnName = "permission")
- )
@OrderBy("expirationDate")
@Where(clause = "1=1")
@WhereJoinTable(clause = "2=2")
Modified: annotations/branches/v3_4_0_GA_CP/src/test/org/hibernate/test/annotations/manytomany/ManyToManyTest.java
===================================================================
--- annotations/branches/v3_4_0_GA_CP/src/test/org/hibernate/test/annotations/manytomany/ManyToManyTest.java 2009-09-19 19:24:40 UTC (rev 17528)
+++ annotations/branches/v3_4_0_GA_CP/src/test/org/hibernate/test/annotations/manytomany/ManyToManyTest.java 2009-09-19 19:59:46 UTC (rev 17529)
@@ -7,15 +7,12 @@
import java.util.Date;
import java.util.HashSet;
import java.util.Iterator;
-import java.util.List;
import java.util.Set;
import org.hibernate.Hibernate;
import org.hibernate.JDBCException;
import org.hibernate.Session;
import org.hibernate.Transaction;
-import org.hibernate.dialect.HSQLDialect;
-import org.hibernate.test.annotations.RequiresDialect;
import org.hibernate.test.annotations.TestCase;
/**
@@ -81,7 +78,6 @@
s.close();
}
- @RequiresDialect(HSQLDialect.class)
public void testDefaultCompositePk() throws Exception {
Session s;
Transaction tx;
@@ -265,7 +261,8 @@
*
* @throws Exception in case the test fails.
*
- * This fails test fails for other databases (except HSQL) due to missing alias in order by clause:
+ * This test only works against databases which allow a mixed usage of
+ * table names and table aliases. The generated SQL for this test is:
*
* select
* contractor0_.EMPLOYER_ID as EMPLOYER1_1_,
@@ -285,54 +282,54 @@
*
*
*/
- @RequiresDialect(HSQLDialect.class)
- public void testOrderByContractor() throws Exception {
-
- Session s;
- Transaction tx;
- s = openSession();
- tx = s.beginTransaction();
-
- // create some test entities
- Employer employer = new Employer();
- Contractor contractor1 = new Contractor();
- contractor1.setName( "Emmanuel" );
- contractor1.setHourlyRate(100.0f);
- Contractor contractor2 = new Contractor();
- contractor2.setName( "Hardy" );
- contractor2.setHourlyRate(99.99f);
- s.persist( contractor1 );
- s.persist( contractor2 );
-
- // add contractors to employer
- List setOfContractors = new ArrayList();
- setOfContractors.add( contractor1 );
- setOfContractors.add( contractor2 );
- employer.setContractors( setOfContractors );
-
- // add employer to contractors
- Collection employerListContractor1 = new ArrayList();
- employerListContractor1.add( employer );
- contractor1.setEmployers( employerListContractor1 );
-
- Collection employerListContractor2 = new ArrayList();
- employerListContractor2.add( employer );
- contractor2.setEmployers( employerListContractor2 );
+// HHH-3577
+// public void testOrderByContractor() throws Exception {
+//
+// Session s;
+// Transaction tx;
+// s = openSession();
+// tx = s.beginTransaction();
+//
+// // create some test entities
+// Employer employer = new Employer();
+// Contractor contractor1 = new Contractor();
+// contractor1.setName( "Emmanuel" );
+// contractor1.setHourlyRate(100.0f);
+// Contractor contractor2 = new Contractor();
+// contractor2.setName( "Hardy" );
+// contractor2.setHourlyRate(99.99f);
+// s.persist( contractor1 );
+// s.persist( contractor2 );
+//
+// // add contractors to employer
+// List setOfContractors = new ArrayList();
+// setOfContractors.add( contractor1 );
+// setOfContractors.add( contractor2 );
+// employer.setContractors( setOfContractors );
+//
+// // add employer to contractors
+// Collection employerListContractor1 = new ArrayList();
+// employerListContractor1.add( employer );
+// contractor1.setEmployers( employerListContractor1 );
+//
+// Collection employerListContractor2 = new ArrayList();
+// employerListContractor2.add( employer );
+// contractor2.setEmployers( employerListContractor2 );
+//
+// s.flush();
+// s.clear();
+//
+// // assertions
+// employer = (Employer) s.get( Employer.class, employer.getId() );
+// assertNotNull( employer );
+// assertNotNull( employer.getContractors() );
+// assertEquals( 2, employer.getContractors().size() );
+// Contractor firstContractorFromDb = (Contractor) employer.getContractors().iterator().next();
+// assertEquals( contractor2.getName(), firstContractorFromDb.getName() );
+// tx.rollback();
+// s.close();
+// }
- s.flush();
- s.clear();
-
- // assertions
- employer = (Employer) s.get( Employer.class, employer.getId() );
- assertNotNull( employer );
- assertNotNull( employer.getContractors() );
- assertEquals( 2, employer.getContractors().size() );
- Contractor firstContractorFromDb = (Contractor) employer.getContractors().iterator().next();
- assertEquals( contractor2.getName(), firstContractorFromDb.getName() );
- tx.rollback();
- s.close();
- }
-
public void testRemoveInBetween() throws Exception {
Session s;
Transaction tx;
@@ -423,7 +420,6 @@
s.close();
}
- @RequiresDialect(HSQLDialect.class)
public void testCompositePk() throws Exception {
Session s;
Transaction tx;
Modified: annotations/branches/v3_4_0_GA_CP/src/test/org/hibernate/test/annotations/manytoone/Frame.java
===================================================================
--- annotations/branches/v3_4_0_GA_CP/src/test/org/hibernate/test/annotations/manytoone/Frame.java 2009-09-19 19:24:40 UTC (rev 17528)
+++ annotations/branches/v3_4_0_GA_CP/src/test/org/hibernate/test/annotations/manytoone/Frame.java 2009-09-19 19:59:46 UTC (rev 17529)
@@ -21,7 +21,6 @@
private Long id;
@OneToMany( mappedBy = "frame" )
private Set<Lens> lenses;
- @Column( unique = true )
private String name;
@Formula("lower(name)")
private String lowerName;
Modified: annotations/branches/v3_4_0_GA_CP/src/test/org/hibernate/test/annotations/manytoone/ManyToOneTest.java
===================================================================
--- annotations/branches/v3_4_0_GA_CP/src/test/org/hibernate/test/annotations/manytoone/ManyToOneTest.java 2009-09-19 19:24:40 UTC (rev 17528)
+++ annotations/branches/v3_4_0_GA_CP/src/test/org/hibernate/test/annotations/manytoone/ManyToOneTest.java 2009-09-19 19:59:46 UTC (rev 17529)
@@ -249,10 +249,6 @@
s.close();
}
- public void testManyToOneAndIdClass() throws Exception {
-
- }
-
public void testManyToOneNonPk() throws Exception {
Session s = openSession();
Transaction tx = s.beginTransaction();
Modified: annotations/branches/v3_4_0_GA_CP/src/test/org/hibernate/test/annotations/manytoone/Order.java
===================================================================
--- annotations/branches/v3_4_0_GA_CP/src/test/org/hibernate/test/annotations/manytoone/Order.java 2009-09-19 19:24:40 UTC (rev 17528)
+++ annotations/branches/v3_4_0_GA_CP/src/test/org/hibernate/test/annotations/manytoone/Order.java 2009-09-19 19:59:46 UTC (rev 17529)
@@ -30,7 +30,7 @@
this.id = id;
}
- @Column(name="order_nbr", unique = true)
+ @Column(name="order_nbr")
public String getOrderNbr() {
return orderNbr;
}
16 years