日期:2014-05-20  浏览次数:20711 次

spring+Hibernate,super.getHibernateTemplate()空值异常
Java code
package com.dao;

import java.util.List;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

public class UserDao extends HibernateDaoSupport {

    public boolean doIsHas1(String str, String columnName) {
        // TODO Auto-generated method stub
        String sql = "from User u where u."+columnName+"=?";
        List list = super.getHibernateTemplate().find(sql, str);
        return (list.size() > 0);
    }
}


Java code

package com.entity;



/**
 * User generated by MyEclipse Persistence Tools
 */

public class User  implements java.io.Serializable {


    // Fields    

     private Integer id;
     private Integer type;
     private String name;
     private String identitynum;
     private Byte sex;
     private Integer age;
     private String country;
     private Integer married;
     private String birthAddress;
     private String address;
     private String telephone;
     private String email;
     private Integer qqnum;
     private String pwdquestion;
     private String pwdanswer;
     private String birthday;
     private String nation;
     private String password;


    // Constructors

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

    /** minimal constructor */
    public User(String name, String telephone, String password) {
        this.name = name;
        this.telephone = telephone;
        this.password = password;
    }
    
    /** full constructor */
    public User(Integer type, String name, String identitynum, Byte sex, Integer age, String country, Integer married, String birthAddress, String address, String telephone, String email, Integer qqnum, String pwdquestion, String pwdanswer, String birthday, String nation, String password) {
        this.type = type;
        this.name = name;
        this.identitynum = identitynum;
        this.sex = sex;
        this.age = age;
        this.country = country;
        this.married = married;
        this.birthAddress = birthAddress;
        this.address = address;
        this.telephone = telephone;
        this.email = email;
        this.qqnum = qqnum;
        this.pwdquestion = pwdquestion;
        this.pwdanswer = pwdanswer;
        this.birthday = birthday;
        this.nation = nation;
        this.password = password;
    }

   
    // Property accessors

    public Integer getId() {
        return this.id;
    }
    
    public void setId(Integer id) {
        this.id = id;
    }

    public Integer getType() {
        return this.type;
    }
    
    public void setType(Integer type) {
        this.type = type;
    }

    public String getName() {
        return this.name;
    }
    
    public void setName(String name) {
        this.name = name;
    }

    public String getIdentitynum() {
        return this.identitynum;
    }
    
    public void setIdentitynum(String identitynum) {
        this.identitynum = identitynum;
    }

    public Byte getSex() {
        return this.sex;
    }
    
    public void setSex(Byte sex) {
        this.sex = sex;
    }

    public Integer getAge() {
        return this.age;
    }
    
    public void setAge(Integer age) {
        this.age = age;
    }

    public String getCountry() {
        return this.country;
    }
    
    public void setCountry(String country) {
        this.country = country;
    }

    public Integer getMarried() {
        return this.married;
    }
    
    public void setMarried(Integer married) {
        this.married = married;
    }

    public String getBirthAddress() {
        return this.birthAddress;
    }
    
    public void setBirthAddress(String birthAddress) {
        this.birthAddress = birthAddress;
    }

    public String getAddress() {
        return this.address;
    }
    
    public void setAddress(String address) {
        this.address = address;
    }

    public String getTelephone() {
        return this.telephone;
    }
    
    public void setTelephone(String telephone) {
        this.telephone = telephone;
    }

    public String getEmail() {
        return this.email;
    }
    
    public void setEmail(String email) {
        this.email = email;
    }

    public Integer getQqnum() {
        return this.qqnum;
    }
    
    public void setQqnum(Integer qqnum) {
        this.qqnum = qqnum;
    }

    public String getPwdquestion() {
        return this.pwdquestion;
    }
    
    public void setPwdquestion(String pwdquestion) {
        this.pwdquestion = pwdquestion;
    }

    public String getPwdanswer() {
        return this.pwdanswer;
    }
    
    public void setPwdanswer(String pwdanswer) {
        this.pwdanswer = pwdanswer;
    }

    public String getBirthday() {
        return this.birthday;
    }
    
    public void setBirthday(String birthday) {
        this.birthday = birthday;
    }

    public String getNation() {
        return this.nation;
    }
    
    public void setNation(String nation) {
        this.nation = nation;
    }

    public String getPassword() {
        return this.password;
    }
    
    public void setPassword(String password) {
        this.password = password;
    }
}