Sneha N Rao

Greenhorn
+ Follow
since Sep 18, 2008
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Sneha N Rao

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 ]
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.
hi friends,
I found out how to do it now.
This association is nothing but a parent and child association. And child and parent are both associated hence there is no change in the POJOs. Slight changes in the mapping xml.

Mapping xml:
Floor-
<hibernate-mapping default-access="field">
<class name="com.spring.orm.FloorBean" table="fl_floor">
<id name="Id" column="FL_FLOOR_ID" >
<generator class="native" />
</id>
<many-to-one name="facility" class="com.spring.orm.FacilityBean" column="FL_FACILITY_ID"/>
</class>
</hibernate-mapping>

The column that stores the facility id is a association with Facility object in the FloorBean class.

Facility-
<hibernate-mapping default-access="field">
<class name="com.spring.orm.FacilityBean" table="fm_facility_master">
<id name="Id" column="FM_FACILITY_ID" >
<generator class="native" />
</id>
<set name="floors" inverse="true" lazy="false" cascade="none">
<key column="FL_FACILITY_ID"/>
<one-to-many class="com.spring.orm.FloorBean"/>
</set>
</class>
</hibernate-mapping>

By setting inverse="true" and cascade="none" both parent and child can be inserted independently. And association still persists.
This is the link where associations are explained very well.
http://www.neeraj.name/43/hibernate-association-behind-the-scene-action

Hello all,
I ve recently started working on Hibernate. I have queries related to persisting collections and their associations.

My application has two POJOs FacilityBean and FloorBean mapping to entities Facility and Floor. FacilityBean has a set of floors as I want the set of floors associated with the facility to be retrieved along with it. And Floor has a Facility object as every floor belongs to a facility (there are no foreign keys involved).

Mapping Xml is like this:

Facility :
<hibernate-mapping default-access="field">
<class name="com.spring.orm.FacilityBean" table="fm_facility_master">
<id name="Id" column="FM_FACILITY_ID" >
<generator class="native" />
</id>
<property name="parent" column="FM_FACILITY_PARENT_ID" />
......
<property name="default_loc" column="FM_DEFAULT_LOC" />

<set name="floors" lazy="false" table="facility_floor" cascade="none">
<key column="FM_FACILITY_ID"/>
<many-to-many column="FL_FLOOR_ID" unique="true"
class="com.spring.orm.FloorBean"/>
</set>
</class>
</hibernate-mapping>

Floor:

<hibernate-mapping default-access="field">
<class name="com.spring.orm.FloorBean" table="fl_floor">
<id name="Id" column="FL_FLOOR_ID" >
<generator class="native" />
</id>
<property name="floorName" type="java.lang.String" column="FL_FLOOR_NAME"/>
<property name="facilityId" column="FL_FACILITY_ID"/>

<join table="facility_floor" inverse="true" optional="true">
<key column="FL_FLOOR_ID"/>
<many-to-one name="facility" column="FM_FACILITY_ID" cascade="all" not-null="true"/>
</join>
</class>
</hibernate-mapping>

I can persist the collection only when i am inserting both the entities together after setting the set of floors.
I want to insert a new floor alone and also update the association table facility_floor like insert new floor object and the FM_FACILITY_ID and the FL_FLOOR_ID fields gets updated in the association table facility_floor.


Can anyone please help me to know how I can do this.
I believe that hibernate will insert data into the association join table only when new entries of the entities like facility and floor are inserted together. Is there a way where I can insert floor object with existing facility and persist this as floors are added later to a facility.
Please help.
Thanks in advance,
Viola

[ September 18, 2008: Message edited by: viola rotrigues ]
[ September 18, 2008: Message edited by: viola rotrigues ]