質問

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