Skip to content

Commit 1287d93

Browse files
committed
HHH-15102 allow -- style comments in native SQL query
1 parent 39f5946 commit 1287d93

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

hibernate-core/src/main/java/org/hibernate/engine/jdbc/internal/BasicFormatterImpl.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,16 @@ public String perform() {
6969

7070
while ( tokens.hasMoreTokens() ) {
7171
token = tokens.nextToken();
72-
lcToken = token.toLowerCase(Locale.ROOT);
7372

73+
if ( "-".equals(token) && result.toString().endsWith("-") ) {
74+
do {
75+
result.append( token );
76+
token = tokens.nextToken();
77+
}
78+
while ( !"\n".equals( token ) && tokens.hasMoreTokens() );
79+
}
80+
81+
lcToken = token.toLowerCase(Locale.ROOT);
7482
switch (lcToken) {
7583

7684
case "'":

hibernate-core/src/test/java/org/hibernate/orm/test/sql/hand/query/NativeSQLQueriesTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -836,6 +836,12 @@ public void testAddJoinForManyToMany(SessionFactoryScope scope) {
836836
);
837837
}
838838

839+
@Test @JiraKey( "HHH-15102" )
840+
@SkipForDialect(dialectClass = MySQLDialect.class, matchSubTypes = true)
841+
public void testCommentInSQLQuery(SessionFactoryScope scope) {
842+
scope.inTransaction( s -> s.createNativeQuery( "select sum(1) --count(*), effectively\nfrom ORGANIZATION" ).getSingleResult() );
843+
}
844+
839845
@Test
840846
public void testTextTypeInSQLQuery(SessionFactoryScope scope) {
841847
String description = buildLongString( 15000, 'a' );

0 commit comments

Comments
 (0)