//从数据库中查找user对象
public static User login(String userName,String passwd){
        Session s=null;
        User user=null;
        try{
            s=HibernateUtil.getSession();
            String hql="from User as user where user.name=? and user.passwd=?";
            Query query=s.createQuery(hql);
            query.setString(0, userName);
            query.setString(1,passwd);
            user=(User) query.uniqueResult();
        }catch(HibernateException e){
            throw e;
        }finally{
            s.close();
        }
        if(user!=null)
            return user;
        return null;
    }服务器将对象传送给客户端user=UserSystem.login(userName, passwd);
objectOutput.writeObject(user);客户端接收user对象public static User login(String userName,String passwd)throws IOException, ClassNotFoundException{
        User user;
        output.writeInt(Intent.INTENT_LOGIN);
        output.writeUTF(userName);
        output.writeUTF(passwd);
        output.flush();
        user=(User)objectInput.readObject();
        return user;
    }但是客户端报错Exception in thread "main" java.lang.ClassNotFoundException: org.hibernate.collection.PersistentSet但是在客户端引入hibernate3.jar后,就没有错误了。也就是说服务端传递过来的user对象还含有hibernate方面的信息。由于客户端要应用在手机上,hibernate3.jar又有3MB之大(不能将程序写得太大),所以想找找有没有能够在服务端将user对象中的hibernate信息去除。。求高手帮助。

解决方案 »

  1.   

    BeanUtiles.copyProperies()应该可以
      

  2.   

    BeanUtils.copyProperties(user, (User)query.uniqueResult());
    我用这个后还是不行,多了一个错误。
    Exception in thread "Thread-0" java.lang.IllegalArgumentException: No destination bean specified
    at org.apache.commons.beanutils.BeanUtils.copyProperties(BeanUtils.java:216)
    at com.way.hibernate.UserSystem.login(UserSystem.java:82)
    at com.way.ServerThread.run(ServerThread.java:36)
      

  3.   

    User 类中也包含多个类
        private int id;
    private String name;
    private String passwd;
    private String petName;
    private String email;
    private String phoneNum;
    private boolean sex;
    private Date time;
    private Date birthDay;
    private double longitude;
    private double latitude;
    private String imgAddr;
    private int state;
    private Set<FeedBack> feedBacks;
    private Set<News> news;
    private Set<Message> messages;
    private Set<Joke> jokes;
    private Set<User>friends;
    如果用copyProperties方法,他的基本属性成员转换没有问题,但是他的类成员还是包含hibernate信息
      

  4.   

    LZ问题解决了吗 我也是相同的问题,纠结死了。也是User类中包含User,比如说u1中有u2,u2中又有u1不知道怎么直接转换,而且就算退而求其次在android中导入hibernate3.jar也不行,可能是因为是序列化对象的serialVersionUID不一样,我猜是android里面的jvm版本和pc上不一样的原因。