Domanda

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.

È stato utile?

Soluzione

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top