开发者

create query in Hibernate

When we have to use

createQuery(String),   

createNamedQuery(String),  

createNativeQuery(String)   

in Hib开发者_如何转开发ernate and what is the difference between them?


  1. CreateQuery: Used to create an HQL.

  2. createNamedQuery: Used to define queries with name in mapping file or annotation. See this.

  3. createNativeQuery: Used to execute native/pure SQL queries. Example


They differ in the meaning of the argument they are called with.

  • createQuery takes an actual JP-QL query as argument.
  • createNamedQuery takes the name of a query as argument, which is defined elsewhere, e.g. with a @javax.persistence.NamedQuery annotation.
  • createNativeQuery is called with a SQL query.


createQuery:

http://docs.jboss.org/hibernate/core/3.6/reference/en-US/html/objectstate.html#objectstate-querying

http://docs.jboss.org/hibernate/core/3.6/reference/en-US/html/queryhql.html

createNamedQuery:

http://www.mkyong.com/hibernate/hibernate-named-query-examples/

http://www.javalobby.org/java/forums/m91885316.html

createNativeQuery:

http://docs.jboss.org/hibernate/core/3.6/reference/en-US/html/querysql.html

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