EJBQL Problem

Hi All,

I have a problem regarding my EJBQL query , and have no idea where the problem is - I am a novice, so any help would be much appreciated.

The EJBQL:

SELECT DISTINCT OBJECT(h)

FROM House h, Location l WHERE l.name = ?1 AND h.bedrooms = ?2

AND h.price BETWEEN ?3 AND ?4

The bedrooms and price conditions work, the problem occurs in the location. For example, I put in Headingley (for location name), 3 (for bedrooms), and 0 (for min price) and 500000 (for max. price). It should display no results, as there are no properties in headingley, however it displays the details of a house located in Harehills which has 3 bedrooms and is between the prices specified. Any ideas why it is ignoring the location condition?

Thanks again,

Pete

[795 byte] By [ppmatthewsa] at [2007-10-2 17:49:20]
# 1
Turn on SQL logging in your persistence.xml,add <properry name="hibernate.show_sql" value="true" /> and check the logged native SQL in you application/server logs
NullPointera at 2007-7-13 19:07:27 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 2
I am not sure but I feel you may have to add another condition in your statement to check if the location of house in House table and location name in Location table are same like h.location=l.name
a_mathewa at 2007-7-13 19:07:27 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 3

Hi All,

Thanks for all the suggestions - and indeed I needed to include a join to the location table. However, I have hit another problem - the EJBQL is now:

SELECT DISTINCT OBJECT(h) FROM House h, Location l

WHERE h.location = l.name

AND l.description = ?1

AND h.bedrooms = ?2

AND (h.price BETWEEN ?3 AND ?4)

But now I recieve the following exception upon deploying:

Error: line(2) column(43): JDO75311: Invalid argument(s) for '='.

; requested operation cannot be completed

Any ideas what this means and how to correct it?

Thanks,

Pete

ppmatthewsa at 2007-7-13 19:07:27 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 4

Please try this query,

SELECT DISTINCT OBJECT(h) FROM Location l, IN (l.houses) As h

WHERE l.name = ?1 AND h.bedrooms = ?2 AND h.price BETWEEN ?3 AND ?4

provided you have two EJBs LocationEJB and HouseEJB and they have a one-to-many relationship and houses is the CMR field name in LocationEJB.

a_mathewa at 2007-7-13 19:07:27 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 5
Thanks so much :):):) It finally works...... Pete
ppmatthewsa at 2007-7-13 19:07:27 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...