Intellij debugger step over hibernate objects values are empty

Robbo_UK :

When im stepping over hibnerate objects with Intellij the objects appear to be null in the debugging window. Labelled as $$_hibernate_interceptor

So lets say I have some simple code that looks like the following

Subscription subscription  = subscriptionRepository.getOne(1l);
log.info("add breakpoint debug code stopped here")

I would like to see what values that have been returned from the subscriptionRepository and assigned to the subscription object within the the Debug: window.

See screenshot that shows what this looks like on my computer.

enter image description here

As you can see most of the Variable values appear to be empty, however if I do a toString() on the subscription object it will output values that are marked as null in the inteceptor window. So they are not really empty.

So couple of questions here

  • What is $$_hibernate_interceptor

Further findings

The interceptor is only returned when I use the default repository.getOne. If I use findBy or my own findByField it does not call the interceptor and displays the values in the debug window.

What is happening here why does getOne display interceptor but the others dont?

cfstras :

As you can see, the type of your Subscription is Subscription$HibernateProxy$.... This is because Hibernate is lazy-loading properties from the database as you use them.

Until the first time they are accessed, say, in a toString(), they will be null. You can sidestep this easily by adding a variable watch (the little + icon) on "subscription.toString()".

The difference between findById and getOne is that the former returns a lazy proxy, while the latter uses an eagerly loaded object. Some information on why can be found here.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=106607&siteId=1