15
15
import java .util .Map ;
16
16
17
17
import org .hibernate .QueryException ;
18
+ import org .hibernate .Session ;
18
19
import org .hibernate .dialect .AbstractHANADialect ;
19
20
import org .hibernate .dialect .DB2Dialect ;
20
21
import org .hibernate .dialect .H2Dialect ;
63
64
import antlr .RecognitionException ;
64
65
import antlr .collections .AST ;
65
66
67
+ import static org .hibernate .testing .junit4 .ExtraAssertions .assertTyping ;
66
68
import static org .junit .Assert .assertEquals ;
67
69
import static org .junit .Assert .assertFalse ;
68
70
import static org .junit .Assert .assertNotNull ;
69
71
import static org .junit .Assert .assertNull ;
70
72
import static org .junit .Assert .assertTrue ;
73
+ import static org .junit .Assert .fail ;
71
74
72
75
/**
73
76
* Tests cases where the AST based query translator and the 'classic' query translator generate identical SQL.
@@ -107,6 +110,38 @@ protected void cleanupTest() throws Exception {
107
110
super .cleanupTest ();
108
111
}
109
112
113
+ @ Test
114
+ @ TestForIssue (jiraKey = "HHH-2187" )
115
+ public void testBogusQuery () {
116
+ try {
117
+ QueryTranslatorImpl translator = createNewQueryTranslator ( "bogus" );
118
+ fail ( "This should have failed with a QueryException" );
119
+ }
120
+ catch ( Throwable t ) {
121
+ assertTyping ( QueryException .class , t );
122
+ }
123
+ }
124
+
125
+ @ Test
126
+ @ TestForIssue (jiraKey = "HHH-2187" )
127
+ public void testBogusCreateQuery () {
128
+ Session session = openSession ();
129
+ try {
130
+ session .beginTransaction ();
131
+ session .createQuery ( "Bogus" );
132
+ fail ( "This should have failed with an IllegalArgumentException" );
133
+ }
134
+ catch ( IllegalArgumentException e ) {
135
+ if ( session .getTransaction ().isActive () ) {
136
+ session .getTransaction ().rollback ();
137
+ }
138
+ assertTyping ( QueryException .class , e .getCause () );
139
+ }
140
+ finally {
141
+ session .close ();
142
+ }
143
+ }
144
+
110
145
@ Test
111
146
public void testModulo () {
112
147
assertTranslation ( "from Animal a where a.bodyWeight % 2 = 0" );
@@ -133,6 +168,7 @@ public void testRowValueConstructorSyntaxInInList2() {
133
168
PostgreSQL81Dialect .class ,
134
169
MySQLDialect .class
135
170
} )
171
+
136
172
public void testRowValueConstructorSyntaxInInListBeingTranslated () {
137
173
QueryTranslatorImpl translator = createNewQueryTranslator ("from LineItem l where l.id in (?)" );
138
174
assertInExist ("'in' should be translated to 'and'" , false , translator );
0 commit comments