请问该如何解决这个问题啊?有人能回答不?

解决方案 »

  1.   

    那这样岂不是所有的业务都不能对这些字段进行更新了?也不行啊。。还有没有其他的解决方法?
      

  2.   

    建议你把你的代码帖出来看看。你一定是哪里的代码有问题,我一直那样用都没有出现什么问题呀?
      

  3.   

    下面是一段示范,大家帮我看看有什么问题:
    客户端调用代码:UserClient.java
    .......
    com.test.dataBase.User user=new com.test.database.User();
    //注意这里没有对User的其他字段进行set
    user.setUserId(userId);
    user.setLoginName(userName);
    user.setLoginPass(loginPass);
    UserFacadeRemote userRemote=null;
    try
    {
    //这里是接口的调用,都是一样的,就不详细些了,浪费时间
    ........} catch (LeasingErrorException e)
    {
    throw new ServletException(e);
    }
    userRemote.update(user);//后面是其他无关紧要的代码也省略了。
    .......服务器端代码:package com.test.database;import javax.persistence.Column;
    import javax.persistence.Entity;
    import javax.persistence.Id;
    import javax.persistence.Table;/**
    * User generated by MyEclipse Persistence Tools
    */
    @Entity
    @Table(name = "User", catalog = "leasing", uniqueConstraints = {})
    public class User implements java.io.Serializable {// Fieldsprivate String userId;
    private String employeeNo;
    private String departId;
    private String userName;
    private String loginName;
    private String loginPass;
    private String email;
    private String phoneNum;
    private int status;
    private String module;
    private String visitMode;
    private String levelid;
    private String posts;// Constructors/** default constructor */
    public User() {
    }/** minimal constructor */
    public User(String userId, String employeeNo, String departId,
    String loginName, int status) {
    this.userId = userId;
    this.employeeNo = employeeNo;
    this.departId = departId;
    this.loginName = loginName;
    this.status = status;
    }/** full constructor */
    public User(String userId, String employeeNo, String departId,
    String userName, String loginName, String loginPass, String email,
    String phoneNum, int status, String module, String visitMode,
    String levelid, String posts) {
    this.userId = userId;
    this.employeeNo = employeeNo;
    this.departId = departId;
    this.userName = userName;
    this.loginName = loginName;
    this.loginPass = loginPass;
    this.email = email;
    this.phoneNum = phoneNum;
    this.status = status;
    this.module = module;
    this.visitMode = visitMode;
    this.levelid = levelid;
    this.posts = posts;
    }// Property accessors
    @Id
    @Column(name = "UserID", unique = true, nullable = false, insertable = true, updatable = true, length = 10)
    public String getUserId() {
    return this.userId;
    }public void setUserId(String userId) {
    this.userId = userId;
    }@Column(name = "employeeNo", unique = false, nullable = false, insertable = true, updatable = true, length = 10)
    public String getEmployeeNo() {
    return this.employeeNo;
    }public void setEmployeeNo(String employeeNo) {
    this.employeeNo = employeeNo;
    }@Column(name = "DepartID", unique = false, nullable = false, insertable = true, updatable = true, length = 10)
    public String getDepartId() {
    return this.departId;
    }public void setDepartId(String departId) {
    this.departId = departId;
    }@Column(name = "UserName", unique = false, nullable = true, insertable = true, updatable = true, length = 20)
    public String getUserName() {
    return this.userName;
    }public void setUserName(String userName) {
    this.userName = userName;
    }@Column(name = "LoginName", unique = false, nullable = false, insertable = true, updatable = true, length = 10)
    public String getLoginName() {
    return this.loginName;
    }public void setLoginName(String loginName) {
    this.loginName = loginName;
    }@Column(name = "LoginPass", unique = false, nullable = true, insertable = true, updatable = true, length = 10)
    public String getLoginPass() {
    return this.loginPass;
    }public void setLoginPass(String loginPass) {
    this.loginPass = loginPass;
    }@Column(name = "EMail", unique = false, nullable = true, insertable = true, updatable = true, length = 50)
    public String getEmail() {
    return this.email;
    }public void setEmail(String email) {
    this.email = email;
    }@Column(name = "PhoneNum", unique = false, nullable = true, insertable = true, updatable = true, length = 20)
    public String getPhoneNum() {
    return this.phoneNum;
    }public void setPhoneNum(String phoneNum) {
    this.phoneNum = phoneNum;
    }@Column(name = "Status", unique = false, nullable = false, insertable = true, updatable = true)
    public int getStatus() {
    return this.status;
    }public void setStatus(int status) {
    this.status = status;
    }@Column(name = "Module", unique = false, nullable = true, insertable = true, updatable = true, length = 100)
    public String getModule() {
    return this.module;
    }public void setModule(String module) {
    this.module = module;
    }@Column(name = "VisitMode", unique = false, nullable = true, insertable = true, updatable = true, length = 10)
    public String getVisitMode() {
    return this.visitMode;
    }public void setVisitMode(String visitMode) {
    this.visitMode = visitMode;
    }@Column(name = "levelid", unique = false, nullable = true, insertable = true, updatable = true, length = 10)
    public String getLevelid() {
    return this.levelid;
    }public void setLevelid(String levelid) {
    this.levelid = levelid;
    }@Column(name = "posts", unique = false, nullable = true, insertable = true, updatable = true, length = 10)
    public String getPosts() {
    return this.posts;
    }public void setPosts(String posts) {
    this.posts = posts;
    }}package com.test.database;import java.util.List;
    import java.util.logging.Level;
    import javax.ejb.Stateless;
    import javax.persistence.EntityManager;
    import javax.persistence.PersistenceContext;
    import javax.persistence.Query;
     session bean 类的代码:UserFacadeRemote.java@Stateless
    public class UserFacade implements UserFacadeRemote
    {@PersistenceContext
    private EntityManager entityManager;
    public User update(User entity)
    {try
    {
    User result = entityManager.merge(entity);return result;
    } catch (RuntimeException re)
    {throw re;
    }
    }
    }接口类太简单,也就不写了, 在UserClient.java中。我只对User的userName和loginPass进行了赋值(userId是主键),而此时数据库中User表的其他字段均是由值的,在update完成以后数据库中除了userName和loginPass有值(就是我刚刚set的值),其他字段的值都成了null(空)(我原本是想保持这些之字段短的值不变,只更新userName和loginPass),很麻烦,大家帮我看下是什么问题