Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/jsf/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JSF-Datamodel&JPA父级用于离开导航。如何?_Jsf_Jpa_Netbeans_Crud_Java Ee 5 - Fatal编程技术网

JSF-Datamodel&JPA父级用于离开导航。如何?

JSF-Datamodel&JPA父级用于离开导航。如何?,jsf,jpa,netbeans,crud,java-ee-5,Jsf,Jpa,Netbeans,Crud,Java Ee 5,我的web应用程序是一个基于JSF2.0/JPA的CRUD web应用程序,使用JavaEE5和JDK1.6。在Glassfish 3.1上运行。IDE是Netbeans 7.0。我不使用EJB,也不使用CDI 问题 我现在可以实现的是在我的实体上执行CRUD。这很好。对于我拥有的每个实体: 列出datatable中该实体的所有Datamodel项的List.xhtml Create.xhtml创建新项的表单 View.xhtml用于查看项目的表单 Edit.xhtml用于编辑项目的表单 结构

我的web应用程序是一个基于JSF2.0/JPA的CRUD web应用程序,使用JavaEE5和JDK1.6。在Glassfish 3.1上运行。IDE是Netbeans 7.0。我不使用EJB,也不使用CDI

问题 我现在可以实现的是在我的实体上执行CRUD。这很好。对于我拥有的每个实体:

列出datatable中该实体的所有Datamodel项的List.xhtml Create.xhtml创建新项的表单 View.xhtml用于查看项目的表单 Edit.xhtml用于编辑项目的表单 结构

实体包:实体。 控制器包:jpa控制器Javax持久性。。。 jsf包:每个实体会话作用域的托管bean。 但主要问题是父叶导航。我希望我的webapp与netbeans7.0附带的演示应用程序agilescrumtoys做同样的事情。或SpringFuse的演示webapp,否则:

例如:当你在一个列表中显示一个作者列表时,你有最后一个放置三个作者的位置,用于编辑、查看和删除所选行。 我想做的是在同一列中添加另一个,使我能够查看与所选行相关的子对象集合。 因此,我想显示一个特定作家所写的书的列表

作者1------*书一对多关系

当用户单击 它将其转发到/book/List.xhtml,此时将显示所选WRITEr行的列表。依此类推,从图书数据表中,从给定的行中,我单击以获取给定图书的参考文献列表。 @Matt给出的提示是使用《托管bean》一书中的一个方法:

public showBooksForWriter(Writer writer) {
// TODO: get the selected writer
// Get the list of books for the selected writer
return "/book/List";  // Outcome
}
并且认为:

<h:datatable value="#{writerController.items}" var="w">
.....
<h:column>
<h:commandButton action="#{bookController.showBooksForWriter(w}" value="Show Books For Writer"/>
</h:column>
....
</h:datatable>
//这里还有其他进口商品

@ManagedBean(name = "writerController")
@SessionScoped
public class WriterController implements Serializable {

    @Resource
    private UserTransaction utx = null;
    @PersistenceUnit(unitName = "writerPU")
    private EntityManagerFactory emf = null;
    private Writer current;
    private DataModel items = null;
    private WriterJpaController jpaController = null;
    private PaginationHelper pagination;
    private int selectedItemIndex;

    public WriterController() {
    }

    public Writer getSelected() {
        if (current == null) {
            current = new Writer();
            selectedItemIndex = -1;
        }
        return current;
    }

    private WriterJpaController getJpaController() {
        if (jpaController == null) {
            jpaController = new WriterJpaController(utx, emf);
        }
        return jpaController;
    }

    public PaginationHelper getPagination() {
        if (pagination == null) {
            pagination = new PaginationHelper(10) {

                @Override
                public int getItemsCount() {
                    return getJpaController().getWriterCount();
                }

                @Override
                public DataModel createPageDataModel() {
                    return new ListDataModel(getJpaController().findWriterEntities(getPageSize(), getPageFirstItem()));
                }
            };
        }
        return pagination;
    }

    public String prepareList() {
        recreateModel();
        return "List";
    }

    public String prepareView() {
        current = (Writer) getItems().getRowData();
        selectedItemIndex = pagination.getPageFirstItem() + getItems().getRowIndex();
        return "View";
    }

