diff --git a/hibernate-core/src/main/java/org/hibernate/binder/AttributeBinder.java b/hibernate-core/src/main/java/org/hibernate/binder/AttributeBinder.java index 4eb497455c..fc4786513b 100644 --- a/hibernate-core/src/main/java/org/hibernate/binder/AttributeBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/binder/AttributeBinder.java @@ -22,6 +22,7 @@ import java.lang.annotation.Annotation; * custom mapping annotation}. * * @see org.hibernate.annotations.AttributeBinderType + * @see TypeBinder * * @author Gavin King */ diff --git a/hibernate-core/src/main/java/org/hibernate/binder/TypeBinder.java b/hibernate-core/src/main/java/org/hibernate/binder/TypeBinder.java index d3d3b33fed..f4c0499b61 100644 --- a/hibernate-core/src/main/java/org/hibernate/binder/TypeBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/binder/TypeBinder.java @@ -20,8 +20,34 @@ import java.lang.annotation.Annotation; * like {@link PersistentClass} and {@link Component} to implement the * semantics of some {@linkplain org.hibernate.annotations.TypeBinderType * custom mapping annotation}. + *
+ * For example, this annotation disables rowcount checking for insert, + * update, and delete statements for annotated entities: + *
+ * @TypeBinderType(binder = NoResultCheck.Binder.class) + * @Target(TYPE) @Retention(RUNTIME) + * public @interface NoResultCheck { + * class Binder implements TypeBinder<NoResultCheck> { + * @Override + * public void bind(NoResultCheck annotation, + * MetadataBuildingContext buildingContext, + * PersistentClass persistentClass) { + * persistentClass.setInsertCheckStyle(NONE); + * persistentClass.setUpdateCheckStyle(NONE); + * persistentClass.setDeleteCheckStyle(NONE); + * } + * @Override + * public void bind(NoResultCheck annotation, + * MetadataBuildingContext buildingContext, + * Component embeddableClass) { + * throw new AnnotationException("'@NoResultCheck' cannot annotate an '@Embeddable' class"); + * } + * } + * } + ** * @see org.hibernate.annotations.TypeBinderType + * @see AttributeBinder * * @author Gavin King */ diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/attributebinder/typebinder/NoResultCheck.java b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/attributebinder/typebinder/NoResultCheck.java new file mode 100644 index 0000000000..1f9f35a0e0 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/attributebinder/typebinder/NoResultCheck.java @@ -0,0 +1,33 @@ +package org.hibernate.orm.test.mapping.attributebinder.typebinder; + +import org.hibernate.annotations.TypeBinderType; +import org.hibernate.binder.TypeBinder; +import org.hibernate.boot.spi.MetadataBuildingContext; +import org.hibernate.mapping.Component; +import org.hibernate.mapping.PersistentClass; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import static java.lang.annotation.ElementType.TYPE; +import static java.lang.annotation.RetentionPolicy.RUNTIME; +import static org.hibernate.engine.spi.ExecuteUpdateResultCheckStyle.NONE; + +@TypeBinderType(binder = NoResultCheck.Binder.class) +@Retention(RUNTIME) +@Target(TYPE) +public @interface NoResultCheck { + class Binder implements TypeBinder