hibernate笔记,687页

native sql: session.createNativeQuery

pagination:

Query sqlQuery =
        session.createSQLQuery("select {u.*} from USERS {u}")
                .addEntity("u", User.class);
sqlQuery.setFirstResult(40);
sqlQuery.setMaxResults(20);

Query q = session.createQuery("from Item")
                 .setReadOnly(true);

All Item objects returned by this query are in persistent state, but no snapshot for automatic dirty checking is enabled in the persistence context.

List result = myQuery.list();

Query categoryByName =     session.createQuery("from Category c where c.name like :name");
categoryByName.setString("name", categoryNamePattern);
Iterator categories = categoryByName.iterate();

iterate读非id的field的时候,主要从找cache里找

ScrollableResults itemCursor =  session.createQuery("from Item").scroll();

An  insensitive  cursor  won’t  expose  you  to modified  data  while  the  cursor  is  open  (effectively  guaranteeing  that  no  dirty reads, unrepeatable reads, or phantom reads can slip into your resultset). On the other hand, a sensitive cursor exposes newly committed data and committed modifications  to  you  while  you  work  on  your  resultset.

The Object[]s returned by this query contain a Long at index 0, a String at index
1, and a BigDecimal or MonetaryAmount at index 2. These are scalar values, not
entity  instances.  Therefore,  they  aren’t  in  any  persistent  state,  like  an  entity
instance would be. They aren’t transactional and obviously aren’t checked auto-
matically for dirty state. We call this kind of query a scalar query.

Implicit  joins  are  always  directed  along  many-to-one  or
one-to-one associations, never through a collection-valued association (you can’t
write item.bids.amount).

 

from Item i     left join fetch i.bids where i.description like '%Foo%'

你可能感兴趣的:(Hibernate,职场,笔记,休闲)