Hibernate SVN: r10539 - trunk/Hibernate3/src/org/hibernate/dialect
by hibernate-commits@lists.jboss.org
Author: scottmarlownovell
Date: 2006-09-29 22:49:47 -0400 (Fri, 29 Sep 2006)
New Revision: 10539
Added:
trunk/Hibernate3/src/org/hibernate/dialect/MySQL5InnoDBDialect.java
Log:
Added dialect for MySQL 5 InnoDB engine, this addresses HHH-1891.
Added: trunk/Hibernate3/src/org/hibernate/dialect/MySQL5InnoDBDialect.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/dialect/MySQL5InnoDBDialect.java 2006-09-29 19:26:00 UTC (rev 10538)
+++ trunk/Hibernate3/src/org/hibernate/dialect/MySQL5InnoDBDialect.java 2006-09-30 02:49:47 UTC (rev 10539)
@@ -0,0 +1,21 @@
+//$Id: $
+package org.hibernate.dialect;
+
+/**
+ * @author Gavin King, Scott Marlow
+ */
+public class MySQL5InnoDBDialect extends MySQL5Dialect {
+
+ public boolean supportsCascadeDelete() {
+ return true;
+ }
+
+ public String getTableTypeString() {
+ return " ENGINE=InnoDB";
+ }
+
+ public boolean hasSelfReferentialForeignKeyBug() {
+ return true;
+ }
+
+}
Property changes on: trunk/Hibernate3/src/org/hibernate/dialect/MySQL5InnoDBDialect.java
___________________________________________________________________
Name: svn:executable
+ *
18 years, 2 months
Hibernate SVN: r10538 - trunk/HibernateExt/ejb/src/java/org/hibernate/ejb
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2006-09-29 15:26:00 -0400 (Fri, 29 Sep 2006)
New Revision: 10538
Modified:
trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/AbstractEntityManagerImpl.java
Log:
EJB-231
Modified: trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/AbstractEntityManagerImpl.java
===================================================================
--- trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/AbstractEntityManagerImpl.java 2006-09-29 19:18:26 UTC (rev 10537)
+++ trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/AbstractEntityManagerImpl.java 2006-09-29 19:26:00 UTC (rev 10538)
@@ -598,10 +598,16 @@
if ( e instanceof StaleStateException ) {
if ( e instanceof StaleObjectStateException ) {
StaleObjectStateException sose = (StaleObjectStateException) e;
- Object entity = getRawSession().load( sose.getEntityName(), sose.getIdentifier() );
- if ( entity instanceof Serializable ) {
- //avoid some user errors regarding boundary crossing
- throwPersistenceException( new OptimisticLockException( null, e, entity ) );
+ Serializable identifier = sose.getIdentifier();
+ if (identifier != null) {
+ Object entity = getRawSession().load( sose.getEntityName(), identifier );
+ if ( entity instanceof Serializable ) {
+ //avoid some user errors regarding boundary crossing
+ throwPersistenceException( new OptimisticLockException( null, e, entity ) );
+ }
+ else {
+ throwPersistenceException( new OptimisticLockException( e ) );
+ }
}
else {
throwPersistenceException( new OptimisticLockException( e ) );
18 years, 2 months
Hibernate SVN: r10537 - in trunk/HibernateExt/metadata/src/java/org/hibernate: annotationfactory cfg cfg/annotations lucene lucene/event reflection/java type validator validator/event
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2006-09-29 15:18:26 -0400 (Fri, 29 Sep 2006)
New Revision: 10537
Modified:
trunk/HibernateExt/metadata/src/java/org/hibernate/annotationfactory/AnnotationFactory.java
trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/AbstractPropertyHolder.java
trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/AnnotationBinder.java
trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/AnnotationConfiguration.java
trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/BinderHelper.java
trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/CollectionBinder.java
trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/MapBinder.java
trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/Version.java
trunk/HibernateExt/metadata/src/java/org/hibernate/lucene/DocumentBuilder.java
trunk/HibernateExt/metadata/src/java/org/hibernate/lucene/event/LuceneEventListener.java
trunk/HibernateExt/metadata/src/java/org/hibernate/reflection/java/EJB3OverridenAnnotationReader.java
trunk/HibernateExt/metadata/src/java/org/hibernate/reflection/java/JavaXFactory.java
trunk/HibernateExt/metadata/src/java/org/hibernate/reflection/java/Pair.java
trunk/HibernateExt/metadata/src/java/org/hibernate/type/ByteArrayBlobType.java
trunk/HibernateExt/metadata/src/java/org/hibernate/type/CharacterArrayClobType.java
trunk/HibernateExt/metadata/src/java/org/hibernate/type/EnumType.java
trunk/HibernateExt/metadata/src/java/org/hibernate/validator/Environment.java
trunk/HibernateExt/metadata/src/java/org/hibernate/validator/event/ValidateEventListener.java
Log:
code cleaning, bug prevention
Modified: trunk/HibernateExt/metadata/src/java/org/hibernate/annotationfactory/AnnotationFactory.java
===================================================================
--- trunk/HibernateExt/metadata/src/java/org/hibernate/annotationfactory/AnnotationFactory.java 2006-09-29 19:13:51 UTC (rev 10536)
+++ trunk/HibernateExt/metadata/src/java/org/hibernate/annotationfactory/AnnotationFactory.java 2006-09-29 19:18:26 UTC (rev 10537)
@@ -23,6 +23,9 @@
try {
return getProxyInstance( proxyClass, handler );
}
+ catch (RuntimeException e) {
+ throw e;
+ }
catch (Exception e) {
throw new RuntimeException( e );
}
Modified: trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/AbstractPropertyHolder.java
===================================================================
--- trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/AbstractPropertyHolder.java 2006-09-29 19:13:51 UTC (rev 10536)
+++ trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/AbstractPropertyHolder.java 2006-09-29 19:18:26 UTC (rev 10537)
@@ -75,7 +75,7 @@
*/
public Column[] getOverriddenColumn(String propertyName) {
Column[] override = null;
- if ( override == null && parent != null ) {
+ if ( parent != null ) {
override = parent.getOverriddenColumn( propertyName );
}
if ( override == null && currentPropertyColumnOverride != null ) {
@@ -92,7 +92,7 @@
*/
public JoinColumn[] getOverriddenJoinColumn(String propertyName) {
JoinColumn[] override = null;
- if ( override == null && parent != null ) {
+ if ( parent != null ) {
override = parent.getOverriddenJoinColumn( propertyName );
}
if ( override == null && currentPropertyJoinColumnOverride != null ) {
Modified: trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/AnnotationBinder.java
===================================================================
--- trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/AnnotationBinder.java 2006-09-29 19:13:51 UTC (rev 10536)
+++ trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/AnnotationBinder.java 2006-09-29 19:18:26 UTC (rev 10537)
@@ -791,8 +791,7 @@
for ( int index = 0; index < deep ; index++ ) {
XClass clazz = classesToProcess.get( index );
- InheritanceState state = inheritanceStatePerClass.get( clazz );
-
+
boolean currentHasIdentifier = addElementsOfAClass(
elements, propertyHolder, isPropertyAnnotated,
accessType, clazz, mappings
Modified: trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/AnnotationConfiguration.java
===================================================================
--- trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/AnnotationConfiguration.java 2006-09-29 19:13:51 UTC (rev 10536)
+++ trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/AnnotationConfiguration.java 2006-09-29 19:18:26 UTC (rev 10537)
@@ -632,7 +632,7 @@
this.precedence = precedence;
}
- private class CacheHolder {
+ private static class CacheHolder {
public CacheHolder(String role, String usage, String region, boolean isClass, boolean cacheLazy) {
this.role = role;
this.usage = usage;
Modified: trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/BinderHelper.java
===================================================================
--- trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/BinderHelper.java 2006-09-29 19:13:51 UTC (rev 10536)
+++ trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/BinderHelper.java 2006-09-29 19:18:26 UTC (rev 10537)
@@ -408,7 +408,7 @@
params.setProperty( (String) elt.getKey(), (String) elt.getValue() );
}
}
- if ( generatorType == "assigned" ) id.setNullValue( "undefined" );
+ if ( "assigned".equals( generatorType ) ) id.setNullValue( "undefined" );
id.setIdentifierGeneratorProperties( params );
}
Modified: trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/CollectionBinder.java
===================================================================
--- trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/CollectionBinder.java 2006-09-29 19:13:51 UTC (rev 10536)
+++ trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/CollectionBinder.java 2006-09-29 19:18:26 UTC (rev 10537)
@@ -22,12 +22,15 @@
import org.hibernate.AssertionFailure;
import org.hibernate.FetchMode;
import org.hibernate.MappingException;
-import org.hibernate.annotations.AccessType;
import org.hibernate.annotations.BatchSize;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CollectionId;
import org.hibernate.annotations.CollectionOfElements;
import org.hibernate.annotations.Fetch;
+import org.hibernate.annotations.Filter;
+import org.hibernate.annotations.FilterJoinTable;
+import org.hibernate.annotations.FilterJoinTables;
+import org.hibernate.annotations.Filters;
import org.hibernate.annotations.ForeignKey;
import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;
@@ -35,10 +38,6 @@
import org.hibernate.annotations.Sort;
import org.hibernate.annotations.SortType;
import org.hibernate.annotations.Where;
-import org.hibernate.annotations.Filter;
-import org.hibernate.annotations.Filters;
-import org.hibernate.annotations.FilterJoinTable;
-import org.hibernate.annotations.FilterJoinTables;
import org.hibernate.annotations.WhereJoinTable;
import org.hibernate.cfg.AnnotatedClassType;
import org.hibernate.cfg.AnnotationBinder;
@@ -67,11 +66,10 @@
import org.hibernate.mapping.Selectable;
import org.hibernate.mapping.SimpleValue;
import org.hibernate.mapping.Table;
-import org.hibernate.reflection.XAnnotatedElement;
import org.hibernate.reflection.XClass;
import org.hibernate.reflection.XProperty;
+import org.hibernate.util.CollectionHelper;
import org.hibernate.util.StringHelper;
-import org.hibernate.util.CollectionHelper;
/**
* Collection binder
@@ -309,6 +307,12 @@
try {
collection.setComparator( (Comparator) comparator.newInstance() );
}
+ catch (ClassCastException e) {
+ throw new AnnotationException(
+ "Comparator not implementing java.util.Comparator class: "
+ + comparator.getName() + "(" + safeCollectionRole() + ")"
+ );
+ }
catch (Exception e) {
throw new AnnotationException(
"Could not instantiate comparator class: "
@@ -1118,10 +1122,8 @@
if ( AnnotatedClassType.EMBEDDABLE.equals( classType ) ) {
EntityBinder entityBinder = new EntityBinder();
- Embeddable embeddable = (Embeddable) elementClass.getAnnotation( Embeddable.class );
PersistentClass owner = collValue.getOwner();
boolean isPropertyAnnotated;
- AccessType access = ( (XAnnotatedElement) elementClass ).getAnnotation( AccessType.class );
//FIXME support @Access for collection of elements
//String accessType = access != null ? access.value() : null;
if ( owner.getIdentifierProperty() != null ) {
Modified: trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/MapBinder.java
===================================================================
--- trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/MapBinder.java 2006-09-29 19:13:51 UTC (rev 10536)
+++ trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/MapBinder.java 2006-09-29 19:18:26 UTC (rev 10537)
@@ -7,16 +7,11 @@
import java.util.Random;
import javax.persistence.AttributeOverride;
import javax.persistence.AttributeOverrides;
-import javax.persistence.Embeddable;
import org.hibernate.AnnotationException;
import org.hibernate.AssertionFailure;
import org.hibernate.FetchMode;
import org.hibernate.MappingException;
-import org.hibernate.dialect.HSQLDialect;
-import org.hibernate.sql.Template;
-import org.hibernate.util.StringHelper;
-import org.hibernate.annotations.AccessType;
import org.hibernate.cfg.AnnotatedClassType;
import org.hibernate.cfg.AnnotationBinder;
import org.hibernate.cfg.BinderHelper;
@@ -29,6 +24,7 @@
import org.hibernate.cfg.PropertyHolderBuilder;
import org.hibernate.cfg.PropertyPreloadedData;
import org.hibernate.cfg.SecondPass;
+import org.hibernate.dialect.HSQLDialect;
import org.hibernate.mapping.Collection;
import org.hibernate.mapping.Column;
import org.hibernate.mapping.Component;
@@ -40,12 +36,12 @@
import org.hibernate.mapping.PersistentClass;
import org.hibernate.mapping.Property;
import org.hibernate.mapping.SimpleValue;
-import org.hibernate.mapping.Table;
import org.hibernate.mapping.ToOne;
import org.hibernate.mapping.Value;
-import org.hibernate.reflection.XAnnotatedElement;
import org.hibernate.reflection.XClass;
import org.hibernate.reflection.XProperty;
+import org.hibernate.sql.Template;
+import org.hibernate.util.StringHelper;
/**
* Implementation to bind a Map
@@ -167,10 +163,8 @@
if ( AnnotatedClassType.EMBEDDABLE.equals( classType ) ) {
EntityBinder entityBinder = new EntityBinder();
- Embeddable embeddable = (Embeddable) elementClass.getAnnotation( Embeddable.class );
PersistentClass owner = mapValue.getOwner();
boolean isPropertyAnnotated;
- AccessType access = ( (XAnnotatedElement) elementClass ).getAnnotation( AccessType.class );
//FIXME support @Access for collection of elements
//String accessType = access != null ? access.value() : null;
if ( owner.getIdentifierProperty() != null ) {
@@ -252,23 +246,18 @@
else if ( element instanceof DependantValue ) {
//TODO this never happen I think
if ( propertyName != null ) {
- Collection coll = (Collection) associatedClass.getRecursiveProperty( propertyName )
- .getValue();
referencedPropertyName = collection.getReferencedPropertyName();
}
else {
throw new AnnotationException( "SecondaryTable JoinColumn cannot reference a non primary key" );
}
}
- Table table;
Iterator referencedEntityColumns;
if (referencedPropertyName == null) {
- table = associatedClass.getTable();
referencedEntityColumns = associatedClass.getIdentifier().getColumnIterator();
}
else {
Property referencedProperty = associatedClass.getRecursiveProperty( referencedPropertyName );
- table = referencedProperty.getValue().getTable();
referencedEntityColumns = referencedProperty.getColumnIterator();
}
String alias = "$alias$";
Modified: trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/Version.java
===================================================================
--- trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/Version.java 2006-09-29 19:13:51 UTC (rev 10536)
+++ trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/Version.java 2006-09-29 19:18:26 UTC (rev 10537)
@@ -8,7 +8,7 @@
* @author Emmanuel Bernard
*/
public class Version {
- public static String VERSION = "3.2.0.CR2";
+ public static final String VERSION = "3.2.0.CR2";
private static Log log = LogFactory.getLog( Version.class );
static {
Modified: trunk/HibernateExt/metadata/src/java/org/hibernate/lucene/DocumentBuilder.java
===================================================================
--- trunk/HibernateExt/metadata/src/java/org/hibernate/lucene/DocumentBuilder.java 2006-09-29 19:13:51 UTC (rev 10536)
+++ trunk/HibernateExt/metadata/src/java/org/hibernate/lucene/DocumentBuilder.java 2006-09-29 19:18:26 UTC (rev 10537)
@@ -84,7 +84,7 @@
private Float getBoost(AnnotatedElement element) {
if (element == null) return null;
Boost boost = element.getAnnotation( Boost.class );
- return boost != null ? new Float( boost.value() ) : null;
+ return boost != null ? Float.valueOf( boost.value() ) : null;
}
private Object getValue(Member member, T bean) {
Modified: trunk/HibernateExt/metadata/src/java/org/hibernate/lucene/event/LuceneEventListener.java
===================================================================
--- trunk/HibernateExt/metadata/src/java/org/hibernate/lucene/event/LuceneEventListener.java 2006-09-29 19:13:51 UTC (rev 10536)
+++ trunk/HibernateExt/metadata/src/java/org/hibernate/lucene/event/LuceneEventListener.java 2006-09-29 19:18:26 UTC (rev 10537)
@@ -76,6 +76,11 @@
try {
analyzer = (Analyzer) analyzerClass.newInstance();
}
+ catch (ClassCastException e) {
+ throw new HibernateException(
+ "Lucene analyzer does not implement " + Analyzer.class.getName() + ": " + analyzerClassName
+ );
+ }
catch (Exception e) {
throw new HibernateException( "Failed to instantiate lucene analyzer with type " + analyzerClassName );
}
Modified: trunk/HibernateExt/metadata/src/java/org/hibernate/reflection/java/EJB3OverridenAnnotationReader.java
===================================================================
--- trunk/HibernateExt/metadata/src/java/org/hibernate/reflection/java/EJB3OverridenAnnotationReader.java 2006-09-29 19:13:51 UTC (rev 10536)
+++ trunk/HibernateExt/metadata/src/java/org/hibernate/reflection/java/EJB3OverridenAnnotationReader.java 2006-09-29 19:18:26 UTC (rev 10537)
@@ -175,7 +175,6 @@
private String className;
private String propertyName;
private PropertyType propertyType;
- private boolean isFieldAccess;
private transient Annotation[] annotations;
private static final String WORD_SEPARATOR = "-";
private transient List<Element> elementsForProperty;
@@ -828,9 +827,6 @@
private void getEmbeddedId(List<Annotation> annotationList, XMLContext.Default defaults) {
for ( Element element : elementsForProperty ) {
if ( "embedded-id".equals( element.getName() ) ) {
- //boolean properAccessOnMetadataComplete = computeProperAccessOnMetadataComplete( defaults );
- //boolean properOverridingOnMetadataNonComplete = computeProperOverridingOnMetadataNonComplete( defaults );
- //if ( properAccessOnMetadataComplete || properOverridingOnMetadataNonComplete ) {
if ( isProcessingId( defaults ) ) {
Annotation annotation = getAttributeOverrides( element, defaults );
if ( annotation != null ) annotationList.add( annotation );
@@ -908,8 +904,6 @@
private void getId(List<Annotation> annotationList, XMLContext.Default defaults) {
for ( Element element : elementsForProperty ) {
if ( "id".equals( element.getName() ) ) {
- //boolean properAccessOnMetadataComplete = computeProperAccessOnMetadataComplete( defaults );
- //boolean properOverridingOnMetadataNonComplete = computeProperOverridingOnMetadataNonComplete( defaults );
boolean processId = isProcessingId( defaults );
if ( processId ) {
Annotation annotation = buildColumns( element );
@@ -985,23 +979,11 @@
return correctAccess || ( ! isExplicit && hasId ) || ( ! isExplicit && propertyIsDefault );
}
- private boolean computeProperOverridingOnMetadataNonComplete(XMLContext.Default defaults) {
- return defaults.canUseJavaAnnotations()
- && super.isAnnotationPresent( Id.class );
- }
-
- private boolean computeProperAccessOnMetadataComplete(XMLContext.Default defaults) {
- return ( ! defaults.canUseJavaAnnotations() )
- && ( ( ! "field".equals( defaults.getAccess() ) && ! PropertyType.FIELD
- .equals( propertyType ) )
- || ( "field".equals( defaults.getAccess() ) && PropertyType.FIELD.equals( propertyType ) ) );
- }
-
private Columns buildColumns(Element element) {
List<Element> subelements = element.elements( "column" );
List<Column> columns = new ArrayList<Column>( subelements.size() );
for ( Element subelement : subelements ) {
- columns.add( getColumn( subelement, false ) );
+ columns.add( getColumn( subelement, false, element ) );
}
if ( columns.size() > 0 ) {
AnnotationDescriptor columnsDescr = new AnnotationDescriptor( Columns.class );
@@ -1164,14 +1146,14 @@
AnnotationDescriptor override = new AnnotationDescriptor( AttributeOverride.class );
copyStringAttribute( override, current, "name", true );
Element column = current != null ? current.element( "column" ) : null;
- override.setValue( "column", getColumn( column, true ) );
+ override.setValue( "column", getColumn( column, true, current ) );
overrides.add( (AttributeOverride) AnnotationFactory.create( override ) );
}
}
return overrides;
}
- private Column getColumn(Element element, boolean isMandatory) {
+ private Column getColumn(Element element, boolean isMandatory, Element current) {
//Element subelement = element != null ? element.element( "column" ) : null;
if ( element != null ) {
AnnotationDescriptor column = new AnnotationDescriptor( Column.class );
@@ -1189,7 +1171,7 @@
}
else {
if ( isMandatory ) {
- throw new AnnotationException( element.getPath() + " is mandatory. " + SCHEMA_VALIDATION );
+ throw new AnnotationException( current.getPath() + ".column is mandatory. " + SCHEMA_VALIDATION );
}
return null;
}
@@ -1217,22 +1199,18 @@
if ( access != null ) {
AnnotationDescriptor ad = new AnnotationDescriptor( AccessType.class );
ad.setValue( "value", access );
- isFieldAccess = "field".equals( access );
return AnnotationFactory.create( ad );
}
else if ( defaults.canUseJavaAnnotations() && super.isAnnotationPresent( AccessType.class ) ) {
AccessType annotation = super.getAnnotation( AccessType.class );
- isFieldAccess = "field".equals( annotation != null ? annotation.value() : null );
return annotation;
}
else if ( defaults.getAccess() != null ) {
AnnotationDescriptor ad = new AnnotationDescriptor( AccessType.class );
ad.setValue( "value", defaults.getAccess() );
- isFieldAccess = "field".equals( defaults.getAccess() );
return AnnotationFactory.create( ad );
}
else {
- isFieldAccess = false;
return null;
}
}
Modified: trunk/HibernateExt/metadata/src/java/org/hibernate/reflection/java/JavaXFactory.java
===================================================================
--- trunk/HibernateExt/metadata/src/java/org/hibernate/reflection/java/JavaXFactory.java 2006-09-29 19:13:51 UTC (rev 10536)
+++ trunk/HibernateExt/metadata/src/java/org/hibernate/reflection/java/JavaXFactory.java 2006-09-29 19:18:26 UTC (rev 10537)
@@ -8,15 +8,13 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import javax.persistence.EntityListeners;
import javax.persistence.NamedNativeQuery;
import javax.persistence.NamedQuery;
import javax.persistence.SequenceGenerator;
import javax.persistence.SqlResultSetMapping;
import javax.persistence.TableGenerator;
-import javax.persistence.EntityListeners;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
import org.dom4j.Element;
import org.hibernate.reflection.ReflectionManager;
import org.hibernate.reflection.XClass;
@@ -40,7 +38,6 @@
*/
public class JavaXFactory implements ReflectionManager {
- private static Log log = LogFactory.getLog( JavaXFactory.class );
private XMLContext xmlContext;
private HashMap defaults;
Modified: trunk/HibernateExt/metadata/src/java/org/hibernate/reflection/java/Pair.java
===================================================================
--- trunk/HibernateExt/metadata/src/java/org/hibernate/reflection/java/Pair.java 2006-09-29 19:13:51 UTC (rev 10536)
+++ trunk/HibernateExt/metadata/src/java/org/hibernate/reflection/java/Pair.java 2006-09-29 19:18:26 UTC (rev 10537)
@@ -19,6 +19,9 @@
@Override
public boolean equals(Object obj) {
+ if ( ! (obj instanceof Pair) ) {
+ return false;
+ }
Pair other = (Pair) obj;
return safeEquals( o1, other.o1 ) && safeEquals( o2, other.o2 );
}
Modified: trunk/HibernateExt/metadata/src/java/org/hibernate/type/ByteArrayBlobType.java
===================================================================
--- trunk/HibernateExt/metadata/src/java/org/hibernate/type/ByteArrayBlobType.java 2006-09-29 19:13:51 UTC (rev 10536)
+++ trunk/HibernateExt/metadata/src/java/org/hibernate/type/ByteArrayBlobType.java 2006-09-29 19:18:26 UTC (rev 10537)
@@ -66,7 +66,7 @@
int length = array.length;
Byte[] copy = new Byte[length];
for ( int index = 0; index < length ; index++ ) {
- copy[index] = new Byte( array[index].byteValue() );
+ copy[index] = Byte.valueOf( array[index].byteValue() );
}
return copy;
}
@@ -168,7 +168,7 @@
int length = bytes.length;
Byte[] result = new Byte[length];
for ( int index = 0; index < length ; index++ ) {
- result[index] = new Byte( bytes[index] );
+ result[index] = Byte.valueOf( bytes[index] );
}
return result;
}
Modified: trunk/HibernateExt/metadata/src/java/org/hibernate/type/CharacterArrayClobType.java
===================================================================
--- trunk/HibernateExt/metadata/src/java/org/hibernate/type/CharacterArrayClobType.java 2006-09-29 19:13:51 UTC (rev 10536)
+++ trunk/HibernateExt/metadata/src/java/org/hibernate/type/CharacterArrayClobType.java 2006-09-29 19:18:26 UTC (rev 10537)
@@ -67,7 +67,7 @@
for ( int i = reader.read( charbuf ); i > 0 ; i = reader.read( charbuf ) ) {
result.ensureCapacity( result.size() + BUFFER_SIZE );
for ( int charIndex = 0; charIndex < i ; charIndex++ ) {
- result.add( new Character( charbuf[charIndex] ) );
+ result.add( Character.valueOf( charbuf[charIndex] ) );
}
}
}
@@ -117,7 +117,7 @@
int length = array.length;
Character[] copy = new Character[length];
for ( int index = 0; index < length ; index++ ) {
- copy[index] = new Character( array[index].charValue() );
+ copy[index] = Character.valueOf( array[index].charValue() );
}
return copy;
}
Modified: trunk/HibernateExt/metadata/src/java/org/hibernate/type/EnumType.java
===================================================================
--- trunk/HibernateExt/metadata/src/java/org/hibernate/type/EnumType.java 2006-09-29 19:13:51 UTC (rev 10536)
+++ trunk/HibernateExt/metadata/src/java/org/hibernate/type/EnumType.java 2006-09-29 19:18:26 UTC (rev 10537)
@@ -119,7 +119,7 @@
if ( IS_TRACE_ENABLED ) {
log.debug( "Binding '" + ordinal + "' to parameter: " + index );
}
- st.setObject( index, new Integer( ordinal ), sqlType );
+ st.setObject( index, Integer.valueOf( ordinal ), sqlType );
}
else {
String enumString = ( (Enum) value ).name();
Modified: trunk/HibernateExt/metadata/src/java/org/hibernate/validator/Environment.java
===================================================================
--- trunk/HibernateExt/metadata/src/java/org/hibernate/validator/Environment.java 2006-09-29 19:13:51 UTC (rev 10536)
+++ trunk/HibernateExt/metadata/src/java/org/hibernate/validator/Environment.java 2006-09-29 19:18:26 UTC (rev 10537)
@@ -12,5 +12,5 @@
/**
* Message interpolator class used. The same instance is shared across all ClassValidators
*/
- public static String MESSAGE_INTERPOLATOR_CLASS = "hibernate.validator.message_interpolator_class";
+ public static final String MESSAGE_INTERPOLATOR_CLASS = "hibernate.validator.message_interpolator_class";
}
Modified: trunk/HibernateExt/metadata/src/java/org/hibernate/validator/event/ValidateEventListener.java
===================================================================
--- trunk/HibernateExt/metadata/src/java/org/hibernate/validator/event/ValidateEventListener.java 2006-09-29 19:13:51 UTC (rev 10536)
+++ trunk/HibernateExt/metadata/src/java/org/hibernate/validator/event/ValidateEventListener.java 2006-09-29 19:18:26 UTC (rev 10537)
@@ -123,12 +123,15 @@
InvalidValue[] invalidValues = element.validator == null ?
null :
element.validator.getInvalidValues( entity );
- for ( InvalidValue invalidValue : invalidValues ) {
- consolidatedInvalidValues.add( invalidValue );
+ if (invalidValues != null) {
+ for ( InvalidValue invalidValue : invalidValues ) {
+ consolidatedInvalidValues.add( invalidValue );
+ }
}
if ( consolidatedInvalidValues.size() > 0 ) {
throw new InvalidStateException(
- consolidatedInvalidValues.toArray( new InvalidValue[]{} ), entity.getClass().getName()
+ consolidatedInvalidValues.toArray( new InvalidValue[consolidatedInvalidValues.size()] ),
+ entity.getClass().getName()
);
}
}
18 years, 2 months
Hibernate SVN: r10536 - in branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/lucene: . bridge event
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2006-09-29 15:13:51 -0400 (Fri, 29 Sep 2006)
New Revision: 10536
Modified:
branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/lucene/DocumentBuilder.java
branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/lucene/bridge/DateBridge.java
branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/lucene/event/LuceneEventListener.java
Log:
code cleaning, bug prevention
Modified: branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/lucene/DocumentBuilder.java
===================================================================
--- branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/lucene/DocumentBuilder.java 2006-09-29 01:46:32 UTC (rev 10535)
+++ branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/lucene/DocumentBuilder.java 2006-09-29 19:13:51 UTC (rev 10536)
@@ -91,7 +91,7 @@
private Float getBoost(AnnotatedElement element) {
if (element == null) return null;
Boost boost = element.getAnnotation( Boost.class );
- return boost != null ? new Float( boost.value() ) : null;
+ return boost != null ? Float.valueOf( boost.value() ) : null;
}
private Object getValue(Member member, T bean) {
Modified: branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/lucene/bridge/DateBridge.java
===================================================================
--- branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/lucene/bridge/DateBridge.java 2006-09-29 01:46:32 UTC (rev 10535)
+++ branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/lucene/bridge/DateBridge.java 2006-09-29 19:13:51 UTC (rev 10536)
@@ -13,7 +13,6 @@
* @author Emmanuel Bernard
*/
public class DateBridge implements StringBridge, ParameterizedBridge {
- //TODO don't depend on such a weak 3rd party API for a public API of ours
DateTools.Resolution resolution;
public Object stringToObject(String stringValue) {
Modified: branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/lucene/event/LuceneEventListener.java
===================================================================
--- branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/lucene/event/LuceneEventListener.java 2006-09-29 01:46:32 UTC (rev 10535)
+++ branches/Lucene_Integration/HibernateExt/metadata/src/java/org/hibernate/lucene/event/LuceneEventListener.java 2006-09-29 19:13:51 UTC (rev 10536)
@@ -83,6 +83,11 @@
try {
analyzer = (Analyzer) analyzerClass.newInstance();
}
+ catch (ClassCastException e) {
+ throw new HibernateException(
+ "Lucene analyzer does not implement " + Analyzer.class.getName() + ": " + analyzerClassName
+ );
+ }
catch (Exception e) {
throw new HibernateException( "Failed to instantiate lucene analyzer with type " + analyzerClassName );
}
18 years, 2 months
Hibernate SVN: r10535 - in trunk/HibernateExt/ejb/src: java/org/hibernate/ejb java/org/hibernate/ejb/packaging test/org/hibernate/ejb/test/packaging
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2006-09-28 21:46:32 -0400 (Thu, 28 Sep 2006)
New Revision: 10535
Modified:
trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/Ejb3Configuration.java
trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/packaging/JarVisitor.java
trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/packaging/JarVisitorTest.java
Log:
Modified: trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/Ejb3Configuration.java
===================================================================
--- trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/Ejb3Configuration.java 2006-09-28 21:24:44 UTC (rev 10534)
+++ trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/Ejb3Configuration.java 2006-09-29 01:46:32 UTC (rev 10535)
@@ -913,6 +913,7 @@
HibernatePersistence.HBXML_FILES
);
for ( InputStream is : hbmXmlFiles ) {
+ //addInputStream has the responsibility to close the stream
cfg.addInputStream( is );
}
}
Modified: trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/packaging/JarVisitor.java
===================================================================
--- trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/packaging/JarVisitor.java 2006-09-28 21:24:44 UTC (rev 10534)
+++ trunk/HibernateExt/ejb/src/java/org/hibernate/ejb/packaging/JarVisitor.java 2006-09-29 01:46:32 UTC (rev 10535)
@@ -213,8 +213,8 @@
if ( !done ) {
//avoid url access and so on
if ( filters.size() > 0 ) doProcessElements();
+ done = true;
}
- done = true;
return entries;
}
@@ -234,8 +234,10 @@
}
else {
String name = entryName;
+ boolean accepted = false;
for ( FileFilter filter : fileFilters ) {
if ( filter.accept( name ) ) {
+ accepted = true;
InputStream localIs;
if ( filter.getStream() ) {
localIs = secondIs;
@@ -251,24 +253,33 @@
this.entries[index].add( entry );
}
}
+ if (!accepted) {
+ //not accepted free resources
+ is.close();
+ secondIs.close();
+ }
}
}
private void executeJavaElementFilter(
String name, Set<JavaElementFilter> filters, InputStream is, InputStream secondIs
) throws IOException {
+ boolean accepted = false;
for ( JavaElementFilter filter : filters ) {
if ( filter.accept( name ) ) {
- InputStream localIs;
- if ( filter.getStream() ) {
- localIs = secondIs;
- }
- else {
- localIs = null;
- secondIs.close();
- }
+ //FIXME cannot currently have a class filtered twice but matching once
+ // need to copy the is
boolean match = checkAnnotationMatching( is, filter );
if ( match ) {
+ accepted = true;
+ InputStream localIs;
+ if ( filter.getStream() ) {
+ localIs = secondIs;
+ }
+ else {
+ localIs = null;
+ secondIs.close();
+ }
log.debug( "Java element filter matched for " + name );
Entry entry = new Entry( name, localIs );
int index = this.filters.indexOf( filter );
@@ -277,6 +288,10 @@
}
}
}
+ if (!accepted) {
+ is.close();
+ secondIs.close();
+ }
}
private boolean checkAnnotationMatching(InputStream is, JavaElementFilter filter) throws IOException {
Modified: trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/packaging/JarVisitorTest.java
===================================================================
--- trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/packaging/JarVisitorTest.java 2006-09-28 21:24:44 UTC (rev 10534)
+++ trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/packaging/JarVisitorTest.java 2006-09-29 01:46:32 UTC (rev 10535)
@@ -58,6 +58,10 @@
assertTrue( entries.contains( entry ) );
assertNull( ( (JarVisitor.Entry) entries.iterator().next() ).getInputStream() );
assertEquals( 2, jarVisitor.getMatchingEntries()[2].size() );
+ for (JarVisitor.Entry localEntry : (Set<JarVisitor.Entry>) jarVisitor.getMatchingEntries()[2] ) {
+ assertNotNull( localEntry.getInputStream() );
+ localEntry.getInputStream().close();
+ }
// Set<String> classes = jarVisitor.getClassNames();
// assertEquals( 3, classes.size() );
@@ -80,7 +84,10 @@
assertTrue( entries.contains( entry ) );
assertNull( ( (JarVisitor.Entry) entries.iterator().next() ).getInputStream() );
assertEquals( 2, jarVisitor.getMatchingEntries()[2].size() );
-
+ for (JarVisitor.Entry localEntry : (Set<JarVisitor.Entry>) jarVisitor.getMatchingEntries()[2] ) {
+ assertNotNull( localEntry.getInputStream() );
+ localEntry.getInputStream().close();
+ }
// Set<String> classes = jarVisitor.getClassNames();
// assertEquals( 3, classes.size() );
// assertTrue( classes.contains( ApplicationServer.class.getName() ) );
@@ -101,7 +108,10 @@
JarVisitor.Entry entry = new JarVisitor.Entry( Carpet.class.getName(), null );
assertTrue( entries[1].contains( entry ) );
-
+ for (JarVisitor.Entry localEntry : (Set<JarVisitor.Entry>) jarVisitor.getMatchingEntries()[2] ) {
+ assertNotNull( localEntry.getInputStream() );
+ localEntry.getInputStream().close();
+ }
// Set<String> classes = jarVisitor.getClassNames();
// assertEquals( 2, classes.size() );
// assertEquals( 1, jarVisitor.getPackageNames().size() );
@@ -109,7 +119,7 @@
// assertTrue( classes.contains( Carpet.class.getName() ) );
}
- public void testDuplicateFilterExplodedJar() throws Exception {
+ public void testDuplicateFilterExplodedJarExpectedfail() throws Exception {
String jarFileName = "./build/testresources/explodedpar.par";
//JarVisitor jarVisitor = new ExplodedJarVisitor( jarFileName, true, true );
JarVisitor.Filter[] filters = getFilters();
@@ -122,7 +132,7 @@
for ( JarVisitor.Filter filter : filters ) {
dupeFilters[index++] = filter;
}
- JarVisitor jarVisitor = new ExplodedJarVisitor( jarFileName, filters );
+ JarVisitor jarVisitor = new ExplodedJarVisitor( jarFileName, dupeFilters );
assertEquals( "explodedpar", jarVisitor.getUnqualifiedJarName() );
Set[] entries = jarVisitor.getMatchingEntries();
assertEquals( 1, entries[1].size() );
18 years, 2 months
Hibernate SVN: r10534 - in trunk/HibernateExt/metadata/src: java/org/hibernate/annotations java/org/hibernate/cfg java/org/hibernate/cfg/annotations test/org/hibernate/test/annotations/manytomany
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2006-09-28 17:24:44 -0400 (Thu, 28 Sep 2006)
New Revision: 10534
Added:
trunk/HibernateExt/metadata/src/java/org/hibernate/annotations/FilterJoinTable.java
trunk/HibernateExt/metadata/src/java/org/hibernate/annotations/FilterJoinTables.java
trunk/HibernateExt/metadata/src/java/org/hibernate/annotations/WhereJoinTable.java
Modified:
trunk/HibernateExt/metadata/src/java/org/hibernate/annotations/Filter.java
trunk/HibernateExt/metadata/src/java/org/hibernate/annotations/Filters.java
trunk/HibernateExt/metadata/src/java/org/hibernate/annotations/Where.java
trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/AnnotationBinder.java
trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/CollectionBinder.java
trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/manytomany/Group.java
trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/manytomany/ManyToManyTest.java
Log:
ANN-346
ANN-447
Introduce where clause and filters on association tables
Modified: trunk/HibernateExt/metadata/src/java/org/hibernate/annotations/Filter.java
===================================================================
--- trunk/HibernateExt/metadata/src/java/org/hibernate/annotations/Filter.java 2006-09-28 15:35:26 UTC (rev 10533)
+++ trunk/HibernateExt/metadata/src/java/org/hibernate/annotations/Filter.java 2006-09-28 21:24:44 UTC (rev 10534)
@@ -7,7 +7,7 @@
import java.lang.annotation.Target;
/**
- * Add filters to an entity or a collection
+ * Add filters to an entity or a target entity of a collection
*
* @author Emmanuel Bernard
* @author Matthew Inger
Added: trunk/HibernateExt/metadata/src/java/org/hibernate/annotations/FilterJoinTable.java
===================================================================
--- trunk/HibernateExt/metadata/src/java/org/hibernate/annotations/FilterJoinTable.java 2006-09-28 15:35:26 UTC (rev 10533)
+++ trunk/HibernateExt/metadata/src/java/org/hibernate/annotations/FilterJoinTable.java 2006-09-28 21:24:44 UTC (rev 10534)
@@ -0,0 +1,20 @@
+//$Id: $
+package org.hibernate.annotations;
+
+import java.lang.annotation.Target;
+import java.lang.annotation.Retention;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.RetentionPolicy;
+
+/**
+ * Add filters to a join table collection
+ *
+ * @author Emmanuel Bernard
+ */
+(a)Target({ElementType.TYPE, ElementType.METHOD, ElementType.FIELD})
+(a)Retention(RetentionPolicy.RUNTIME)
+public @interface FilterJoinTable {
+ String name();
+
+ String condition() default "";
+}
Added: trunk/HibernateExt/metadata/src/java/org/hibernate/annotations/FilterJoinTables.java
===================================================================
--- trunk/HibernateExt/metadata/src/java/org/hibernate/annotations/FilterJoinTables.java 2006-09-28 15:35:26 UTC (rev 10533)
+++ trunk/HibernateExt/metadata/src/java/org/hibernate/annotations/FilterJoinTables.java 2006-09-28 21:24:44 UTC (rev 10534)
@@ -0,0 +1,18 @@
+//$Id: $
+package org.hibernate.annotations;
+
+import java.lang.annotation.Target;
+import java.lang.annotation.Retention;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.RetentionPolicy;
+
+/**
+ * Add multiple @FilterJoinTable to a collection
+ *
+ * @author Emmanuel Bernard
+ */
+(a)Target({ElementType.TYPE, ElementType.METHOD, ElementType.FIELD})
+(a)Retention(RetentionPolicy.RUNTIME)
+public @interface FilterJoinTables {
+ FilterJoinTable[] value();
+}
Modified: trunk/HibernateExt/metadata/src/java/org/hibernate/annotations/Filters.java
===================================================================
--- trunk/HibernateExt/metadata/src/java/org/hibernate/annotations/Filters.java 2006-09-28 15:35:26 UTC (rev 10533)
+++ trunk/HibernateExt/metadata/src/java/org/hibernate/annotations/Filters.java 2006-09-28 21:24:44 UTC (rev 10534)
@@ -7,7 +7,7 @@
import java.lang.annotation.Target;
/**
- * Add multiple filters to an entity or a collection
+ * Add multiple @Filters
*
* @author Emmanuel Bernard
* @author Matthew Inger
Modified: trunk/HibernateExt/metadata/src/java/org/hibernate/annotations/Where.java
===================================================================
--- trunk/HibernateExt/metadata/src/java/org/hibernate/annotations/Where.java 2006-09-28 15:35:26 UTC (rev 10533)
+++ trunk/HibernateExt/metadata/src/java/org/hibernate/annotations/Where.java 2006-09-28 21:24:44 UTC (rev 10534)
@@ -6,7 +6,7 @@
import java.lang.annotation.Target;
/**
- * Where clause to add to the element (Class or Collection)
+ * Where clause to add to the element Entity or target entity of a collection
*
* @author Emmanuel Bernard
*/
Added: trunk/HibernateExt/metadata/src/java/org/hibernate/annotations/WhereJoinTable.java
===================================================================
--- trunk/HibernateExt/metadata/src/java/org/hibernate/annotations/WhereJoinTable.java 2006-09-28 15:35:26 UTC (rev 10533)
+++ trunk/HibernateExt/metadata/src/java/org/hibernate/annotations/WhereJoinTable.java 2006-09-28 21:24:44 UTC (rev 10534)
@@ -0,0 +1,18 @@
+//$Id: $
+package org.hibernate.annotations;
+
+import java.lang.annotation.Target;
+import java.lang.annotation.Retention;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.RetentionPolicy;
+
+/**
+ * Where clause to add to the colleciton join table
+ *
+ * @author Emmanuel Bernard
+ */
+(a)Target({ElementType.TYPE, ElementType.METHOD, ElementType.FIELD})
+(a)Retention(RetentionPolicy.RUNTIME)
+public @interface WhereJoinTable {
+ String clause();
+}
Modified: trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/AnnotationBinder.java
===================================================================
--- trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/AnnotationBinder.java 2006-09-28 15:35:26 UTC (rev 10533)
+++ trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/AnnotationBinder.java 2006-09-28 21:24:44 UTC (rev 10534)
@@ -1327,19 +1327,7 @@
collectionBinder.setSort( sortAnn );
Cache cachAnn = property.getAnnotation( Cache.class );
collectionBinder.setCache( cachAnn );
- Filter filterAnn = property.getAnnotation( Filter.class );
- if ( filterAnn != null ) {
- collectionBinder.addFilter( filterAnn.name(), filterAnn.condition() );
- }
- Filters filtersAnn = property.getAnnotation( Filters.class );
- if ( filtersAnn != null ) {
- for ( Filter filter : filtersAnn.value() ) {
- collectionBinder.addFilter( filter.name(), filter.condition() );
- }
- }
collectionBinder.setPropertyHolder( propertyHolder );
- Where whereAnn = property.getAnnotation( Where.class );
- collectionBinder.setWhere( whereAnn );
Cascade hibernateCascade = property.getAnnotation( Cascade.class );
NotFound notFound = property.getAnnotation( NotFound.class );
boolean ignoreNotFound = notFound != null && notFound.action().equals( NotFoundAction.IGNORE );
Modified: trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/CollectionBinder.java
===================================================================
--- trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/CollectionBinder.java 2006-09-28 15:35:26 UTC (rev 10533)
+++ trunk/HibernateExt/metadata/src/java/org/hibernate/cfg/annotations/CollectionBinder.java 2006-09-28 21:24:44 UTC (rev 10534)
@@ -35,6 +35,11 @@
import org.hibernate.annotations.Sort;
import org.hibernate.annotations.SortType;
import org.hibernate.annotations.Where;
+import org.hibernate.annotations.Filter;
+import org.hibernate.annotations.Filters;
+import org.hibernate.annotations.FilterJoinTable;
+import org.hibernate.annotations.FilterJoinTables;
+import org.hibernate.annotations.WhereJoinTable;
import org.hibernate.cfg.AnnotatedClassType;
import org.hibernate.cfg.AnnotationBinder;
import org.hibernate.cfg.BinderHelper;
@@ -82,7 +87,6 @@
protected String propertyName;
PropertyHolder propertyHolder;
int batchSize;
- String where;
private String mappedBy;
private XClass collectionType;
private XClass targetEntity;
@@ -90,7 +94,6 @@
private Ejb3JoinColumn[] inverseJoinColumns;
private String cascadeStrategy;
String cacheConcurrencyStrategy;
- Map<String, String> filters = new HashMap<String, String>();
String cacheRegionName;
private boolean oneToMany;
protected IndexColumn indexColumn;
@@ -329,25 +332,6 @@
collection.setCacheRegionName( cacheRegionName );
}
- //set filtering
- Iterator<Map.Entry<String, String>> iter = filters.entrySet().iterator();
- if ( StringHelper.isNotEmpty( where ) ) collection.setWhere( where );
- while ( iter.hasNext() ) {
- Map.Entry<String, String> filter = iter.next();
- String name = filter.getKey();
- String cond = filter.getValue();
- if ( BinderHelper.isDefault( cond ) ) {
- cond = mappings.getFilterDefinition( name ).getDefaultFilterCondition();
- if ( StringHelper.isEmpty( cond ) ) {
- throw new AnnotationException(
- "no filter condition found for filter " + name + " in "
- + StringHelper.qualify( propertyHolder.getPath(), propertyName )
- );
- }
- }
- collection.addFilter( name, cond );
- }
-
//work on association
boolean isMappedBy = ! BinderHelper.isDefault( mappedBy );
collection.setInverse( isMappedBy );
@@ -594,7 +578,7 @@
log.info(
"Mapping collection: " + collection.getRole() + " -> " + collection.getCollectionTable().getName()
);
-
+ bindFilters(false);
bindCollectionSecondPass( collection, null, fkJoinColumns, cascadeDeleteEnabled, property, mappings );
if ( !collection.isInverse()
&& !collection.getKey().isNullable() ) {
@@ -612,6 +596,119 @@
}
}
+ private void bindFilters(boolean hasAssociationTable) {
+ Filter simpleFilter = property.getAnnotation( Filter.class );
+ //set filtering
+ //test incompatible choices
+ //if ( StringHelper.isNotEmpty( where ) ) collection.setWhere( where );
+ if (simpleFilter != null) {
+ if (hasAssociationTable) {
+ collection.addManyToManyFilter( simpleFilter.name(), getCondition( simpleFilter ) );
+ }
+ else {
+ collection.addFilter( simpleFilter.name(), getCondition( simpleFilter ) );
+ }
+ }
+ Filters filters = property.getAnnotation( Filters.class );
+ if (filters != null) {
+ for ( Filter filter : filters.value() ) {
+ if (hasAssociationTable) {
+ collection.addManyToManyFilter( filter.name(), getCondition( filter ) );
+ }
+ else {
+ collection.addFilter( filter.name(), getCondition( filter ) );
+ }
+ }
+ }
+ FilterJoinTable simpleFilterJoinTable = property.getAnnotation( FilterJoinTable.class );
+ if (simpleFilterJoinTable != null) {
+ if (hasAssociationTable) {
+ collection.addFilter( simpleFilterJoinTable.name(), getCondition( simpleFilterJoinTable ) );
+ }
+ else {
+ throw new AnnotationException(
+ "Illegal use of @FilterJoinTable on an association without join table:"
+ + StringHelper.qualify( propertyHolder.getPath(), propertyName )
+ );
+ }
+ }
+ FilterJoinTables filterJoinTables = property.getAnnotation( FilterJoinTables.class );
+ if (filterJoinTables != null) {
+ for ( FilterJoinTable filter : filterJoinTables.value() ) {
+ if (hasAssociationTable) {
+ collection.addFilter( filter.name(), getCondition( filter ) );
+ }
+ else {
+ throw new AnnotationException(
+ "Illegal use of @FilterJoinTable on an association without join table:"
+ + StringHelper.qualify( propertyHolder.getPath(), propertyName )
+ );
+ }
+ }
+ }
+
+ Where where = property.getAnnotation( Where.class );
+ String whereClause = where == null ? null : where.clause();
+ if ( StringHelper.isNotEmpty( whereClause ) ) {
+ if (hasAssociationTable) {
+ collection.setManyToManyWhere( whereClause );
+ }
+ else {
+ collection.setWhere( whereClause );
+ }
+ }
+
+ WhereJoinTable whereJoinTable = property.getAnnotation( WhereJoinTable.class );
+ String whereJoinTableClause = whereJoinTable == null ? null : whereJoinTable.clause();
+ if ( StringHelper.isNotEmpty( whereJoinTableClause ) ) {
+ if (hasAssociationTable) {
+ collection.setWhere( whereJoinTableClause );
+ }
+ else {
+ throw new AnnotationException(
+ "Illegal use of @WhereJoinTable on an association without join table:"
+ + StringHelper.qualify( propertyHolder.getPath(), propertyName )
+ );
+ }
+ }
+// This cannot happen in annotations since the second fetch is hardcoded to join
+// if ( ( ! collection.getManyToManyFilterMap().isEmpty() || collection.getManyToManyWhere() != null ) &&
+// collection.getFetchMode() == FetchMode.JOIN &&
+// collection.getElement().getFetchMode() != FetchMode.JOIN ) {
+// throw new MappingException(
+// "association with join table defining filter or where without join fetching " +
+// "not valid within collection using join fetching [" + collection.getRole() + "]"
+// );
+// }
+ }
+
+ private String getCondition(FilterJoinTable filter) {
+ //set filtering
+ String name = filter.name();
+ String cond = filter.condition();
+ return getCondition( cond, name );
+ }
+
+ private String getCondition(Filter filter) {
+ //set filtering
+ String name = filter.name();
+ String cond = filter.condition();
+ return getCondition( cond, name );
+ }
+
+ private String getCondition(String cond, String name) {
+ if ( BinderHelper.isDefault( cond ) ) {
+ cond = mappings.getFilterDefinition( name ).getDefaultFilterCondition();
+ if ( StringHelper.isEmpty( cond ) ) {
+ throw new AnnotationException(
+ "no filter condition found for filter " + name + " in "
+ + StringHelper.qualify( propertyHolder.getPath(), propertyName )
+ );
+ }
+ }
+ return cond;
+ }
+
public void setCache(Cache cacheAnn) {
if ( cacheAnn != null ) {
cacheRegionName = BinderHelper.isDefault( cacheAnn.region() ) ? null : cacheAnn.region();
@@ -623,16 +720,6 @@
}
}
- public void addFilter(String name, String condition) {
- filters.put( name, condition );
- }
-
- public void setWhere(Where whereAnn) {
- if ( whereAnn != null ) {
- where = whereAnn.clause();
- }
- }
-
public void setOneToMany(boolean oneToMany) {
this.oneToMany = oneToMany;
}
@@ -854,7 +941,7 @@
return key;
}
- protected static void bindManyToManySecondPass(
+ protected void bindManyToManySecondPass(
Collection collValue,
Map persistentClasses,
Ejb3JoinColumn[] joinColumns,
@@ -970,7 +1057,7 @@
}
collValue.setCollectionTable( associationTableBinder.bind() );
}
-
+ bindFilters( isCollectionOfEntities );
bindCollectionSecondPass( collValue, collectionEntity, joinColumns, cascadeDeleteEnabled, property, mappings );
ManyToOne element = null;
Modified: trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/manytomany/Group.java
===================================================================
--- trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/manytomany/Group.java 2006-09-28 15:35:26 UTC (rev 10533)
+++ trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/manytomany/Group.java 2006-09-28 21:24:44 UTC (rev 10534)
@@ -8,15 +8,22 @@
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 javax.persistence.OrderBy;
+import org.hibernate.annotations.Where;
+import org.hibernate.annotations.FilterDef;
+import org.hibernate.annotations.Filter;
+import org.hibernate.annotations.FilterJoinTable;
+import org.hibernate.annotations.WhereJoinTable;
+
/**
* @author Emmanuel Bernard
*/
@Entity
@Table(name = "tbl_group")
+@FilterDef(name="Groupfilter")
public class Group {
private Integer id;
private Collection<Permission> permissions;
@@ -37,6 +44,10 @@
inverseJoinColumns = @JoinColumn(name = "permission", referencedColumnName = "permission")
)
@OrderBy("expirationDate")
+ @Where(clause = "1=1")
+ @WhereJoinTable(clause = "2=2")
+ @Filter(name="Groupfilter", condition = "3=3")
+ @FilterJoinTable(name="Groupfilter", condition = "4=4")
public Collection<Permission> getPermissions() {
return permissions;
}
Modified: trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/manytomany/ManyToManyTest.java
===================================================================
--- trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/manytomany/ManyToManyTest.java 2006-09-28 15:35:26 UTC (rev 10533)
+++ trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/manytomany/ManyToManyTest.java 2006-09-28 21:24:44 UTC (rev 10534)
@@ -441,6 +441,7 @@
public void testAssociationTableAndOrderBy() throws Exception {
Session s = openSession();
+ s.enableFilter( "Groupfilter" );
Permission readAccess = new Permission();
readAccess.setPermission( "read" );
readAccess.setExpirationDate( new Date() );
@@ -458,6 +459,7 @@
s.flush();
s.clear();
group = (Group) s.get( Group.class, group.getId() );
+ s.createQuery( "select g from Group g join fetch g.permissions").list();
assertEquals( "write", group.getPermissions().iterator().next().getPermission() );
s.getTransaction().rollback();
s.close();
18 years, 2 months
Hibernate SVN: r10533 - trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/manytomany
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2006-09-28 11:35:26 -0400 (Thu, 28 Sep 2006)
New Revision: 10533
Modified:
trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/manytomany/Group.java
trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/manytomany/ManyToManyTest.java
Log:
more tests
Modified: trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/manytomany/Group.java
===================================================================
--- trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/manytomany/Group.java 2006-09-26 20:24:38 UTC (rev 10532)
+++ trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/manytomany/Group.java 2006-09-28 15:35:26 UTC (rev 10533)
@@ -10,6 +10,7 @@
import javax.persistence.ManyToMany;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
+import javax.persistence.OrderBy;
/**
* @author Emmanuel Bernard
@@ -35,6 +36,7 @@
joinColumns = @JoinColumn(name = "group_id", referencedColumnName = "id"),
inverseJoinColumns = @JoinColumn(name = "permission", referencedColumnName = "permission")
)
+ @OrderBy("expirationDate")
public Collection<Permission> getPermissions() {
return permissions;
}
Modified: trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/manytomany/ManyToManyTest.java
===================================================================
--- trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/manytomany/ManyToManyTest.java 2006-09-26 20:24:38 UTC (rev 10532)
+++ trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/manytomany/ManyToManyTest.java 2006-09-28 15:35:26 UTC (rev 10533)
@@ -439,6 +439,30 @@
}
}
+ public void testAssociationTableAndOrderBy() throws Exception {
+ Session s = openSession();
+ Permission readAccess = new Permission();
+ readAccess.setPermission( "read" );
+ readAccess.setExpirationDate( new Date() );
+ Permission writeAccess = new Permission();
+ writeAccess.setPermission( "write" );
+ writeAccess.setExpirationDate( new Date( new Date().getTime() - 10*60*1000 ) );
+ Collection<Permission> coll = new ArrayList<Permission>( 2 );
+ coll.add( readAccess );
+ coll.add( writeAccess );
+ Group group = new Group();
+ group.setId( new Integer( 1 ) );
+ group.setPermissions( coll );
+ s.getTransaction().begin();
+ s.persist( group );
+ s.flush();
+ s.clear();
+ group = (Group) s.get( Group.class, group.getId() );
+ assertEquals( "write", group.getPermissions().iterator().next().getPermission() );
+ s.getTransaction().rollback();
+ s.close();
+ }
+
public void testJoinedSubclassManyToMany() throws Exception {
Session s = openSession();
Zone a = new Zone();
18 years, 2 months
Hibernate SVN: r10532 - trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/emops
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2006-09-26 16:24:38 -0400 (Tue, 26 Sep 2006)
New Revision: 10532
Modified:
trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/emops/MergeTest.java
trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/emops/Race.java
Log:
more tests
Modified: trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/emops/MergeTest.java
===================================================================
--- trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/emops/MergeTest.java 2006-09-26 15:54:00 UTC (rev 10531)
+++ trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/emops/MergeTest.java 2006-09-26 20:24:38 UTC (rev 10532)
@@ -54,6 +54,38 @@
em.close();
}
+ public void testConcurrentMerge() {
+ Race race = new Race();
+ race.name = "Derby";
+ EntityManager em = factory.createEntityManager();
+ em.getTransaction().begin();
+ em.persist( race );
+ em.flush();
+ em.getTransaction().commit();
+ em.close();
+
+ race.name = "Magnicourt";
+
+ em = factory.createEntityManager();
+ em.getTransaction().begin();
+ Race race2 = em.find(Race.class, race.id );
+ race2.name = "Mans";
+
+ race = em.merge( race );
+ em.flush();
+ em.getTransaction().commit();
+ em.close();
+
+ em = factory.createEntityManager();
+ em.getTransaction().begin();
+ race2 = em.find(Race.class, race.id );
+ assertEquals( "Last commit win in merge", "Magnicourt", race2.name );
+
+ em.remove( race2 );
+ em.getTransaction().commit();
+ em.close();
+ }
+
public Class[] getAnnotatedClasses() {
return new Class[] {
Race.class,
Modified: trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/emops/Race.java
===================================================================
--- trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/emops/Race.java 2006-09-26 15:54:00 UTC (rev 10531)
+++ trunk/HibernateExt/ejb/src/test/org/hibernate/ejb/test/emops/Race.java 2006-09-26 20:24:38 UTC (rev 10532)
@@ -21,4 +21,5 @@
@IndexColumn( name="index" ) @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@org.hibernate.annotations.Cascade( { org.hibernate.annotations.CascadeType.ALL, org.hibernate.annotations.CascadeType.DELETE_ORPHAN })
public List<Competitor> competitors = new ArrayList<Competitor>();
+ public String name;
}
18 years, 2 months
Hibernate SVN: r10531 - branches/Branch_3_2/Hibernate3/doc/reference/en/modules trunk/Hibernate3/doc/reference/en/modules
by hibernate-commits@lists.jboss.org
Author: christian.bauer(a)jboss.com
Date: 2006-09-26 11:54:00 -0400 (Tue, 26 Sep 2006)
New Revision: 10531
Modified:
branches/Branch_3_2/Hibernate3/doc/reference/en/modules/batch.xml
trunk/Hibernate3/doc/reference/en/modules/batch.xml
Log:
Documented insert batch and identity
Modified: branches/Branch_3_2/Hibernate3/doc/reference/en/modules/batch.xml
===================================================================
--- branches/Branch_3_2/Hibernate3/doc/reference/en/modules/batch.xml 2006-09-25 21:55:12 UTC (rev 10530)
+++ branches/Branch_3_2/Hibernate3/doc/reference/en/modules/batch.xml 2006-09-26 15:54:00 UTC (rev 10531)
@@ -30,6 +30,11 @@
<programlisting><![CDATA[hibernate.jdbc.batch_size 20]]></programlisting>
+ <para id="disablebatching" revision="1">
+ Note that Hibernate disables insert batching at the JDBC level transparently if you
+ use an <literal>identiy</literal> identifier generator.
+ </para>
+
<para>
You also might like to do this kind of work in a process where interaction with
the second-level cache is completely disabled:
Modified: trunk/Hibernate3/doc/reference/en/modules/batch.xml
===================================================================
--- trunk/Hibernate3/doc/reference/en/modules/batch.xml 2006-09-25 21:55:12 UTC (rev 10530)
+++ trunk/Hibernate3/doc/reference/en/modules/batch.xml 2006-09-26 15:54:00 UTC (rev 10531)
@@ -30,6 +30,11 @@
<programlisting><![CDATA[hibernate.jdbc.batch_size 20]]></programlisting>
+ <para id="disablebatching" revision="1">
+ Note that Hibernate disables insert batching at the JDBC level transparently if you
+ use an <literal>identiy</literal> identifier generator.
+ </para>
+
<para>
You also might like to do this kind of work in a process where interaction with
the second-level cache is completely disabled:
18 years, 2 months
Hibernate SVN: r10530 - in trunk/HibernateExt/metadata/src: java/org/hibernate/validator java/org/hibernate/validator/event test/org/hibernate/validator/test
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2006-09-25 17:55:12 -0400 (Mon, 25 Sep 2006)
New Revision: 10530
Added:
trunk/HibernateExt/metadata/src/java/org/hibernate/validator/Environment.java
trunk/HibernateExt/metadata/src/test/org/hibernate/validator/test/PrefixMessageInterpolator.java
Modified:
trunk/HibernateExt/metadata/src/java/org/hibernate/validator/event/ValidateEventListener.java
trunk/HibernateExt/metadata/src/test/org/hibernate/validator/test/HibernateAnnotationIntegrationTest.java
Log:
ANN-443 hibernate.validator.interpolator_class
Added: trunk/HibernateExt/metadata/src/java/org/hibernate/validator/Environment.java
===================================================================
--- trunk/HibernateExt/metadata/src/java/org/hibernate/validator/Environment.java 2006-09-25 16:14:29 UTC (rev 10529)
+++ trunk/HibernateExt/metadata/src/java/org/hibernate/validator/Environment.java 2006-09-25 21:55:12 UTC (rev 10530)
@@ -0,0 +1,16 @@
+//$Id: $
+package org.hibernate.validator;
+
+/**
+ * Hibernate Validator Event properties
+ * The properties are retrieved from Hibernate
+ * (hibernate.properties, hibernate.cfg.xml, persistence.xml or Configuration API)
+ *
+ * @author Emmanuel Bernard
+ */
+public class Environment {
+ /**
+ * Message interpolator class used. The same instance is shared across all ClassValidators
+ */
+ public static String MESSAGE_INTERPOLATOR_CLASS = "hibernate.validator.message_interpolator_class";
+}
Modified: trunk/HibernateExt/metadata/src/java/org/hibernate/validator/event/ValidateEventListener.java
===================================================================
--- trunk/HibernateExt/metadata/src/java/org/hibernate/validator/event/ValidateEventListener.java 2006-09-25 16:14:29 UTC (rev 10529)
+++ trunk/HibernateExt/metadata/src/java/org/hibernate/validator/event/ValidateEventListener.java 2006-09-25 21:55:12 UTC (rev 10530)
@@ -11,6 +11,9 @@
import org.hibernate.AssertionFailure;
import org.hibernate.EntityMode;
+import org.hibernate.HibernateException;
+import org.hibernate.util.StringHelper;
+import org.hibernate.util.ReflectHelper;
import org.hibernate.cfg.Configuration;
import org.hibernate.event.Initializable;
import org.hibernate.event.PreInsertEvent;
@@ -26,6 +29,8 @@
import org.hibernate.validator.ClassValidator;
import org.hibernate.validator.InvalidStateException;
import org.hibernate.validator.InvalidValue;
+import org.hibernate.validator.Environment;
+import org.hibernate.validator.MessageInterpolator;
/**
* Before insert and update, executes the validator framework
@@ -42,11 +47,32 @@
@SuppressWarnings("unchecked")
public synchronized void initialize(final Configuration cfg) {
if ( !isInitialized ) {
+ String interpolatorString = cfg.getProperty( Environment.MESSAGE_INTERPOLATOR_CLASS );
+ MessageInterpolator interpolator = null;
+ if ( StringHelper.isNotEmpty( interpolatorString ) ) {
+ try {
+ Class interpolatorClass = ReflectHelper.classForName( interpolatorString );
+ interpolator = (MessageInterpolator) interpolatorClass.newInstance();
+ }
+ catch (ClassNotFoundException e) {
+ throw new HibernateException( "Unable to find message interpolator: " + interpolatorString, e );
+ }
+ catch (IllegalAccessException e) {
+ throw new HibernateException( "Unable to instanciate message interpolator: " + interpolatorString, e );
+ }
+ catch (InstantiationException e) {
+ throw new HibernateException( "Unable to instanciate message interpolator: " + interpolatorString, e );
+ }
+ catch (ClassCastException e) {
+ throw new HibernateException( "Class does not implement "
+ + MessageInterpolator.class.getName() + ": " + interpolatorString, e );
+ }
+ }
Iterator<PersistentClass> classes = (Iterator<PersistentClass>) cfg.getClassMappings();
while ( classes.hasNext() ) {
PersistentClass clazz = classes.next();
final Class mappedClass = clazz.getMappedClass();
- ClassValidator validator = new ClassValidator( mappedClass );
+ ClassValidator validator = new ClassValidator( mappedClass, interpolator );
ValidatableElement element = new ValidatableElement( mappedClass, validator );
addSubElement( clazz.getIdentifierProperty(), element );
Iterator properties = clazz.getPropertyIterator();
Modified: trunk/HibernateExt/metadata/src/test/org/hibernate/validator/test/HibernateAnnotationIntegrationTest.java
===================================================================
--- trunk/HibernateExt/metadata/src/test/org/hibernate/validator/test/HibernateAnnotationIntegrationTest.java 2006-09-25 16:14:29 UTC (rev 10529)
+++ trunk/HibernateExt/metadata/src/test/org/hibernate/validator/test/HibernateAnnotationIntegrationTest.java 2006-09-25 21:55:12 UTC (rev 10530)
@@ -10,6 +10,7 @@
import org.hibernate.mapping.PersistentClass;
import org.hibernate.test.annotations.TestCase;
import org.hibernate.validator.InvalidStateException;
+import org.hibernate.validator.Environment;
import org.hibernate.validator.event.ValidatePreInsertEventListener;
import org.hibernate.validator.event.ValidatePreUpdateEventListener;
@@ -68,6 +69,9 @@
catch (InvalidStateException e) {
//success
assertEquals( 2, e.getInvalidValues().length );
+ assertTrue( "Environment.MESSAGE_INTERPOLATOR_CLASS does not work",
+ e.getInvalidValues()[0].getMessage().startsWith( "prefix_")
+ );
}
finally {
if ( tx != null ) tx.rollback();
@@ -145,6 +149,7 @@
}
protected void configure(Configuration cfg) {
+ cfg.setProperty( Environment.MESSAGE_INTERPOLATOR_CLASS, PrefixMessageInterpolator.class.getName() );
cfg.getEventListeners()
.setPreInsertEventListeners( new PreInsertEventListener[]{new ValidatePreInsertEventListener()} );
cfg.getEventListeners()
Added: trunk/HibernateExt/metadata/src/test/org/hibernate/validator/test/PrefixMessageInterpolator.java
===================================================================
--- trunk/HibernateExt/metadata/src/test/org/hibernate/validator/test/PrefixMessageInterpolator.java 2006-09-25 16:14:29 UTC (rev 10529)
+++ trunk/HibernateExt/metadata/src/test/org/hibernate/validator/test/PrefixMessageInterpolator.java 2006-09-25 21:55:12 UTC (rev 10530)
@@ -0,0 +1,14 @@
+//$Id: $
+package org.hibernate.validator.test;
+
+import org.hibernate.validator.MessageInterpolator;
+import org.hibernate.validator.Validator;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class PrefixMessageInterpolator implements MessageInterpolator {
+ public String interpolate(String message, Validator validator, MessageInterpolator defaultInterpolator) {
+ return "prefix_" + defaultInterpolator.interpolate( message, validator, defaultInterpolator );
+ }
+}
18 years, 2 months