0

I have a query that is not producing any results even though there is definitely data in the underlying database corresponding with the query. The query is being run by Hibernate, and I want to validate it by running the query directly in MySQL. How can I translate from Hibernate to SQL so that I can see if the query produces any results?

Here is the Hibernate query that the Eclipse console says is being run:

select
 drugword0_.name as name1_12_2_,
 concepts1_.word as word1_12_4_,
 drugconcep2_.rxcui as rxcui2_13_4_,
 drugconcep2_.rxcui as rxcui1_10_0_,
 atoms3_.rxcui as rxcui3_10_5_,
 atoms3_.rxaui as rxaui1_39_5_,
 atoms3_.rxaui as rxaui1_39_1_,
 atoms3_.rxcui as rxcui3_39_1_,
 atoms3_.str as str2_39_1_ 
from drugwords drugword0_
 left outer join drugwordsconsoJunction concepts1_ on drugword0_.name=concepts1_.word
 left outer join drugconcepts drugconcep2_ on concepts1_.rxcui=drugconcep2_.rxcui
 left outer join rxnconso atoms3_ on drugconcep2_.rxcui=atoms3_.rxcui where drugword0_.name=?

How do I convert that Hibernate query into working syntax for a sql query of a MySQL database? And why do you think my Hibernate query is not returning any results? Are the Hibernate mappings set up incorrectly?

halfer
  • 19,824
  • 17
  • 99
  • 186
CodeMed
  • 9,527
  • 70
  • 212
  • 364
  • possible duplicate of [Hibernate show real SQL](http://stackoverflow.com/questions/2536829/hibernate-show-real-sql) – Luiggi Mendoza Mar 26 '14 at 21:38
  • This question featured various external links to image hosts and file lockers. Unfortunately all those resources no longer work. For the time being I am voting to put the question on hold, since the post no longer contains a [mcve]. In the unlikely event the question can be repaired, we can reopen again. – halfer Jul 17 '23 at 18:04

1 Answers1

0

ORMs sometimes have a rather unique view on how to translate their query language to SQL, which may lead to various issues ranging from slow queries to odd or absent results.

Therefore I'd advise you to activate the query log (see here or here), that will be the SQL that actually gets sent to the server.

Community
  • 1
  • 1
fvu
  • 32,488
  • 6
  • 61
  • 79
  • Thank you for taking the time to answer. The links you sent do not explain key steps for someone who has never used the technologies before. Are you able to write out explicit instructions for someone who is new to hibernate and MySQL? – CodeMed Mar 26 '14 at 21:42
  • Actually both linked answers also contain links to the Hibernate help where configuring logging is explained: http://docs.jboss.org/hibernate/core/4.1/manual/en-US/html/ch03.html#configuration-logging ... – fvu Mar 26 '14 at 21:46