With Hibernate, how do I load an entity using generics?
Curretly I am doing:
Entity e = (Entity) session.load(Entity.class, 123);
In NHibernate, with generics, I can do:
session.Get<Entity>(123);
What’s the Hibernate equivalent?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Unfortunately, Java doesn’t support Reified Generics yet.
Best what you could do is to wrap it in another convenience method to remove the need to cast:
which can be used as follows: