Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/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/2/apache-kafka/3.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
Hibernate PrimeFaces+;数据表(编辑行)和#x2B;冬眠+;MYSQLDatabase_Hibernate_Jsf_Jsf 2_Primefaces_Datatable - Fatal编程技术网

Hibernate PrimeFaces+;数据表(编辑行)和#x2B;冬眠+;MYSQLDatabase

Hibernate PrimeFaces+;数据表(编辑行)和#x2B;冬眠+;MYSQLDatabase,hibernate,jsf,jsf-2,primefaces,datatable,Hibernate,Jsf,Jsf 2,Primefaces,Datatable,我想编辑datatable行。我的代码在这里 我的ManagedBean @ManagedBean @ViewScoped public class course implements Serializable{ private int course_Id ; private String course_Name; private Integer course_Hours ; private Date course_Date; private Double course_Prise ;

我想编辑datatable行。我的代码在这里

我的ManagedBean

@ManagedBean
@ViewScoped 
public class course implements Serializable{

private int course_Id ; 
private String course_Name;
private Integer course_Hours  ;
private Date course_Date;
private Double course_Prise ;

SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy");  
private String sd  ;


   getter and setter .....

  public void onRowEdit(RowEditEvent event) {
     course c =((course) event.getObject());

       Transaction trn = null ;
      Session session = HibernateUtil.getSessionFactory().openSession();
      trn = session.beginTransaction();
     c.setCourse_Id(getCourse_Id());
     c.setCourse_Name(getCourse_Name());
     c.setCourse_Hours(getCourse_Hours());
     c.setCourse_Prise(getCourse_Prise());
     c.setCourse_Date(getCourse_Date());

        session.update(c);

          session.getTransaction().commit();

    FacesMessage msg = new FacesMessage("Course Edited", ((course) event.getObject()).getCourse_Name());
    FacesContext.getCurrentInstance().addMessage(null, msg);
}
我的JSF页面

       <?xml version='1.0' encoding='UTF-8' ?>
          <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://xmlns.jcp.org/jsf/core">
    <h:head>
          <title>Facelet Title</title>
</h:head>
<h:body>
    <h:form id="form">
    <p:growl id="msgs" showDetail="true"/>
    <p:dataTable  id="dt" value="#{course.allcourses}" var="course" editable="true">
        <p:ajax event="rowEdit" listener="#{course.onRowEdit}" update=":form:msgs"  />
        <p:ajax event="rowEditCancel" listener="#{course.onRowCancel}" update=":form:msgs" />

     <p:column id="colId" filterBy="#{course.course_Id}" sortBy="#{course.course_Id}"
                                                  headerText="ID" footerText="contains" 

                                                  filterMatchMode="contains">


                                            <h:outputText value="#{course.course_Id}" />                    
                                        </p:column>
    <p:column filterBy="#{course.course_Name}" headerText="Name" sortBy="#{course.course_Name}">

                                            <p:cellEditor >
                                             <f:facet name="output">  
                                           <h:outputText value="#{course.course_Name}" />  
                                                </f:facet>  
                                                <f:facet name="input">  
                            <p:inputText value="#{course.course_Name}" style="width:100%"/>  
                                                </f:facet> 
                                            </p:cellEditor>
                                        </p:column>
 <p:column filterBy="#{course.course_Hours}" headerText="Hours" sortBy="#{course.course_Hours}">
                                        <p:cellEditor >
                                          <f:facet name="output">  
                                        <h:outputText value="#{course.course_Hours}" />  
                                                </f:facet>  
                                                <f:facet name="input">  
                         <p:inputText value="#{course.course_Hours}" style="width:100%"/>  
                                                </f:facet> 
                                            </p:cellEditor>
                                        </p:column>
  <p:column filterBy="#{course.course_Prise}" headerText="Prise" sortBy="#{course.course_Prise}">
                                     <p:cellEditor >
                                       <f:facet name="output">  
                                <h:outputText value="#{course.course_Prise}" />  
                                                </f:facet>  
                                                <f:facet name="input">  
                        <p:inputText value="#{course.course_Prise}" style="width:100%"/>  
                                                </f:facet> 
                                            </p:cellEditor>
                                        </p:column>
          <p:column filterBy="#{course.course_Date}"    headerText="Start Date" sortBy="#  {course.course_Date}">
                                            <p:cellEditor >
                                                <f:facet name="output">  
                                               <h:outputText value="#{course.course_Date}" />  
                                                </f:facet>  
                                                <f:facet name="input">  
                                    <p:inputText value="#{course.sd}" style="width:100%"/>  
                                                </f:facet> 
                                            </p:cellEditor>


