Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to get all the objects of a particular type which are present in the Session.

 
Rahul Babbar
Ranch Hand
Posts: 210
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I was wondering if there was a way to get all the objects of a particular type present(loaded) in the Hibernate session.

Ex, If i have an entity A, at a certain point in the code, i want to find out which are all the instances of A, that are loaded in the current Hibernate Session.

Regards,
 
Bhagat Singh Rawat
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rahul Babbar wrote:Hi,

I was wondering if there was a way to get all the objects of a particular type present(loaded) in the Hibernate session.

Ex, If i have an entity A, at a certain point in the code, i want to find out which are all the instances of A, that are loaded in the current Hibernate Session.

Regards,


Get all instances and use instance of A object, that way you can find out all the instance of A type.
 
Rahul Babbar
Ranch Hand
Posts: 210
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bhagat Singh Rawat wrote:
Get all instances and use instance of A object, that way you can find out all the instance of A type.


How do i get all instances of various entities present in a Hibernate Session?

I am not sure there is an API for it..
 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmmmm....

An interesting question, although I'm not sure if I understand how it might be applied? I mean, what are you going to do with this information.

I looked at the Session and SessionImpl JavaDoc, but couldn't see any methods that seemed to generate a list of loaded classes:

JavaDoc for SessionImpl

You can always open up the source code? Maybe you can hack the API and see what's going on in the code?

-Cameron McKenzie
 
Rahul Babbar
Ranch Hand
Posts: 210
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes....the question stemmed from the following thought process...

If we do a batch operations(like bulk update) through hibernate, the Hibernate Session will not propagate those changes to the objects already present in the session..

One way to have those objects in session refreshed could be done by getting all the entities of a particular type present in the session and update those in the session(which was done by the bulk update query)...so that the objects in Session remain in sync...even after batching operations...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic