These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: cannot edit user
PostPosted: Tue Jun 27, 2006 4:44 am 
Beginner
Beginner

Joined: Tue Feb 07, 2006 10:39 pm
Posts: 46
i have this editUser method:

Code:
/**
                   * @ejb.interface-method 
                   *
                   * @param user
                   * @throws ServiceException
                   */
                  public MUser  EditUser (MUser user, List listRoles)throws ServiceException {
                     Session ses = null;
                     String userId = user.getUserId();
                     
                     try{         
                        ses = ThreadLocalSession.currentSession();   
                        
                        //Search for user Id
                        Query query = ses.createQuery("from MUser as user where user.userId=?");
                        query.setString(0, userId);
                        List result = query.list();
                        
                        //Obtain list of roles for that user
                        MUser user1 = (MUser)result.get(0);
                        List listRole = new ArrayList();
                          listRole = user1.getUserRoles();
                         
                          //Delete list of roles
                          Iterator ite = listRole.iterator();
                        while(ite.hasNext()){
                           MUserRoles roles = (MUserRoles)ite.next();
                           ses.delete(roles);
                        }
                        //ses.delete(user);

                        int i =0;
                        List list = new ArrayList();
                         Iterator ite2 = listRoles.iterator();
                            while(ite2.hasNext()){ 
                               MRoles roles = (MRoles)ite2.next();   
                               MUserRoles x = new MUserRoles(); 
                               x.setRoleId(roles.roleId);
                               x.setUser(user);
                               x.setNo(i);
                               list.add(i,x);
                               ses.save(x);
                               i++;
                            }
                        
                         user.setUserRoles(list);
                        user.setDesignation(user.getDesignation());
                        user.setFullName(user.getFullName());
                        //user.setPassword(users.getPassword());
                        
                        ses.update(user);
                        
                        ses.flush();
                        
                        return user;
                     } catch (HibernateException e) {
                        ctx.setRollbackOnly();
                        throw new ServiceException("Unable to update User "/*[" +users.getUserId()+"].\n"
                                +getCause(e.getCause() != null?e.getCause().toString():"")*/);
                     }finally{
                        
                        try {
                           ThreadLocalSession.closeSession();
                        } catch (HibernateException e1) {
                           e1.printStackTrace();
                        }
                     }                   
               
}

but when i try to edit the data. it seem like cannot work. i called this method by
Code:
Object ob = EJBInvoker.invokeRemoteEJB(Global.JBOSS_JNP,SetUpBeanHome.JNDI_NAME,"EditUser",
                  args,argsType);


how to fix it?? thanks


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 27, 2006 6:59 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Ouch! You drop the entire persistent set and replace it with a transient set every time? That's going to get expensive, quickly. Work with the in-place list, not the transient one.

Also, you really should use session.get(MUser.class, userId), not that query. A few checks would be a good idea (what if there is no matching user? Your code will throw IndexOutOfBoundsException).

Finally, you didn't say what your error is. When reporting an error, you've got to remember that "it doesn't work" isn't an error report. Try logging any and all exceptions, add a lot more logging, anything that might help.

_________________
Code tags are your friend. Know them and use them.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 27, 2006 8:11 pm 
Beginner
Beginner

Joined: Tue Feb 07, 2006 10:39 pm
Posts: 46
what i'm doing is i have a view which allows the user to insert the data into the database and the data will show in a table view.
the problem is when i try to edit data. it keep on pop out the error (' cannot update user').
this is my first time working with the list. so im quite helpless. hope to hear more from u. thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 27, 2006 9:49 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
I can't offer any more suggestions until I know what the error is. Stack traces, log dumps, whatever you've got. There are a couple of ideas in my previous post, try those.

_________________
Code tags are your friend. Know them and use them.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.