What does the Hibernate load () method do for non-existent identifiers?

I am a bit confused about JavaDocs on Session.load :

Returns a constant instance of this entity class with the given identifier, assuming that the instance exists. This method can return a proxy instance, which is initialized on demand, when accessing the non-identifier method.

You should not use this method to determine if an instance exists (use get () instead). Use this only to get an instance that you assume exists where there was no actual error.

I understand that I have to use get, but I do not understand what a bit means, which is initialized on demand when using the non-identifier method.

For me, if I have a class and use load(MyClass.class, NonExistingID)and then print the output getId()on the returned instance, it will automatically create a new instance NonExistingIDevery time. Why is this?

Am I just trying to figure out a getId()non-identifying method?

+5
source share
2 answers

" " , - ( ) . load -, , - . , getId - , Hibernate ( , load).

hibernate:

, Hibernate , , , . , get , .

. , , Hibernate, , , , . , - .

, , , bean? , , , , , , . , Hibernate :

org.hibernate.ObjectNotFoundException: : [ № 123]

, , , - , - " ", - .

+5

, :

session.load -, .

session.get null, , .

+6

All Articles