The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.


In the book in 4.4.1 "Retrieving objects by identifier" it says :
get() never returns a proxy.

But in our code, it does.

We use JBoss 4.0.4GA (includes hibernate 3.2.0.cr2) and the code looks like this :

Foo foo = session.get(Foo.class, someID);
session.get(foo.getClass(), foo.getID()); // BOOM

If we run this code twice in a row with the same (String) value of someID, the returned object (foo) in the second case is not of type Foo, but Foo$$EnhancerByCGLIB$$f6f2dbd7.

Therefore the second get() (line commented with BOOM) fails with :
org.hibernate.MappingException: Unknown entity: Foo$$EnhancerByCGLIB$$f6f2dbd7

Any idea what is going on ?
How to avoid the problem ?


(the above code is run inside a Bean, transactions are used)