Sqeezer
Sqeezer

Reputation: 1277

Entity object as HQL parameter

I have the following question, which is not covered in Hibernate documentation. Or I just couldn't find the answer there. Googling doesn't give me details also.

If we use an Entity object as a parameter and bind it to an HQL using Query.setParameter, what happens next?

Thank you in advance!

Upvotes: 3

Views: 2105

Answers (1)

Steve Ebersole
Steve Ebersole

Reputation: 9443

In terms of the SQL it will simply compare using the ids. The entity you bind does not have to be managed within that session as the comment on your question suggests.

Essentially what happens is that Hibernate will attempt to resolve the entity type of the entity instance it is given. It will then use that type to bind the JDBC parameter value, which will write just the identifier. So the assumption here is that the entity instance can resolved to its "entity type". That is usually easy in most situations. Where it gets difficult is in the case of Hibernate-specific "entity name" features.

Upvotes: 2

Related Questions