daily pastebin goal
44%
SHARE
TWEET

Untitled

a guest May 16th, 2018 97 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. @Override
  2.     @Transactional
  3.     public Author getAuthorById(int id) {
  4.         Session session = sessionFactory.getCurrentSession();
  5.         Author author = session.get(Author.class, id);
  6.         logger.info("Class load: " + author);
  7.         return author;
  8.     }
  9.    
  10. Query query = session.createQuery("from Author where name = :name");
  11. query.setParameter("name", "Howard Phillips Lovecraft");
  12. Author author = query.getSingleResult();
  13.    
  14. CriteriaBuilder builder = session.getCriteriaBuilder();
  15. CriteriaQuery<Author> criteria = builder.createQuery(Author.class);
  16. Root<Author> root = criteria.from(Author.class);
  17. criteria.select(root);
  18. ParameterExpression<String> nameParam = builder.parameter(String.class);
  19. criteria.where(builder.eq(root.get("name"), nameParam));
  20. Query query = session.createQuery(criteria);
  21. Author author = query.getSingleResult();
  22.    
  23. Session session = sessionFactory.getCurrentSession();
  24. String queryString = "from Author where " + name + "= :value";
  25. Query queryObject = session.createQuery(queryString);
  26. queryObject.setParameter("value", value);
  27. List<Author> list = queryObject.list();
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top