Hibernate-4
6.Query languages
Q-A)Why we need a query language in hibernate.
- for join quires.
- for update PK.
- JPQL queries can use in HQL,But HQL queries cant use JPQL.
- SQL queries cant use in JPQL & JPQL queries cant use in SQL.
- SQL include all DDL,DML quires.
- But JPQL & HQL include DML quires.
- JPQL include UPDATE,DELETE,SELECT quires.
- HQL include UPDATE,DELETE,SELECT,INSERT INTO... SELECT quires.
NH Vs JPAH differences in session vs entity manager
Should be considered:-(R):return type
:-(Q):query language
1.Get data
CreateQuery vs CreateQuery
(R)Query/TypeQuery vs Query/TypeQuery
(Q)JPQL/HQL vs JPQL(Cant use for the SQL)
2.List of data
list() vs getResultList()
3.UniqueResult(0 vs getSingleResult()
4.addEntity vs <not define>
5.getNameQuery vs createNamedQuery
6.getNamedNativeQuery Vs CreateNameQuery
Parameters
Using mixture of these parameters is no not a good practice
a)Positional Parameters
use number as parameter
use "?" to represent
Must be positive integer
Gap between 2 parameters should be always 1
Do not want to start 1 (can start like 50,51,52)
b)Named Parameters
use text for represent parameters.
use ":" to represent
Comments
Post a Comment