Web hosting support - 278 APPENDIX B n HIBERNATE TOOLS APPENDIX B

278 APPENDIX B n HIBERNATE TOOLS APPENDIX B n HIBERNATE TOOLS The generated SQL will be visible whenever the HQL query is syntactically valid, allowing you to confirm the basic correctness of the HQL and confirm the sanity of the underlying query at the same time. Once you have a satisfactory HQL query, it can be executed against the database to validate the returned results. Enter the following query in the scratch pad window, and then click the green play button above the editor window. select note as Note_Entry from Note whereid > 10andid < 20 The view shown in Figure B-19 will list the results of the query. Note that the results have been given the correct column heading. Figure B-19. The output from the query Query Parameters While the scratch pad alone is adequate for running stand-alone queries, much of the HQL that you will use in practice in your applications will be parameterized. Consider the following typical query: select owner from Notepad where owner = :username This query uses a named parameter, username, as a placeholder for the actual value. When converted to SQL, this will become a parameter in a prepared statement, and will not be specified until the application is actually running. The Hibernate Console provides the novel feature of allowing you to specify the values of parameters in Hibernate queries of this type.2 This means that you can cut and paste an HQL query from your code into the scratch pad, and test it there without having to edit any of the parameters themselves. If you paste the preceding query into a scratch pad window and try to run it as is, the console will log an appropriate error, warning you that the query parameters have not all been set (currently this appears in the Hibernate Query Result view). On the right-hand side of the perspective s default layout, there is a view called Query Parameters. Adjust the layout so that you can see the three columns within this view, labeled Name, Type, and Value. 2. If you ve ever encountered problems debugging complex SQL queries, in which the process of manually substituting in parameters disguised the cause of the problem during testing, you will understand why we are extremely enthusiastic about this ingenious feature!
You need excellent and relaible webhost company to host your web applications? Then pay a visit to Inexpensive Web Hosting services.

Leave a Reply