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?
CreateQuery: Used to create an HQL.
createNamedQuery: Used to define queries with name in mapping file or annotation. See this.
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
精彩评论