I am trying to run a SQL query in Hibernate. I am using its documentation. Because of some unknown values i am trying to do inside the Source code.
See this below SQL-Query configuration. How to re-write it in source code itself!! I tried this
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();
What i am trying to do with the above query is, it should map person.ID & 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].
In JDBC the columns of resultset, for the above query looks like
NAME, AGE, SEX, STREET, CITY, STATE, ZIP
But its not working it says, address columns in the query were not found. Is there any syntax error in my version of query!!
Query Declaration in mapping file;
<sql-query name="personsWith">
<return alias="person" class="eg.Person"/>
<return-join alias="address" property="person.mailingAddress"/>
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
</sql-query>
Thanks