    public String prepareCreate() {
        current = new Writer();
        selectedItemIndex = -1;
        return "Create";
    }

    public String create() {
        try {
            getJpaController().create(current);
            JsfUtil.addSuccessMessage(ResourceBundle.getBundle("/Bundle").getString("WriterCreated"));
            return prepareCreate();
        } catch (Exception e) {
            JsfUtil.addErrorMessage(e, ResourceBundle.getBundle("/Bundle").getString("PersistenceErrorOccured"));
            return null;
        }
    }

    public String prepareEdit() {
        current = (Writer) getItems().getRowData();
        selectedItemIndex = pagination.getPageFirstItem() + getItems().getRowIndex();
        return "Edit";
    }

    public String update() {
        try {
            getJpaController().edit(current);
            JsfUtil.addSuccessMessage(ResourceBundle.getBundle("/Bundle").getString("WriterUpdated"));
            return "View";
        } catch (Exception e) {
            JsfUtil.addErrorMessage(e, ResourceBundle.getBundle("/Bundle").getString("PersistenceErrorOccured"));
            return null;
        }
    }

    public String destroy() {
        current = (Writer) getItems().getRowData();
        selectedItemIndex = pagination.getPageFirstItem() + getItems().getRowIndex();
        performDestroy();
        recreateModel();
        return "List";
    }

    public String destroyAndView() {
        performDestroy();
        recreateModel();
        updateCurrentItem();
        if (selectedItemIndex >= 0) {
            return "View";
        } else {
            // all items were removed - go back to list
            recreateModel();
            return "List";
        }
    }

    private void performDestroy() {
        try {
            getJpaController().destroy(current.getWriterid());
            JsfUtil.addSuccessMessage(ResourceBundle.getBundle("/Bundle").getString("WriterDeleted"));
        } catch (Exception e) {
            JsfUtil.addErrorMessage(e, ResourceBundle.getBundle("/Bundle").getString("PersistenceErrorOccured"));
        }
    }

    private void updateCurrentItem() {
        int count = getJpaController().getWriterCount();
        if (selectedItemIndex >= count) {
            // selected index cannot be bigger than number of items:
            selectedItemIndex = count - 1;
            // go to previous page if last page disappeared:
            if (pagination.getPageFirstItem() >= count) {
                pagination.previousPage();
            }
        }
        if (selectedItemIndex >= 0) {
            current = getJpaController().findWriterEntities(1, selectedItemIndex).get(0);
        }
    }

    public DataModel getItems() {
        if (items == null) {
            items = getPagination().createPageDataModel();
        }
        return items;
    }

    private void recreateModel() {
        items = null;
    }

    public String next() {
        getPagination().nextPage();
        recreateModel();
        return "List";
    }

    public String previous() {
        getPagination().previousPage();
        recreateModel();
        return "List";
    }

    public SelectItem[] getItemsAvailableSelectMany() {
        return JsfUtil.getSelectItems(getJpaController().findWriterEntities(), false);
    }

    public SelectItem[] getItemsAvailableSelectOne() {
        return JsfUtil.getSelectItems(getJpaController().findWriterEntities(), true);
    }

    @FacesConverter(forClass = Writer.class)
    public static class WriterControllerConverter implements Converter {

        public Object getAsObject(FacesContext facesContext, UIComponent component, String value) {
            if (value == null || value.length() == 0) {
                return null;
            }
            WriterController controller = (WriterController) facesContext.getApplication().getELResolver().
                    getValue(facesContext.getELContext(), null, "writerController");
            return controller.getJpaController().findWriter(getKey(value));
        }

        java.lang.Integer getKey(String value) {
            java.lang.Integer key;
            key = Integer.valueOf(value);
            return key;
        }

        String getStringKey(java.lang.Integer value) {
            StringBuffer sb = new StringBuffer();
            sb.append(value);
            return sb.toString();
        }

        public String getAsString(FacesContext facesContext, UIComponent component, Object object) {
            if (object == null) {
                return null;
            }
            if (object instanceof Writer) {
                Writer o = (Writer) object;
                return getStringKey(o.getWriterid());
            } else {
                throw new IllegalArgumentException("object " + object + " is of type " + object.getClass().getName() + "; expected type: " + WriterController.class.getName());
            }
        }
    }
}
public class JsfUtil {

