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