diff --git a/hibernate-core/src/main/java/org/hibernate/annotations/DialectOverride.java b/hibernate-core/src/main/java/org/hibernate/annotations/DialectOverride.java index 40fe9162ce..a3eda5277e 100644 --- a/hibernate-core/src/main/java/org/hibernate/annotations/DialectOverride.java +++ b/hibernate-core/src/main/java/org/hibernate/annotations/DialectOverride.java @@ -362,6 +362,30 @@ public interface DialectOverride { FilterDefs[] value(); } + /** + * Specializes a {@link org.hibernate.annotations.SQLSelect} + * in a certain dialect. + */ + @Target({METHOD, FIELD, TYPE}) + @Retention(RUNTIME) + @Repeatable(SQLSelects.class) + @OverridesAnnotation(org.hibernate.annotations.SQLSelect.class) + @interface SQLSelect { + /** + * The {@link Dialect} in which this override applies. + */ + Class dialect(); + Version before() default @Version(major = MAX_VALUE); + Version sameOrAfter() default @Version(major = MIN_VALUE); + + org.hibernate.annotations.SQLSelect override(); + } + @Target({METHOD, FIELD}) + @Retention(RUNTIME) + @interface SQLSelects { + SQLSelect[] value(); + } + /** * Marks an annotation type as a dialect-specific override for * some other annotation type. diff --git a/hibernate-core/src/main/java/org/hibernate/annotations/SQLSelect.java b/hibernate-core/src/main/java/org/hibernate/annotations/SQLSelect.java index 721519874b..a42956c32f 100644 --- a/hibernate-core/src/main/java/org/hibernate/annotations/SQLSelect.java +++ b/hibernate-core/src/main/java/org/hibernate/annotations/SQLSelect.java @@ -51,6 +51,7 @@ import static java.lang.annotation.RetentionPolicy.RUNTIME; * * * @see HQLSelect + * @see DialectOverride.SQLSelect * * @author Gavin King * diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/EntityBinder.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/EntityBinder.java index c012c8acf0..11bb7209db 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/EntityBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/EntityBinder.java @@ -1251,8 +1251,9 @@ public class EntityBinder { } private void bindCustomSql() { - //SQL overriding //TODO: tolerate non-empty table() member here if it explicitly names the main table + //TODO: would be nice to add these guys to @DialectOverride, but getOverridableAnnotation() + // does not yet handle repeatable annotations final SQLInsert sqlInsert = findMatchingSqlAnnotation( "", SQLInsert.class, SQLInserts.class ); if ( sqlInsert != null ) { @@ -1288,7 +1289,7 @@ public class EntityBinder { + persistentClass.getEntityName()); } - final SQLSelect sqlSelect = annotatedClass.getAnnotation( SQLSelect.class ); + final SQLSelect sqlSelect = getOverridableAnnotation( annotatedClass, SQLSelect.class, context ); if ( sqlSelect != null ) { final String loaderName = persistentClass.getEntityName() + "$SQLSelect"; persistentClass.setLoaderName( loaderName );