开发者

hibernate Query by primary key

I wanna create query by primary key. Supposed I have class primary key, PersonKey, the properties is name and id.

I have Person class, the property is PersonKey, address, DOB.

Now, I wanna search person by primary key.

First, I create instance of PersonKey, and set the name become: joe, and id become:007

can I get the person by ID, by pass t开发者_如何转开发he key variable ???

person.findByKey(someKey); , but the logic do not criteria


Yes you can. Assuming the PersonKey is Serializable, simply pass it to the get method:

PersonKey pk = new PersonKey(007l, "joe");
Person person = (Person) session.get(Person.class, pk);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