    public static SelectItem[] getSelectItems(List<?> entities, boolean selectOne) {
        int size = selectOne ? entities.size() + 1 : entities.size();
        SelectItem[] items = new SelectItem[size];
        int i = 0;
        if (selectOne) {
            items[0] = new SelectItem("", "---");
            i++;
        }
        for (Object x : entities) {
            items[i++] = new SelectItem(x, x.toString());
        }
        return items;
    }

    public static void addErrorMessage(Exception ex, String defaultMsg) {
        String msg = ex.getLocalizedMessage();
        if (msg != null && msg.length() > 0) {
            addErrorMessage(msg);
        } else {
            addErrorMessage(defaultMsg);
        }
    }

    public static void addErrorMessages(List<String> messages) {
        for (String message : messages) {
            addErrorMessage(message);
        }
    }

    public static void addErrorMessage(String msg) {
        FacesMessage facesMsg = new FacesMessage(FacesMessage.SEVERITY_ERROR, msg, msg);
        FacesContext.getCurrentInstance().addMessage(null, facesMsg);
    }

    public static void addSuccessMessage(String msg) {
        FacesMessage facesMsg = new FacesMessage(FacesMessage.SEVERITY_INFO, msg, msg);
        FacesContext.getCurrentInstance().addMessage("successInfo", facesMsg);
    }

    public static String getRequestParameter(String key) {
        return FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get(key);
    }

    public static Object getObjectFromRequestParameter(String requestParameterName, Converter converter, UIComponent component) {
        String theId = JsfUtil.getRequestParameter(requestParameterName);
        return converter.getAsObject(FacesContext.getCurrentInstance(), component, theId);
    }
}
JSF实用程序类

//这里还有其他进口商品

@ManagedBean(name = "writerController")
@SessionScoped
public class WriterController implements Serializable {

    @Resource
    private UserTransaction utx = null;
    @PersistenceUnit(unitName = "writerPU")
    private EntityManagerFactory emf = null;
    private Writer current;
    private DataModel items = null;
    private WriterJpaController jpaController = null;
    private PaginationHelper pagination;
    private int selectedItemIndex;

    public WriterController() {
    }

    public Writer getSelected() {
        if (current == null) {
            current = new Writer();
            selectedItemIndex = -1;
        }
        return current;
    }

    private WriterJpaController getJpaController() {
        if (jpaController == null) {
            jpaController = new WriterJpaController(utx, emf);
        }
        return jpaController;
    }

    public PaginationHelper getPagination() {
        if (pagination == null) {
            pagination = new PaginationHelper(10) {

                @Override
                public int getItemsCount() {
                    return getJpaController().getWriterCount();
                }

                @Override
                public DataModel createPageDataModel() {
                    return new ListDataModel(getJpaController().findWriterEntities(getPageSize(), getPageFirstItem()));
                }
            };
        }
        return pagination;
    }

    public String prepareList() {
        recreateModel();
        return "List";
    }

    public String prepareView() {
        current = (Writer) getItems().getRowData();
        selectedItemIndex = pagination.getPageFirstItem() + getItems().getRowIndex();
        return "View";
    }

    public String prepareCreate() {
        current = new Writer();
        selectedItemIndex = -1;
        return "Create";
    }

    public String create() {
        try {
            getJpaController().create(current);
            JsfUtil.addSuccessMessage(ResourceBundle.getBundle("/Bundle").getString("WriterCreated"));
            return prepareCreate();
        } catch (Exception e) {
            JsfUtil.addErrorMessage(e, ResourceBundle.getBundle("/Bundle").getString("PersistenceErrorOccured"));
            return null;
        }
    }

    public String prepareEdit() {
        current = (Writer) getItems().getRowData();
        selectedItemIndex = pagination.getPageFirstItem() + getItems().getRowIndex();
        return "Edit";
    }

    public String update() {
        try {
            getJpaController().edit(current);
            JsfUtil.addSuccessMessage(ResourceBundle.getBundle("/Bundle").getString("WriterUpdated"));
            return "View";
        } catch (Exception e) {
            JsfUtil.addErrorMessage(e, ResourceBundle.getBundle("/Bundle").getString("PersistenceErrorOccured"));
            return null;
        }
    }

