Hi,
Am using Hibernate with spring in POJO framework.
I tried to use dao to execute the following query:
dao.find(" select l , (select count(*) from Message m where m.listing_id=l.id) as Message_received from Listing l where l.subscriber_id='Jane '");
but it returned the following error:
===========================
[ERROR] PARSER - *** ERROR: <AST>:0:0: unexpected AST node: query
===========================
Am not sure what is the problem with this query statement in hibernate. But when I execute it using mysql common without hibernate, this query is able to return me the result as what I expect to see as below:
==================
ID Subscriber Message_received
==================
1 Jane 2
---------------------------------
3 Jane 2
---------------------------------
4 Jane 1
---------------------------------
8 Jane 0
===================
The select statement counts the number of Messages for each listing for Subscriber Jane.
For your information, there exists 2 table as below:
Listing
============
Id Subscriber
============
1 Jane
---------------------
2 Thong
-----------------
3 Jane
-----------------
4 Jane
-----------------
5 Thong
-----------------
6 David
-----------------
7 Jane
===========
Message
=======================
ID Message Listing_id
=======================
1 XXXXXXXX 1
-----------------------------------------
2 YYYYYY 1
-----------------------------------------
3 GJGKJHG 2
-----------------------------------------
4 JJJJJJJJJJ 3
-----------------------------------------
5 JJdfJJJJJJJ 4
----------------------------------------
6 JJJJJJJdfsdf 5
----------------------------------------
7 JJJJJJ 6
----------------------------------------
8 JJJJJJJJasdJJ 3
======================
Listing_id is a the foreign key. Each Listing can have many Messages.
Please guide. Thank you!
meileng
|