diff --git a/hibernate-models-orm/src/main/java/org/hibernate/models/orm/categorize/internal/EntityTypeMetadataImpl.java b/hibernate-models-orm/src/main/java/org/hibernate/models/orm/categorize/internal/EntityTypeMetadataImpl.java
index 6f8b049..8d97be7 100644
--- a/hibernate-models-orm/src/main/java/org/hibernate/models/orm/categorize/internal/EntityTypeMetadataImpl.java
+++ b/hibernate-models-orm/src/main/java/org/hibernate/models/orm/categorize/internal/EntityTypeMetadataImpl.java
@@ -361,7 +361,7 @@ public static CustomSql extractCustomSql(AnnotationUsage> customSqlAnnotation)
}
final String sql = customSqlAnnotation.getAttributeValue( "sql" );
- final boolean isCallable = customSqlAnnotation.getAttributeValue( "value" );
+ final boolean isCallable = customSqlAnnotation.getAttributeValue( "callable" );
final ResultCheckStyle checkValue = customSqlAnnotation.getAttributeValue( "check" );
final ExecuteUpdateResultCheckStyle checkStyle;
diff --git a/hibernate-models-orm/src/main/java/org/hibernate/models/orm/categorize/xml/internal/AttributeProcessor.java b/hibernate-models-orm/src/main/java/org/hibernate/models/orm/categorize/xml/internal/AttributeProcessor.java
index f91d046..e86713b 100644
--- a/hibernate-models-orm/src/main/java/org/hibernate/models/orm/categorize/xml/internal/AttributeProcessor.java
+++ b/hibernate-models-orm/src/main/java/org/hibernate/models/orm/categorize/xml/internal/AttributeProcessor.java
@@ -10,6 +10,10 @@
import org.hibernate.annotations.CollectionId;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.Nationalized;
+import org.hibernate.annotations.SQLDelete;
+import org.hibernate.annotations.SQLDeleteAll;
+import org.hibernate.annotations.SQLInsert;
+import org.hibernate.annotations.SQLUpdate;
import org.hibernate.annotations.SortComparator;
import org.hibernate.annotations.SortNatural;
import org.hibernate.boot.internal.CollectionClassification;
@@ -572,6 +576,11 @@ public static MutableMemberDetails processElementCollectionAttribute(
XmlAnnotationHelper.applySqlRestriction( jaxbElementCollection.getSqlRestriction(), memberDetails, sourceModelBuildingContext );
+ XmlAnnotationHelper.applyCustomSql( jaxbElementCollection.getSqlInsert(), memberDetails, SQLInsert.class, sourceModelBuildingContext );
+ XmlAnnotationHelper.applyCustomSql( jaxbElementCollection.getSqlUpdate(), memberDetails, SQLUpdate.class, sourceModelBuildingContext );
+ XmlAnnotationHelper.applyCustomSql( jaxbElementCollection.getSqlDelete(), memberDetails, SQLDelete.class, sourceModelBuildingContext );
+ XmlAnnotationHelper.applyCustomSql( jaxbElementCollection.getSqlDeleteAll(), memberDetails, SQLDeleteAll.class, sourceModelBuildingContext );
+
// todo : attribute-override
// todo : association-override
diff --git a/hibernate-models-orm/src/main/java/org/hibernate/models/orm/categorize/xml/internal/ManagedTypeProcessor.java b/hibernate-models-orm/src/main/java/org/hibernate/models/orm/categorize/xml/internal/ManagedTypeProcessor.java
index 6328bbb..63e4b5e 100644
--- a/hibernate-models-orm/src/main/java/org/hibernate/models/orm/categorize/xml/internal/ManagedTypeProcessor.java
+++ b/hibernate-models-orm/src/main/java/org/hibernate/models/orm/categorize/xml/internal/ManagedTypeProcessor.java
@@ -11,6 +11,9 @@
import java.util.Map;
import java.util.Set;
+import org.hibernate.annotations.SQLDelete;
+import org.hibernate.annotations.SQLInsert;
+import org.hibernate.annotations.SQLUpdate;
import org.hibernate.boot.internal.Abstract;
import org.hibernate.boot.internal.Extends;
import org.hibernate.boot.internal.LimitedCollectionClassification;
@@ -457,6 +460,10 @@ private static void processEntityMetadata(
XmlAnnotationHelper.applySqlRestriction( jaxbEntity.getSqlRestriction(), classDetails, sourceModelBuildingContext );
+ XmlAnnotationHelper.applyCustomSql( jaxbEntity.getSqlInsert(), classDetails, SQLInsert.class, sourceModelBuildingContext );
+ XmlAnnotationHelper.applyCustomSql( jaxbEntity.getSqlUpdate(), classDetails, SQLUpdate.class, sourceModelBuildingContext );
+ XmlAnnotationHelper.applyCustomSql( jaxbEntity.getSqlDelete(), classDetails, SQLDelete.class, sourceModelBuildingContext );
+
processEntityOrMappedSuperclass( jaxbEntity, classDetails, sourceModelBuildingContext );
XmlAnnotationHelper.applyRowId( jaxbEntity.getRowid(), classDetails, sourceModelBuildingContext );
diff --git a/hibernate-models-orm/src/main/java/org/hibernate/models/orm/categorize/xml/internal/XmlAnnotationHelper.java b/hibernate-models-orm/src/main/java/org/hibernate/models/orm/categorize/xml/internal/XmlAnnotationHelper.java
index 0ce3cd9..cfdb420 100644
--- a/hibernate-models-orm/src/main/java/org/hibernate/models/orm/categorize/xml/internal/XmlAnnotationHelper.java
+++ b/hibernate-models-orm/src/main/java/org/hibernate/models/orm/categorize/xml/internal/XmlAnnotationHelper.java
@@ -27,6 +27,7 @@
import org.hibernate.annotations.NaturalIdCache;
import org.hibernate.annotations.OptimisticLock;
import org.hibernate.annotations.Parameter;
+import org.hibernate.annotations.ResultCheckStyle;
import org.hibernate.annotations.RowId;
import org.hibernate.annotations.SQLJoinTableRestriction;
import org.hibernate.annotations.SQLRestriction;
@@ -43,6 +44,7 @@
import org.hibernate.boot.jaxb.mapping.spi.JaxbColumnImpl;
import org.hibernate.boot.jaxb.mapping.spi.JaxbConfigurationParameterImpl;
import org.hibernate.boot.jaxb.mapping.spi.JaxbConvertImpl;
+import org.hibernate.boot.jaxb.mapping.spi.JaxbCustomSqlImpl;
import org.hibernate.boot.jaxb.mapping.spi.JaxbEmbeddedIdImpl;
import org.hibernate.boot.jaxb.mapping.spi.JaxbEntity;
import org.hibernate.boot.jaxb.mapping.spi.JaxbEntityListenerImpl;
@@ -60,6 +62,7 @@
import org.hibernate.boot.jaxb.mapping.spi.JaxbTableImpl;
import org.hibernate.boot.jaxb.mapping.spi.JaxbUserTypeImpl;
import org.hibernate.boot.jaxb.mapping.spi.JaxbUuidGeneratorImpl;
+import org.hibernate.engine.spi.ExecuteUpdateResultCheckStyle;
import org.hibernate.models.ModelsException;
import org.hibernate.models.internal.CollectionHelper;
import org.hibernate.models.internal.StringHelper;
@@ -888,12 +891,41 @@ private static void applySqlRestriction(
}
}
+ static void applyCustomSql(
+ JaxbCustomSqlImpl jaxbCustomSql,
+ MutableAnnotationTarget target,
+ Class annotationType,
+ SourceModelBuildingContext buildingContext) {
+ if ( jaxbCustomSql != null ) {
+ final MutableAnnotationUsage annotation = getOrMakeAnnotation( annotationType, target );
+ annotation.setAttributeValue( "sql", jaxbCustomSql.getValue() );
+ annotation.setAttributeValue( "callable", jaxbCustomSql.isCallable() );
+ applyAttributeIfSpecified( annotation, "table", jaxbCustomSql.getTable() );
+ if ( jaxbCustomSql.getCheck() != null ) {
+ annotation.setAttributeValue( "check", getResultCheckStyle( jaxbCustomSql.getCheck() ) );
+ }
+ }
+ }
+
+ private static ResultCheckStyle getResultCheckStyle(ExecuteUpdateResultCheckStyle style) {
+ switch ( style ) {
+ case NONE:
+ return ResultCheckStyle.NONE;
+ case COUNT:
+ return ResultCheckStyle.COUNT;
+ case PARAM:
+ return ResultCheckStyle.PARAM;
+ default:
+ return null;
+ }
+ }
+
static void applyIdClass(
JaxbIdClassImpl jaxbIdClass,
MutableClassDetails target,
SourceModelBuildingContext buildingContext) {
if ( jaxbIdClass != null ) {
- XmlProcessingHelper.makeAnnotation( IdClass.class, target ).setAttributeValue(
+ getOrMakeAnnotation( IdClass.class, target ).setAttributeValue(
"value",
buildingContext.getClassDetailsRegistry().resolveClassDetails( jaxbIdClass.getClazz() )
);
@@ -933,9 +965,9 @@ static void applyLifecycleCallbacks(
applyLifecycleCallback( lifecycleCallbackContainer.getPostLoad(), PostLoad.class, classDetails );
}
- private static void applyLifecycleCallback(
+ private static void applyLifecycleCallback(
JaxbLifecycleCallback lifecycleCallback,
- Class extends Annotation> lifecycleAnnotation,
+ Class lifecycleAnnotation,
MutableClassDetails classDetails) {
if ( lifecycleCallback != null ) {
final MethodDetails method = classDetails.findMethodByName( lifecycleCallback.getMethodName() );
diff --git a/hibernate-models-orm/src/test/java/org/hibernate/models/orm/xml/complete/SimpleCompleteXmlTests.java b/hibernate-models-orm/src/test/java/org/hibernate/models/orm/xml/complete/SimpleCompleteXmlTests.java
index a837978..4457cd0 100644
--- a/hibernate-models-orm/src/test/java/org/hibernate/models/orm/xml/complete/SimpleCompleteXmlTests.java
+++ b/hibernate-models-orm/src/test/java/org/hibernate/models/orm/xml/complete/SimpleCompleteXmlTests.java
@@ -9,6 +9,8 @@
import java.util.List;
import org.hibernate.annotations.Filter;
+import org.hibernate.annotations.ResultCheckStyle;
+import org.hibernate.annotations.SQLInsert;
import org.hibernate.annotations.SQLRestriction;
import org.hibernate.annotations.SqlFragmentAlias;
import org.hibernate.boot.internal.BootstrapContextImpl;
@@ -81,6 +83,8 @@ void testSimpleCompleteEntity() {
assertThat( sqlRestriction ).isNotNull();
assertThat( sqlRestriction.getAttributeValue( "value" ) ).isEqualTo( "name is not null" );
+ validateSqlInsert( root.getClassDetails().getAnnotationUsage( SQLInsert.class ));
+
validateFilterUsage( root.getClassDetails().getAnnotationUsage( Filter.class ) );
}
}
@@ -97,4 +101,12 @@ private void validateFilterUsage(AnnotationUsage filter) {
.getAttributeValue( "entity" )
.getName() ).isEqualTo( SimpleEntity.class.getName() );
}
+
+ private void validateSqlInsert(AnnotationUsage sqlInsert) {
+ assertThat( sqlInsert ).isNotNull();
+ assertThat( sqlInsert.getAttributeValue( "sql" ) ).isEqualTo( "insert into SimpleEntity(name) values(?)" );
+ assertThat( sqlInsert.getAttributeValue( "callable" ) ).isTrue();
+ assertThat( sqlInsert.getAttributeValue( "check" ) ).isEqualTo( ResultCheckStyle.COUNT );
+ assertThat( sqlInsert.getAttributeValue( "table" ) ).isEqualTo( "SimpleEntity" );
+ }
}
diff --git a/hibernate-models-orm/src/test/resources/mappings/complete/simple-complete.xml b/hibernate-models-orm/src/test/resources/mappings/complete/simple-complete.xml
index c21781a..c5e45ad 100644
--- a/hibernate-models-orm/src/test/resources/mappings/complete/simple-complete.xml
+++ b/hibernate-models-orm/src/test/resources/mappings/complete/simple-complete.xml
@@ -10,6 +10,7 @@
version="3.1">
name is not null
+ insert into SimpleEntity(name) values(?)
diff --git a/hibernate-orm/src/main/resources/org/hibernate/xsd/mapping/mapping-3.1.0.xsd b/hibernate-orm/src/main/resources/org/hibernate/xsd/mapping/mapping-3.1.0.xsd
index ea2ae52..f053c85 100644
--- a/hibernate-orm/src/main/resources/org/hibernate/xsd/mapping/mapping-3.1.0.xsd
+++ b/hibernate-orm/src/main/resources/org/hibernate/xsd/mapping/mapping-3.1.0.xsd
@@ -870,6 +870,11 @@
+
+
+
+
+
@@ -1359,12 +1364,20 @@
-
+
+
+
+
+
+
+
-
+
+
+
+
-
@@ -1849,6 +1862,10 @@
+
+
+
+
@@ -2629,6 +2646,7 @@
+
@@ -2814,6 +2832,10 @@
+
+
+
+