    public String destroy() {
        current = (Writer) getItems().getRowData();
        selectedItemIndex = pagination.getPageFirstItem() + getItems().getRowIndex();
        performDestroy();
        recreateModel();
        return "List";
    }

    public String destroyAndView() {
        performDestroy();
        recreateModel();
        updateCurrentItem();
        if (selectedItemIndex >= 0) {
            return "View";
        } else {
            // all items were removed - go back to list
            recreateModel();
            return "List";
        }
    }

    private void performDestroy() {
        try {
            getJpaController().destroy(current.getWriterid());
            JsfUtil.addSuccessMessage(ResourceBundle.getBundle("/Bundle").getString("WriterDeleted"));
        } catch (Exception e) {
            JsfUtil.addErrorMessage(e, ResourceBundle.getBundle("/Bundle").getString("PersistenceErrorOccured"));
        }
    }

    private void updateCurrentItem() {
        int count = getJpaController().getWriterCount();
        if (selectedItemIndex >= count) {
            // selected index cannot be bigger than number of items:
            selectedItemIndex = count - 1;
            // go to previous page if last page disappeared:
            if (pagination.getPageFirstItem() >= count) {
                pagination.previousPage();
            }
        }
        if (selectedItemIndex >= 0) {
            current = getJpaController().findWriterEntities(1, selectedItemIndex).get(0);
        }
    }

    public DataModel getItems() {
        if (items == null) {
            items = getPagination().createPageDataModel();
        }
        return items;
    }

    private void recreateModel() {
        items = null;
    }

    public String next() {
        getPagination().nextPage();
        recreateModel();
        return "List";
    }

    public String previous() {
        getPagination().previousPage();
        recreateModel();
        return "List";
    }

    public SelectItem[] getItemsAvailableSelectMany() {
        return JsfUtil.getSelectItems(getJpaController().findWriterEntities(), false);
    }

    public SelectItem[] getItemsAvailableSelectOne() {
        return JsfUtil.getSelectItems(getJpaController().findWriterEntities(), true);
    }

    @FacesConverter(forClass = Writer.class)
    public static class WriterControllerConverter implements Converter {

        public Object getAsObject(FacesContext facesContext, UIComponent component, String value) {
            if (value == null || value.length() == 0) {
                return null;
            }
            WriterController controller = (WriterController) facesContext.getApplication().getELResolver().
                    getValue(facesContext.getELContext(), null, "writerController");
            return controller.getJpaController().findWriter(getKey(value));
        }

        java.lang.Integer getKey(String value) {
            java.lang.Integer key;
            key = Integer.valueOf(value);
            return key;
        }

        String getStringKey(java.lang.Integer value) {
            StringBuffer sb = new StringBuffer();
            sb.append(value);
            return sb.toString();
        }

        public String getAsString(FacesContext facesContext, UIComponent component, Object object) {
            if (object == null) {
                return null;
            }
            if (object instanceof Writer) {
                Writer o = (Writer) object;
                return getStringKey(o.getWriterid());
            } else {
                throw new IllegalArgumentException("object " + object + " is of type " + object.getClass().getName() + "; expected type: " + WriterController.class.getName());
            }
        }
    }
}
public class JsfUtil {

    public static SelectItem[] getSelectItems(List<?> entities, boolean selectOne) {
        int size = selectOne ? entities.size() + 1 : entities.size();
        SelectItem[] items = new SelectItem[size];
        int i = 0;
        if (selectOne) {
            items[0] = new SelectItem("", "---");
            i++;
        }
        for (Object x : entities) {
            items[i++] = new SelectItem(x, x.toString());
        }
        return items;
    }

    public static void addErrorMessage(Exception ex, String defaultMsg) {
        String msg = ex.getLocalizedMessage();
        if (msg != null && msg.length() > 0) {
            addErrorMessage(msg);
        } else {
            addErrorMessage(defaultMsg);
        }
    }

    public static void addErrorMessages(List<String> messages) {
        for (String message : messages) {
            addErrorMessage(message);
        }
    }

    public static void addErrorMessage(String msg) {
        FacesMessage facesMsg = new FacesMessage(FacesMessage.SEVERITY_ERROR, msg, msg);
        FacesContext.getCurrentInstance().addMessage(null, facesMsg);
    }