                                        </p:column>
         <p:column style="width:32px">
       <p:rowEditor />

         </p:column>


    </p:dataTable>
    </h:form>
</h:body>
这是课程DAo课上的getCourses方法

   `public List<course> getCourses (){  

    List<course> allcourses =  null ;
      Transaction trns = null;
    Session session =HibernateUtil.getSessionFactory().openSession();
        try {
       trns= session.beginTransaction();
        allcourses = session.createCriteria(course.class).list();
        session.getTransaction().commit();

         } catch (HibernateException e) {
             e.getMessage();
            trns.rollback();
           } finally {
        session.flush();
        session.close();
    }
    return allcourses;
    }
`public List getCourses(){
列出所有课程=空;
事务trns=null;
Session Session=HibernateUtil.getSessionFactory().openSession();
试一试{
trns=session.beginTransaction();
allcourses=session.createCriteria(course.class.list();
session.getTransaction().commit();
}捕获(休眠异常e){
e、 getMessage();
trns.rollback();
}最后{
session.flush();
session.close();
}
返回所有课程;
}
`
**您看到我的代码中有错误吗?***

您的逻辑在这里被颠倒了。。。您正在从事件中获取课程对象:

course c =((course) event.getObject()); 
它保存数据表中更新的值,然后通过调用setter将这些值替换为旧值

移除所有这些,它应该可以工作:

 c.setCourse_Id(getCourse_Id());
 c.setCourse_Name(getCourse_Name());
 c.setCourse_Hours(getCourse_Hours());
 c.setCourse_Prise(getCourse_Prise());
 c.setCourse_Date(getCourse_Date());

我正在寻找解决此问题的方法,但没有找到,我解决了它,如下所示:

    //managed bean

    public List<Operacao> operacoes;

        @PostConstruct
        public void init(){
            this.operacoes = operacaoService.operacoes();
        }

        public List<Operacao> getOperacoes() {
            return operacoes;        
        }

    //xhtml 

<p:dataTable id="cars1" var="car" value="#{tabelaTrades.operacoes}" editable="true" >
//托管bean
公开名单歌剧;
@施工后
公共void init(){
this.operacoes=operacaoService.operacoes();
}
公共列表getOperacoes(){
返回歌剧;
}
//xhtml
我当时正在做,value=“#{tabelaterades.operacoes()}”,在一些更改之后,它没有更新数据表


亲爱的Emil Kaminski我如你所说做了,但电池仍恢复到原始状态,你看到我的代码中有错误吗?这个问题让我发疯。。我想你需要再调试一下你的问题。请检查:是否正在呼叫您的设定者?您的课程c=((课程)event.getObject())obejct是否在session.update(c)调用之前保存更新的值?您的私有字段是否具有正确的值?你的#{course.allcourses}怎么样?这个方法是否包含任何将值重置为原始状态的逻辑?亲爱的Emil首先感谢重播,我多次调试以检查这个问题,但每件事情都很好,对于#{course.allcourses}”这是一个课程类列表,它从课程表中获取所有课程,并在DataTable中显示。还有一件事,为什么我使用这个代码
c.setCourse_Name(“Hibernate”)例如,更新工作正常,我看到课程名称单元格更新了为什么?我需要帮助这个问题让我发疯
    //managed bean

    public List<Operacao> operacoes;

        @PostConstruct
        public void init(){
            this.operacoes = operacaoService.operacoes();
        }

        public List<Operacao> getOperacoes() {
            return operacoes;        
        }

    //xhtml 

<p:dataTable id="cars1" var="car" value="#{tabelaTrades.operacoes}" editable="true" >