Skip to content

Instantly share code, notes, and snippets.

@przodownikR1
Created June 26, 2016 22:46
Show Gist options
  • Save przodownikR1/9f4e6ff5960a99449a7efcd4023e551b to your computer and use it in GitHub Desktop.
Save przodownikR1/9f4e6ff5960a99449a7efcd4023e551b to your computer and use it in GitHub Desktop.
Session session = getSession();
Transaction tx = null;
tx = session.beginTransaction();
Book book = (Book)session.get(Book.class, new Long(1));
String name = (String) session.createQuery("select b.name from bkch b where b.isbn = :isbn").setParameter("isbn", book.getIsbn()).uniqueResult();
System.out.println("book Name- "+name);
tx.commit();
session.close();
//Read Committed to Repeatable Read comes with scalability issues
Session session = getSession();
Transaction tx = null;
tx = session.beginTransaction();
Book book = (Book)session.get(Book.class, new Long(1));
session.lock(book, LockMode.UPGRADE);
String name = (String) session.createQuery("select b.name from bkch b where b.isbn = :isbn").setParameter("isbn", book.getIsbn()).uniqueResult();
System.out.println("book Name- "+name);
tx.commit();
session.close();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment