At last, after six months of hard work, our Hibernate and JPA Training Course is now available.
It took so long because I wanted to cover all of the major areas of Hibernate and JPA. We can’t cover every single bit of the API (I do encourage you to use the reference manual through the course), but I wanted to make sure that all of the problems that I’ve encountered with Hibernate is there on the course. The best parts of the course are the three chapters towards the end where we look at how Hibernate integrates with real architectures. We look at basic web applications, Spring Applications and EJB Applications and it is surprising how easy it is to run into problems! As always, code is provided and we’re here to support you if you run into problems on the course! The outline is:
- Introduction
- Getting Started
- Persisting Objects
- Configuring Hibernate
- Manipulating Objects (Dirty Checking)
- More on Mapping
- Handling Crashes and Logging
- Relationships
- Collections
- Bi Directional Relations
- Many to Many (really a long worked practical)
- Equals and HashCode
- XML Mappings
- Java Persistence API
- Cascades
- Embedding Objects
- Queries – Part 1
- Queries – Part 2
- Queries – Part 3
- Criteria API – Part 1
- Criteria API – Part 2
- Inheritance
- Detaching and Merging
- Optimistic Locking and Versioning
- Pessimistic Locking
- Performance and Lazy Initialisation
- Tuning Perfomance
- First Level Cache
- Second Level Cache
- Web Applications
- Spring Applications
- EJB/Java EE Applications
- Course Review
Richard I'm working with JPA (Eclipselink) with Netbeans and they create a controller that looks like this:
public class CustomerJpaController implements Serializable {
public CustomerJpaController(UserTransaction utx, EntityManagerFactory emf) {this.utx = utx;this.emf = emf; }
private UserTransaction utx = null; private EntityManagerFactory emf = null;
public EntityManager getEntityManager() { return emf.createEntityManager(); }
public void create(Customer customer) throws RollbackFailureException, Exception {EntityManager em = null;
try {utx.begin();em = getEntityManager();em.persist(customer);utx.commit();} catch (Exception ex) {try {utx.rollback();
} catch (Exception re) {throw new RollbackFailureException("An error occurred attempting to roll back the transaction.", re); }
throw ex;} finally {if (em != null) { em.close();}}}
public void edit(Customer customer) throws NonexistentEntityException, RollbackFailureException, Exception {EntityManager em = null;
try {utx.begin();em = getEntityManager();customer = em.merge(customer);utx.commit();} catch (Exception ex) {try {
utx.rollback();} catch (Exception re) {throw new RollbackFailureException("An error occurred attempting to roll back the transaction.", re); }
String msg = ex.getLocalizedMessage(); if (msg == null || msg.length() == 0) {Long id = customer.getId(); if (findCustomer(id) == null) {
throw new NonexistentEntityException("The customer with id " + id + " no longer exists.");}}throw ex;} finally {
if (em != null) {em.close();}}}
public void destroy(Long id) throws NonexistentEntityException, RollbackFailureException, Exception {EntityManager em = null;
try {utx.begin();em = getEntityManager();Customer customer;try {customer = em.getReference(Customer.class, id);customer.getId(); } catch (EntityNotFoundException enfe) {
throw new NonexistentEntityException("The customer with id " + id + " no longer exists.", enfe);}em.remove(customer);utx.commit();} catch (Exception ex) {
try {utx.rollback(); } catch (Exception re) {throw new RollbackFailureException("An error occurred attempting to roll back the transaction.", re);
}throw ex;} finally {if (em != null) {em.close(); }}}
public List findCustomerEntities() {return findCustomerEntities(true, -1, -1);}
public List findCustomerEntities(int maxResults, int firstResult) {return findCustomerEntities(false, maxResults, firstResult);
}private List findCustomerEntities(boolean all, int maxResults, int firstResult) {EntityManager em = getEntityManager();
try {CriteriaQuery cq = em.getCriteriaBuilder().createQuery();cq.select(cq.from(Customer.class));Query q = em.createQuery(cq);
if (!all) {q.setMaxResults(maxResults); q.setFirstResult(firstResult);} return q.getResultList(); } finally {
em.close();}}
public Customer findCustomer(Long id) {EntityManager em = getEntityManager();try {return em.find(Customer.class, id);
} finally {em.close();}} public int getCustomerCount() {EntityManager em = getEntityManager();
try {CriteriaQuery cq = em.getCriteriaBuilder().createQuery();Root rt = cq.from(Customer.class);
cq.select(em.getCriteriaBuilder().count(rt));Query q = em.createQuery(cq);return ((Long) q.getSingleResult()).intValue();
} finally {em.close();}}}
My question is how do I invoke these methods? Please help me out email: ty@radleaf.com
Hi Sorry Ty I missed your original post. As you can see the text has got mangled by our blogger software. If you're on the training course, could you send a message into the support system and we'll get a proper response back to you.
Hi Ultrasolution, please contact us via the contact us link at http://www.virtualpairprogrammers.com and we can deal with your enquiry there. Many thanks!