File tree Expand file tree Collapse file tree 1 file changed +35
-0
lines changed
hibernate-core/src/main/java/org/hibernate/tool/schema/internal Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -197,6 +197,41 @@ protected void applyTableTypeString(StringBuilder buf) {
197
197
198
198
protected void applyTableCheck (Table table , StringBuilder buf ) {
199
199
if ( dialect .supportsTableCheck () ) {
200
+ if ( !dialect .supportsColumnCheck () ) {
201
+ for ( Column column : table .getColumns () ) {
202
+ // some databases (Maria, SQL Server) don't like multiple 'check' clauses
203
+ final List <CheckConstraint > checkConstraints = column .getCheckConstraints ();
204
+ long anonConstraints = checkConstraints .stream ().filter ( CheckConstraint ::isAnonymous ).count ();
205
+ if ( anonConstraints == 1 ) {
206
+ for ( CheckConstraint constraint : checkConstraints ) {
207
+ buf .append ( "," ).append ( constraint .constraintString ( dialect ) );
208
+ }
209
+ }
210
+ else {
211
+ boolean first = true ;
212
+ for ( CheckConstraint constraint : checkConstraints ) {
213
+ if ( constraint .isAnonymous () ) {
214
+ if ( first ) {
215
+ buf .append ( "," ).append ( " check (" );
216
+ first = false ;
217
+ }
218
+ else {
219
+ buf .append ( " and " );
220
+ }
221
+ buf .append ( constraint .getConstraintInParens () );
222
+ }
223
+ }
224
+ if ( !first ) {
225
+ buf .append ( ")" );
226
+ }
227
+ for ( CheckConstraint constraint : checkConstraints ) {
228
+ if ( constraint .isNamed () ) {
229
+ buf .append ( constraint .constraintString ( dialect ) );
230
+ }
231
+ }
232
+ }
233
+ }
234
+ }
200
235
for ( CheckConstraint constraint : table .getChecks () ) {
201
236
buf .append ( "," ).append ( constraint .constraintString ( dialect ) );
202
237
}
You can’t perform that action at this time.
0 commit comments