Announcement Announcement Module
Collapse
No announcement yet.
Can not execute Update in Hibernate Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Can not execute Update in Hibernate

    hibernate.hbm.xml
    <class name="com.test.Aclrole" table="acl_role" discriminator-value="W">
    <id name="roleid" type="int" >
    <column name="roleid" not-null="true"/>
    <generator class="native"/>
    </id>
    <property name="rolename" type="string">
    <column name="rolename" sql-type="varchar(99)" />
    </property>
    <property name="roledesc" type="string">
    <column name="roledesc" sql-type="varchar(99)" />
    </property>
    <set name="permission" cascade="all" inverse="true">
    <key column="roleid"/>
    <one-to-many class="com.test.Aclrolepermission"/>
    </set>
    </class>

    DAO code:
    Aclrole aclrole = (Aclrole)getHibernateTemplate().load(Aclrole.class ,role.getRoleid());
    aclrole.setRolename(role.getRolename());
    aclrole.setRoledesc(role.getRoledesc());
    getHibernateTemplate().update(aclrole);


    After that I check the database, the data is old,no update executed.

    and I debug the code
    after aclrole.setRoledesc(role.getRoledesc());
    I use System.out.println(aclrole.getRoledesc()); to display the data,but I found that the data is old, the setRoledesc() method doesn't take effect.
    How can i do

  • #2
    the following is the domain class:
    import java.io.Serializable;
    import java.util.Set;
    import org.apache.commons.lang.builder.EqualsBuilder;
    import org.apache.commons.lang.builder.HashCodeBuilder;
    import org.apache.commons.lang.builder.ToStringBuilder;

    /** @author Hibernate CodeGenerator */
    public class Aclrole implements Serializable {

    /** identifier field */
    private Integer roleid;

    /** nullable persistent field */
    private String rolename;

    private String roledesc;

    /** persistent field */
    private Set permission;

    public Aclrole(Integer roleid) {
    this.roleid = roleid;
    }

    /** full constructor */
    public Aclrole(java.lang.String rolename, Set permission) {
    this.rolename = rolename;
    this.permission = permission;
    }

    /** default constructor */
    public Aclrole() {
    }

    /** minimal constructor */
    public Aclrole(Set permission) {
    this.permission = permission;
    }

    public java.lang.Integer getRoleid() {
    return this.roleid;
    }

    public void setRoleid(java.lang.Integer roleid) {
    this.roleid = roleid;
    }

    public java.lang.String getRolename() {
    return this.rolename;
    }

    public void setRolename(java.lang.String rolename) {
    this.rolename = rolename;
    }

    public String getRoledesc()
    {
    return this.rolename;
    }
    public void setRoledesc(String roledesc)
    {
    this.roledesc = roledesc;
    }

    public java.util.Set getPermission() {
    return this.permission;
    }

    public void setPermission(java.util.Set permission) {
    this.permission = permission;
    }

    public String toString() {
    return new ToStringBuilder(this)
    .append("roleid", getRoleid())
    .toString();
    }

    public boolean equals(Object other) {
    if ( !(other instanceof Aclrole) ) return false;
    Aclrole castOther = (Aclrole) other;
    return new EqualsBuilder()
    .append(this.getRoleid(), castOther.getRoleid())
    .isEquals();
    }

    public int hashCode() {
    return new HashCodeBuilder()
    .append(getRoleid())
    .toHashCode();
    }

    }

    Comment


    • #3
      the following is the domain class:
      import java.io.Serializable;
      import java.util.Set;
      import org.apache.commons.lang.builder.EqualsBuilder;
      import org.apache.commons.lang.builder.HashCodeBuilder;
      import org.apache.commons.lang.builder.ToStringBuilder;

      /** @author Hibernate CodeGenerator */
      public class Aclrole implements Serializable {

      /** identifier field */
      private Integer roleid;

      /** nullable persistent field */
      private String rolename;

      private String roledesc;

      /** persistent field */
      private Set permission;

      public Aclrole(Integer roleid) {
      this.roleid = roleid;
      }

      /** full constructor */
      public Aclrole(java.lang.String rolename, Set permission) {
      this.rolename = rolename;
      this.permission = permission;
      }

      /** default constructor */
      public Aclrole() {
      }

      /** minimal constructor */
      public Aclrole(Set permission) {
      this.permission = permission;
      }

      public java.lang.Integer getRoleid() {
      return this.roleid;
      }

      public void setRoleid(java.lang.Integer roleid) {
      this.roleid = roleid;
      }

      public java.lang.String getRolename() {
      return this.rolename;
      }

      public void setRolename(java.lang.String rolename) {
      this.rolename = rolename;
      }

      public String getRoledesc()
      {
      return this.rolename;
      }
      public void setRoledesc(String roledesc)
      {
      this.roledesc = roledesc;
      }

      public java.util.Set getPermission() {
      return this.permission;
      }

      public void setPermission(java.util.Set permission) {
      this.permission = permission;
      }

      public String toString() {
      return new ToStringBuilder(this)
      .append("roleid", getRoleid())
      .toString();
      }

      public boolean equals(Object other) {
      if ( !(other instanceof Aclrole) ) return false;
      Aclrole castOther = (Aclrole) other;
      return new EqualsBuilder()
      .append(this.getRoleid(), castOther.getRoleid())
      .isEquals();
      }

      public int hashCode() {
      return new HashCodeBuilder()
      .append(getRoleid())
      .toHashCode();
      }

      }

      Comment


      • #4
        kalfen,

        This has nothing to do with Spring nor Hibernate. There is a bug in your domain class:
        Code:
        public String getRoledesc&#40;&#41;
        &#123;
        return this.rolename;
        &#125;
        your method should be
        Code:
        public String getRoledesc&#40;&#41; &#123;
          return this.roledesc;
        &#125;
        /** @author Hibernate CodeGenerator */
        did you create this class yourself or is there a bug in Hibernate CodeGenerator

        Comment

        Working...
        X