tag:blogger.com,1999:blog-6402887293870911985.post1714165347354157810..comments2023-06-19T06:10:58.458-07:00Comments on Richard Chesterwood's Blog: Hibernate and JPA Training Course - new releaseRichard Chesterwoodhttp://www.blogger.com/profile/04747758278892300028noreply@blogger.comBlogger3125tag:blogger.com,1999:blog-6402887293870911985.post-59848522940393219962013-10-04T04:46:06.476-07:002013-10-04T04:46:06.476-07:00Hi Ultrasolution, please contact us via the contac...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!Richard Chesterwoodhttps://www.blogger.com/profile/04747758278892300028noreply@blogger.comtag:blogger.com,1999:blog-6402887293870911985.post-70221252143739841012013-07-23T03:32:18.335-07:002013-07-23T03:32:18.335-07:00Hi Sorry Ty I missed your original post. As you ca...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.Richard Chesterwoodhttps://www.blogger.com/profile/04747758278892300028noreply@blogger.comtag:blogger.com,1999:blog-6402887293870911985.post-32331609005290007852013-06-14T12:40:14.581-07:002013-06-14T12:40:14.581-07:00Richard I'm working with JPA (Eclipselink) wit...Richard I'm working with JPA (Eclipselink) with Netbeans and they create a controller that looks like this:<br />public class CustomerJpaController implements Serializable {<br /> public CustomerJpaController(UserTransaction utx, EntityManagerFactory emf) {this.utx = utx;this.emf = emf; }<br /> private UserTransaction utx = null; private EntityManagerFactory emf = null;<br /> public EntityManager getEntityManager() { return emf.createEntityManager(); }<br /> public void create(Customer customer) throws RollbackFailureException, Exception {EntityManager em = null;<br /> try {utx.begin();em = getEntityManager();em.persist(customer);utx.commit();} catch (Exception ex) {try {utx.rollback();<br /> } catch (Exception re) {throw new RollbackFailureException("An error occurred attempting to roll back the transaction.", re); }<br /> throw ex;} finally {if (em != null) { em.close();}}}<br /> public void edit(Customer customer) throws NonexistentEntityException, RollbackFailureException, Exception {EntityManager em = null;<br /> try {utx.begin();em = getEntityManager();customer = em.merge(customer);utx.commit();} catch (Exception ex) {try {<br /> utx.rollback();} catch (Exception re) {throw new RollbackFailureException("An error occurred attempting to roll back the transaction.", re); }<br /> String msg = ex.getLocalizedMessage(); if (msg == null || msg.length() == 0) {Long id = customer.getId(); if (findCustomer(id) == null) {<br /> throw new NonexistentEntityException("The customer with id " + id + " no longer exists.");}}throw ex;} finally {<br /> if (em != null) {em.close();}}}<br /> public void destroy(Long id) throws NonexistentEntityException, RollbackFailureException, Exception {EntityManager em = null;<br /> try {utx.begin();em = getEntityManager();Customer customer;try {customer = em.getReference(Customer.class, id);customer.getId(); } catch (EntityNotFoundException enfe) {<br /> throw new NonexistentEntityException("The customer with id " + id + " no longer exists.", enfe);}em.remove(customer);utx.commit();} catch (Exception ex) {<br /> try {utx.rollback(); } catch (Exception re) {throw new RollbackFailureException("An error occurred attempting to roll back the transaction.", re);<br /> }throw ex;} finally {if (em != null) {em.close(); }}}<br /> public List findCustomerEntities() {return findCustomerEntities(true, -1, -1);}<br /> public List findCustomerEntities(int maxResults, int firstResult) {return findCustomerEntities(false, maxResults, firstResult);<br /> }private List findCustomerEntities(boolean all, int maxResults, int firstResult) {EntityManager em = getEntityManager();<br /> try {CriteriaQuery cq = em.getCriteriaBuilder().createQuery();cq.select(cq.from(Customer.class));Query q = em.createQuery(cq);<br /> if (!all) {q.setMaxResults(maxResults); q.setFirstResult(firstResult);} return q.getResultList(); } finally {<br /> em.close();}}<br /> public Customer findCustomer(Long id) {EntityManager em = getEntityManager();try {return em.find(Customer.class, id);<br /> } finally {em.close();}} public int getCustomerCount() {EntityManager em = getEntityManager();<br /> try {CriteriaQuery cq = em.getCriteriaBuilder().createQuery();Root rt = cq.from(Customer.class);<br /> cq.select(em.getCriteriaBuilder().count(rt));Query q = em.createQuery(cq);return ((Long) q.getSingleResult()).intValue();<br /> } finally {em.close();}}}<br /> My question is how do I invoke these methods? Please help me out email: ty@radleaf.comAnonymousnoreply@blogger.com