This week's book giveaway is in the JavaScript forum.
We're giving away four copies of JavaScript Promises Essentials and have Rami Sarieddine on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes Hibernate query cache issue Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate query cache issue" Watch "Hibernate query cache issue" New topic
Author

Hibernate query cache issue

Sneha N Rao
Greenhorn

Joined: Sep 18, 2008
Posts: 4
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.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

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.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Sneha N Rao
Greenhorn

Joined: Sep 18, 2008
Posts: 4
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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Hibernate query cache issue