Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hibernate: 1st level cache

Could someone tell me how could I peek into objects being managed by a session in Hibernate?

I am trying to use eclipse debugger and drill into persistenceContext but I am not sure if that is where I would find the objects being managed by hibernate session.

Could someone tell me how to find out the objects that are being managed by Hibernate objects?

Thanks.

like image 807
skip Avatar asked Dec 20 '25 21:12

skip


1 Answers

Are you looking to use this information simply for your own benefit and learning? You won't be able to access the information as far as I know in any sort of standard JPA-approved method.

However, if you're using Hibernate, you could put a breakpoint and dig into Hibernate's implementation of PersistenceContext.java which is called StatefulPersistenceContext.java. There should be a map of entities and collections loaded. You will of course need the Hibernate source code for this.

The fields should be named something like...

private Map entitiesByKey;
private Map proxiesByKey;
private Map collectionsByKey;

EDIT: Don't forget to toggle "Show Logical Structures" in the Eclipse debugger or navigating those maps will drive you insane.

like image 55
Pace Avatar answered Dec 23 '25 07:12

Pace



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!