Forums Register Login

Hibernate query cache issue

+Pie Number of slices to send: Send
Hi all,

I am using hibernate and spring for my application. And I am using Hibernate second level cache mechanism with Ehcache.
There is a central database and two different applications running on different JVMs are working on it. One of them is a web aplication which is built using hibernate and spring.

There is one query(Sensor Object) which is actually cached and another query(Badge object) is executed for every object of the first query and this second query is never cached as these objects may be manipulated at the Database by the other application.

The application works very well when I run without manipulating the database. Whenever I make a change in the db for Badge objects the second query does not execute as I can see the sql executed by Hibernate and no data is available at the front end.

The second query for badge objects is executed for every sensor object which is cached whenever there is no change at db for badge data but when the badge data at db is changed the this second query is never executed while the application is running.

Can anyone please help me in finding a way such that the query that is never cached still gets executed even if there is a change in db.

I am caching the sensor objects and not the badge objects.

Please help its an urgent requirement.
+Pie Number of slices to send: Send
How do you signal to your Hibernate application that data in the database has been changed by another app? This isn't something Hibernate can do out the box.
+Pie Number of slices to send: Send
Hi Paul,

Thanks for the reply..

Badge object is never cached so it is always picked from the DB. Yet there is no data coming from db and the query is also not complete when I make the change.

This is a list of SQl queries from hibernate.

- Exec: EV.getSensorsAtFloor()

Hibernate: select evsensor0_.ST_SENSOR_ID as ST1_0_, evsensor0_.ST_SENSOR_TYPE as ST2_0_, evsensor0_.ST_SENSOR_NAME as ST3_0_, evsensor0_.ST_X as ST4_0_, evsensor0_.ST_Y as ST5_0_, evsensor0_.ST_BOUNDING_X1 as ST6_0_, evsensor0_.ST_BOUNDING_Y1 as ST7_0_, evsensor0_.ST_BOUNDING_X2 as ST8_0_, evsensor0_.ST_BOUNDING_Y2 as ST9_0_, evsensor0_.ST_FACILITY_ID as ST10_0_, evsensor0_.ST_FLOOR_ID as ST11_0_ from st_sensor_table evsensor0_ where (evsensor0_.ST_FLOOR_ID in (6)) and (evsensor0_.ST_X is not null) and (evsensor0_.ST_Y is not null) and (evsensor0_.ST_BOUNDING_X1 is not null) and (evsensor0_.ST_BOUNDING_X2 is not null) and (evsensor0_.ST_BOUNDING_Y1 is not null) and (evsensor0_.ST_BOUNDING_Y2 is not null)
Hibernate: select evfacility0_.FM_FACILITY_ID as FM1_3_0_, evfacility0_.FM_FACILITY_NAME as FM2_3_0_ from fm_facility_master evfacility0_ where evfacility0_.FM_FACILITY_ID=?
Hibernate: select evfloor0_.FL_FLOOR_ID as FL1_4_0_, evfloor0_.FL_FLOOR_NAME as FL2_4_0_ from fl_floor evfloor0_ where evfloor0_.FL_FLOOR_ID=?
-----> The First Query which will be cached along with its associations.

Hibernate: select evcategory0_.BT_BDG_TYPE_ID as BT1_2_, evcategory0_.BT_BDG_TYPE as BT2_2_, evcategory0_.BT_ICON as BT3_2_, evcategory0_.BT_PARENT_ID as BT4_2_ from bt_badgetype_master evcategory0_ where evcategory0_.BT_BDG_TYPE_ID in (select evbadge1_.BM_BADGE_TYPE_ID from bm_badge_master evbadge1_ where evbadge1_.BM_BADGE_AT=?) ----> Second query that picks data every time from DB

Asset types:0 ---> I am printing this to see the result. This for the first sensor Object

Hibernate: select evcategory0_.BT_BDG_TYPE_ID as BT1_2_, evcategory0_.BT_BDG_TYPE as BT2_2_, evcategory0_.BT_ICON as BT3_2_, evcategory0_.BT_PARENT_ID as BT4_2_ from bt_badgetype_master evcategory0_ where evcategory0_.BT_BDG_TYPE_ID in (select evbadge1_.BM_BADGE_TYPE_ID from bm_badge_master evbadge1_ where evbadge1_.BM_BADGE_AT=?)
Hibernate: select badges0_.BM_BADGE_TYPE_ID as BM3_1_, badges0_.BM_BADGE_ID as BM1_1_, badges0_.BM_BADGE_ID as BM1_1_0_, badges0_.BM_BADGE_TAG_ID as BM2_1_0_, badges0_.BM_BADGE_TYPE_ID as BM3_1_0_, badges0_.BM_BADGE_ICONPATH as BM4_1_0_, badges0_.BM_BADGE_AT as BM5_1_0_, badges0_.BM_BADGE_PARAM1 as BM6_1_0_, badges0_.BM_BADGE_PARAM2 as BM7_1_0_, badges0_.BM_BADGE_PARAM3 as BM8_1_0_, badges0_.BM_BADGE_PARAM4 as BM9_1_0_, badges0_.BM_BADGE_PARAM5 as BM10_1_0_ from bm_badge_master badges0_ where badges0_.BM_BADGE_TYPE_ID=?

Asset types:1 --> For Second sensor Object
After iteration is complete
No of sensors : 2


Next time when same execution takes place and when I have changed the Badge data the sql is different

Sensor data is cached so the is no call to db for the first query....

- Exec: EV.getSensorsAtFloor()
Asset types:0 ----> I have changed the badge data such that it belongs to this first sensor.
Hibernate: select evcategory0_.BT_BDG_TYPE_ID as BT1_2_0_, evcategory0_.BT_BDG_TYPE as BT2_2_0_, evcategory0_.BT_ICON as BT3_2_0_, evcategory0_.BT_PARENT_ID as BT4_2_0_ from bt_badgetype_master evcategory0_ where evcategory0_.BT_BDG_TYPE_ID=?
---> If compared above this second query is incomplete......
Hibernate: select badges0_.BM_BADGE_TYPE_ID as BM3_1_, badges0_.BM_BADGE_ID as BM1_1_, badges0_.BM_BADGE_ID as BM1_1_0_, badges0_.BM_BADGE_TAG_ID as BM2_1_0_, badges0_.BM_BADGE_TYPE_ID as BM3_1_0_, badges0_.BM_BADGE_ICONPATH as BM4_1_0_, badges0_.BM_BADGE_AT as BM5_1_0_, badges0_.BM_BADGE_PARAM1 as BM6_1_0_, badges0_.BM_BADGE_PARAM2 as BM7_1_0_, badges0_.BM_BADGE_PARAM3 as BM8_1_0_, badges0_.BM_BADGE_PARAM4 as BM9_1_0_, badges0_.BM_BADGE_PARAM5 as BM10_1_0_ from bm_badge_master badges0_ where badges0_.BM_BADGE_TYPE_ID=?
Asset types:0 ---> Badges are not even here
No of sensors : 2 ----> but sensors are read from the cache and it is available for this query.

How does the query not execute completely when I make changes in the db. And this executes when I replace the same data in the db which is only for Badge table....


This is the code..

[ November 20, 2008: Message edited by: viola rotrigues ]
[ November 20, 2008: Message edited by: Paul Sturrock ]
We're all out of roofs. But we still have tiny ads:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 2100 times.
Similar Threads
Hibernate slow on refresh
Relation between Hibernate Query Cache and Second Level Cache
How setCacheable of Query will work
Can I use Hibernate in my RFID based attendance tracking application?
Hibernate Caching
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 12:39:57.