    public static void addSuccessMessage(String msg) {
        FacesMessage facesMsg = new FacesMessage(FacesMessage.SEVERITY_INFO, msg, msg);
        FacesContext.getCurrentInstance().addMessage("successInfo", facesMsg);
    }

    public static String getRequestParameter(String key) {
        return FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get(key);
    }

    public static Object getObjectFromRequestParameter(String requestParameterName, Converter converter, UIComponent component) {
        String theId = JsfUtil.getRequestParameter(requestParameterName);
        return converter.getAsObject(FacesContext.getCurrentInstance(), component, theId);
    }
}
JSF分页辅助程序

package jsf.util;

import javax.faces.model.DataModel;

public abstract class PaginationHelper {

    private int pageSize;
    private int page;

    public PaginationHelper(int pageSize) {
        this.pageSize = pageSize;
    }

    public abstract int getItemsCount();

    public abstract DataModel createPageDataModel();

    public int getPageFirstItem() {
        return page * pageSize;
    }

    public int getPageLastItem() {
        int i = getPageFirstItem() + pageSize - 1;
        int count = getItemsCount() - 1;
        if (i > count) {
            i = count;
        }
        if (i < 0) {
            i = 0;
        }
        return i;
    }

    public boolean isHasNextPage() {
        return (page + 1) * pageSize + 1 <= getItemsCount();
    }

    public void nextPage() {
        if (isHasNextPage()) {
            page++;
        }
    }

    public boolean isHasPreviousPage() {
        return page > 0;
    }

    public void previousPage() {
        if (isHasPreviousPage()) {
            page--;
        }
    }

    public int getPageSize() {
        return pageSize;
    }
} // END of CLASS
JPA控制器


当然,您真的在使用JavaEE5吗?换句话说,您的web.xml是根据Servlet2.5规范声明的吗?这意味着EL 2.1,在此EL版本中不支持在EL中传递方法参数。Glassfish 3.1是一个Java EE 6容器,它支持Servlet 3.0,并且隐式支持EL 2.2,其中支持在EL中传递方法参数。如果将web.xml重新声明为Servlet 3.0,那么应该能够在EL中传递方法参数。这样您就不一定需要数据模型了。@BalusC对不起!我不知道你的评论。天哪!!实际上是2.5@BalusC I被命令使用JSF数据模型,这就是我哭泣的原因:我已经使用了一个方法:{ddnController.setPatientitem.id},该方法在数据表中运行良好。我一直认为我从一开始就在使用EL2.2,因为我的web中使用的默认库是与Glassfish 3.1捆绑在一起的库,并且在使用诸如:{myproperty.size}或{empty bean.att或bean.toto.equalssoso}等新特性时没有问题
package jsf.util;

import javax.faces.model.DataModel;

public abstract class PaginationHelper {

    private int pageSize;
    private int page;

    public PaginationHelper(int pageSize) {
        this.pageSize = pageSize;
    }

    public abstract int getItemsCount();

    public abstract DataModel createPageDataModel();

    public int getPageFirstItem() {
        return page * pageSize;
    }

    public int getPageLastItem() {
        int i = getPageFirstItem() + pageSize - 1;
        int count = getItemsCount() - 1;
        if (i > count) {
            i = count;
        }
        if (i < 0) {
            i = 0;
        }
        return i;
    }

    public boolean isHasNextPage() {
        return (page + 1) * pageSize + 1 <= getItemsCount();
    }

    public void nextPage() {
        if (isHasNextPage()) {
            page++;
        }
    }

    public boolean isHasPreviousPage() {
        return page > 0;
    }

    public void previousPage() {
        if (isHasPreviousPage()) {
            page--;
        }
    }

    public int getPageSize() {
        return pageSize;
    }
} // END of CLASS
package jpa.controllers;

