什么时候使用EntityManager的createQuery()和find()方法? [英] When use createQuery() and find() methods of EntityManager?
问题描述
我想知道这两种方法之间的区别.
I would like to know the difference between on these methods.
何时使用EntityManager的createQuery()
和find()
方法?
When use the createQuery()
and find()
methods of EntityManager ?
它们每个都有什么优点?
What the advantages about each of them ?
谢谢你回答我.
推荐答案
You use find
when you want to look up an entity by primary key. That means you know exactly what you're looking for, you just want to pull it out of the database.
您使用 createQuery
当您要使用条件查找实体或要使用JPQL语句定义要返回的内容时.因此,当您要获取符合某些条件的实体或实体集合时,可以使用查询.
You use createQuery
when you want to find entities using criteria or if you want to use a JPQL statement to define what you get back. So you would use the query when you want to get an entity or collection of entities matching some conditions.
这篇关于什么时候使用EntityManager的createQuery()和find()方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!