File tree Expand file tree Collapse file tree 3 files changed +37
-3
lines changed
hibernate-community-dialects/src/main/java/org/hibernate/community/dialect
hibernate-core/src/main/java/org/hibernate Expand file tree Collapse file tree 3 files changed +37
-3
lines changed Original file line number Diff line number Diff line change @@ -1014,4 +1014,8 @@ public boolean supportsRowValueConstructorSyntaxInInList() {
10141014 return false ;
10151015 }
10161016
1017+ @ Override
1018+ public boolean requiresColumnListInCreateView () {
1019+ return true ;
1020+ }
10171021}
Original file line number Diff line number Diff line change @@ -2927,12 +2927,23 @@ public String getCrossReferenceParentTableFilter(){
29272927 * The syntax used to add a primary key constraint to a table.
29282928 *
29292929 * @param constraintName The name of the PK constraint.
2930- * @return The "add PK" fragment
2930+ *
2931+ * @apiNote Currently unused, since we never use {@code alter table}
2932+ * to add a primary key constraint.
29312933 */
29322934 public String getAddPrimaryKeyConstraintString (String constraintName ) {
29332935 return " add constraint " + constraintName + " primary key " ;
29342936 }
29352937
2938+ /**
2939+ * Is a list of column names required in the {@code create view} statement?
2940+ *
2941+ * @since 7.1
2942+ */
2943+ public boolean requiresColumnListInCreateView () {
2944+ return false ;
2945+ }
2946+
29362947 /**
29372948 * The {@link SqmMultiTableMutationStrategy} to use when not specified by
29382949 * {@link org.hibernate.query.spi.QueryEngineOptions#getCustomSqmMultiTableMutationStrategy}.
Original file line number Diff line number Diff line change 3333import org .hibernate .type .SqlTypes ;
3434
3535import static java .util .Collections .addAll ;
36+ import static java .util .Comparator .comparing ;
3637import static org .hibernate .internal .util .StringHelper .EMPTY_STRINGS ;
3738import static org .hibernate .tool .schema .internal .ColumnDefinitions .appendColumn ;
3839
@@ -64,8 +65,26 @@ public String[] getSqlCreateStrings(
6465 final String viewQuery = table .getViewQuery ();
6566 if ( viewQuery != null ) {
6667 createTable .append ("create view " )
67- .append ( formattedTableName )
68- .append (" as " )
68+ .append ( formattedTableName );
69+ if ( dialect .requiresColumnListInCreateView () ) {
70+ createTable .append (" (" );
71+ var sortedColumns =
72+ table .getColumns ().stream ()
73+ .sorted ( comparing ( c -> viewQuery .indexOf ( c .getQuotedName ( dialect ) ) ) )
74+ .toList ();
75+ boolean isFirst = true ;
76+ for ( Column column : sortedColumns ) {
77+ if ( isFirst ) {
78+ isFirst = false ;
79+ }
80+ else {
81+ createTable .append ( ", " );
82+ }
83+ createTable .append ( column .getQuotedName ( dialect ) );
84+ }
85+ createTable .append (")" );
86+ }
87+ createTable .append (" as " )
6988 .append ( viewQuery );
7089 }
7190 else {
You can’t perform that action at this time.
0 commit comments