import entities.Writer;
// other imports here

    public class WriterJpaController implements Serializable {

        public WriterJpaController(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(Writer writer) throws RollbackFailureException, Exception {
            if (writer.getTopicList() == null) {
                writer.setTopicList(new ArrayList<Topic>());
            }
            if (writer.getEvaluationList() == null) {
                writer.setEvaluationList(new ArrayList<Evaluation>());
            }
            if (writer.getBookList() == null) {
                writer.setBookList(new ArrayList<Book>());
            }
            EntityManager em = null;
            try {
                utx.begin();
                em = getEntityManager();
                List<Topic> attachedTopicList = new ArrayList<Topic>();
                for (Topic topicListTopicToAttach : writer.getTopicList()) {
                    topicListTopicToAttach = em.getReference(topicListTopicToAttach.getClass(), topicListTopicToAttach.getTopicname());
                    attachedTopicList.add(topicListTopicToAttach);
                }
                writer.setTopicList(attachedTopicList);
                List<Evaluation> attachedEvaluationList = new ArrayList<Evaluation>();
                for (Evaluation evaluationListEvaluationToAttach : writer.getEvaluationList()) {
                    evaluationListEvaluationToAttach = em.getReference(evaluationListEvaluationToAttach.getClass(), evaluationListEvaluationToAttach.getEvaluationPK());
                    attachedEvaluationList.add(evaluationListEvaluationToAttach);
                }
                writer.setEvaluationList(attachedEvaluationList);
                List<Book> attachedBookList = new ArrayList<Book>();
                for (Book bookListBookToAttach : writer.getBookList()) {
                    bookListBookToAttach = em.getReference(bookListBookToAttach.getClass(), bookListBookToAttach.getBookPK());
                    attachedBookList.add(bookListBookToAttach);
                }
                writer.setBookList(attachedBookList);
                em.persist(writer);
                for (Topic topicListTopic : writer.getTopicList()) {
                    topicListTopic.getWriterList().add(writer);
                    topicListTopic = em.merge(topicListTopic);
                }
                for (Evaluation evaluationListEvaluation : writer.getEvaluationList()) {
                    Writer oldWriterOfEvaluationListEvaluation = evaluationListEvaluation.getWriter();
                    evaluationListEvaluation.setWriter(writer);
                    evaluationListEvaluation = em.merge(evaluationListEvaluation);
                    if (oldWriterOfEvaluationListEvaluation != null) {
                        oldWriterOfEvaluationListEvaluation.getEvaluationList().remove(evaluationListEvaluation);
                        oldWriterOfEvaluationListEvaluation = em.merge(oldWriterOfEvaluationListEvaluation);
                    }
                }
                for (Book bookListBook : writer.getBookList()) {
                    Writer oldWriterOfBookListBook = bookListBook.getWriter();
                    bookListBook.setWriter(writer);
                    bookListBook = em.merge(bookListBook);
                    if (oldWriterOfBookListBook != null) {
                        oldWriterOfBookListBook.getBookList().remove(bookListBook);
                        oldWriterOfBookListBook = em.merge(oldWriterOfBookListBook);
                    }
                }
                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(Writer writer) throws IllegalOrphanException, NonexistentEntityException, RollbackFailureException, Exception {
          // remainder of code goes here
        }

        public void destroy(Integer id) throws IllegalOrphanException, NonexistentEntityException, RollbackFailureException, Exception {
           // remainder of code goes here
        }

        public List<Writer> findWriterEntities() {
            return findWriterEntities(true, -1, -1);
        }

        public List<Writer> findWriterEntities(int maxResults, int firstResult) {
            return findWriterEntities(false, maxResults, firstResult);
        }

        private List<Writer> findWriterEntities(boolean all, int maxResults, int firstResult) {
            EntityManager em = getEntityManager();
            try {
                CriteriaQuery cq = em.getCriteriaBuilder().createQuery();
                cq.select(cq.from(Writer.class));
                Query q = em.createQuery(cq);
                if (!all) {
                    q.setMaxResults(maxResults);
                    q.setFirstResult(firstResult);
                }
                return q.getResultList();
            } finally {
                em.close();
            }
        }

        public Writer findWriter(Integer id) {
            EntityManager em = getEntityManager();
            try {
                return em.find(Writer.class, id);
            } finally {
                em.close();
            }
        }

        public int getWriterCount() {
            EntityManager em = getEntityManager();
            try {
                CriteriaQuery cq = em.getCriteriaBuilder().createQuery();
                Root<Writer> rt = cq.from(Writer.class);
                cq.select(em.getCriteriaBuilder().count(rt));
                Query q = em.createQuery(cq);
                return ((Long) q.getSingleResult()).intValue();
            } finally {
                em.close();
            }
        }

    }