3 Replies Latest reply on May 25, 2009 4:49 AM by Emmanuel Rousselle

    Help: Hibernate-Seam persists instantly

    Dang LH Newbie


      I have a problem regarding Hibernate and persistence. In my view I'm using a backing bean called CreateCourse. In that bean 1 Hibernate managed Entity bean Course is processed. The CreateCourse bean looks like kind of this.

      public class CreateCourse{
              private EntityManager em;
              private Integer coursesetup_id;
              private CourseSetup courseSetup;
              private Integer course_id;
              private Course course;
              public void importCourseFromCourseSetup() {
              public String initialize() {
                      //get the PersistenceContext
                      this.em = (EntityManager) Component.getInstance("entityManager",true);
                      if(this.course_id != null)
                      {//work with a defined course
                                      this.course = em.find(Course.class, this.course_id);
                      }else{//work with a new course 
                              this.course = new Course();
                      if(this.coursesetup_id != null)
                                 this.courseSetup =           
                              this.courseSetup = new CourseSetup();
                      return "initialised";

      the associating view is built as such, that the user can pick a CourseSetup and import an already defined courseSetup to the Course' definition. So when the the user clicks on inport a h:form will be submitted setting Course.coursesetup, and Course.importCourseFromCourseSetup() will be processed, which sets the Course.

      At the end the user shall be able to persist the Course finally, or just persist the edited content he/she's done.

      But now here comes the Problem i dont understand:

      When Course.importCourseFromCourseSetup() Hibernate instantly persist/writes the data into the DB. I don't understand this behavior at all, because i thought that one should clearly specify the persist operation (such as this.em.persist(this.course) or this.em.update(this.course) ... etc.).

      Can someone explain this behavior of Hibernate, or have i done an elemantary mistake somewhere ?

      P.S. the view is like that:

      <h:form id="courseform">
                  <f:facet name="header">course</f:facet>
                  <s:decorate id="nameField" template="../layout/edit.xhtml">
                      <ui:define name="label">courseSetup</ui:define>
                      <h:selectOneMenu value="#{createCourse.courseSetup}" required="true">
                                      <s:selectItems var="courseSetup" value="#{courseSetupList.resultList}" label="#{courseSetup.coursename}"></s:selectItems>
                              <h:commandButton type="submit"
                                      value="import" action="#{createCourse.importCourseFromCourseSetup()}">
      <h:commandButton value="save"
              <h:commandButton value="edit"

      the problem is that Hibernate persists/updates the data instantly as soon as the form is submitted.

      Thanks for the answers.