Вопрос

I have a UserEntity with an auto-generated field called "id". I am aware that I can retrieve the result that I want by using

hibernateTemplate.find

but I was wondering if there was a better way.

Thanks.

[Edit] My apologies {@JB Nizet}

Expected result: same as what this would give,

hibernateTemplate.find("SELECT user FROM UserEntity user WHERE user.id = ?", id);

where id is a PK in my table.

Это было полезно?

Решение

The correct way of getting an entity by ID is to use Session.get() (native Hibernate API), or HibernateTemplate.get() (HibernateTemplate api).

Simply reading the javadoc would have told you that.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top