Note that there are some explanatory texts on larger screens.

plurals
  1. POHow this SQL Query in hbm.xml file can be written in source code?
    text
    copied!<p>I am trying to run a SQL query in Hibernate. I am using its <a href="http://docs.jboss.org/hibernate/stable/core/reference/en/html/querysql.html#d0e14492" rel="nofollow">documentation</a>. Because of some unknown values i am trying to do inside the Source code.</p> <p>See this below SQL-Query configuration. How to re-write it in source code itself!! I tried this </p> <p><code>personList = session.createSQLQuery("SELECT person.NAME, person.AGE, person.SEX, address.STREET, address.CITY, address.STATE, address.ZIP FROM person JOIN address WHERE person.ID = address.PERSON_ID").addEntity(Person.class).addEntity(Address.class).list();</code></p> <p>What i am trying to do with the above query is, it should map person.ID &amp; PERSON_ID. If it matches, then fetch the other columns in the ADDRESS[STREET, CITY, STATE, ZIP] table with the PERSON table columns[NAME, AGE, SEX].</p> <p>In JDBC the columns of resultset, for the above query looks like </p> <p><code>NAME, AGE, SEX, STREET, CITY, STATE, ZIP</code></p> <p>But its not working it says, address columns in the query were not found. Is there any syntax error in my version of query!!</p> <p><strong>Query Declaration in mapping file</strong>;</p> <pre><code>&lt;sql-query name="personsWith"&gt; &lt;return alias="person" class="eg.Person"/&gt; &lt;return-join alias="address" property="person.mailingAddress"/&gt; SELECT person.NAME AS {person.name}, person.AGE AS {person.age}, person.SEX AS {person.sex}, address.STREET AS {address.street}, address.CITY AS {address.city}, address.STATE AS {address.state}, address.ZIP AS {address.zip} FROM PERSON person JOIN ADDRESS address ON person.ID = address.PERSON_ID &lt;/sql-query&gt; </code></pre> <p>Thanks</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload