pb00067 wrote:
Are you sure that both operations (insert-query, select-query) are acting within the same session?
Eventually I suggest you to log all jdbc-activities with a JDBC-Logger like p6spy, so you can effectively check if it happens is different sessions (transactions) or not.
If it happens in different sessions, then the select-query might not see the inserted records because of Isolation-settings (READ_COMMITED or higher) due to the fact that the inserted data isn't commited yet.
thanks for the reply. I installed p6spy and gave me back the log file. But how do I know if it uses the same session?
these are the strings of my interest:
Code:
1359633434916|2|1|statement|select count(*) from context where time_slot=34 and day=0;|select count(*) from context where time_slot=34 and day=0;
1359633434916|-1||resultset|select count(*) from context where time_slot=34 and day=0;|count = 0
1359633434922|3|2|statement|insert into context (time_slot, day, weather,events) values (34,0,'sunny','nothing') returning id;|insert into context (time_slot, day, weather,events) values (34,0,'sunny','nothing') returning id;
1359633434922|-1||resultset|insert into context (time_slot, day, weather,events) values (34,0,'sunny','nothing') returning id;|
1359633434950|26|3|statement|insert into context (time_slot, day, weather,events) values (34,0,'sunny','nothing') returning id;|insert into context (time_slot, day, weather,events) values (34,0,'sunny','nothing') returning id;
1359633434951|-1||resultset|insert into context (time_slot, day, weather,events) values (34,0,'sunny','nothing') returning id;|
1359633434955|2|1|statement|insert into context (time_slot, day, weather,events) values (34,0,'sunny','nothing') returning id;|insert into context (time_slot, day, weather,events) values (34,0,'sunny','nothing') returning id;
1359633434956|-1||resultset|insert into context (time_slot, day, weather,events) values (34,0,'sunny','nothing') returning id;|
As you can see the insert of the same context is executed multiple times.
In practice, before I do the insert I check if the entry is already present with the "count" and if "count == 0" proceed with the insert but if i do all this in the same run java the count is always ==0.
PS: i have found a solution. If I set this string <property name="hibernate.cache.use_query_cache">true</property> to false in the hibernate configuration the problem is solved but the execution time increases considerably. Can I disable the cache only for a specific query?