I'm developing a Struts2 application as an admin tool for users, passwords and roles. The authentication menthod uses Tomcat j_security. The realm needs two separate mySql DB tables - users and roles.

My problem is passing values using the roles table.The tabe has two columns (userName and roleName). Both are are Strings and both are primary keys. When trying to create a new Role I get the following error:

java.lang.NullPointerException
admin.dao.RoleDAOImpl.createRole(RoleDAOImpl.java:34)
admin.main.RoleManager.create(RoleManager.java:25)
admin.main.RoleAction.create(RoleAction.java:55)
...
...
...

Is this error hapenning beause there's more than one primary key?

I marked where the stack trace is happening in my application files below. Would really appreciate some advice about why I'm getting this error. Please let me know if I need to provide any further information. Thanks in advance!


RoleDAOImpl.java
Code:
public class RoleDAOImpl extends DAOBase implements RoleDAO {

    private static final String CREATE_ROLE_SQL = "INSERT INTO memrole (userName, roleName) VALUES (?, ?)";

    @Override
    public void createRole(Role roleclient) throws DAOException {
        Connection connection = null;
        PreparedStatement ps = null;
        // role=new Role();
        try {
            connection = getConnection();
            System.out.println("*** Roles DB Connection is: "+ connection);
            ps = connection.prepareStatement(CREATE_ROLE_SQL);
// ERROR STARTS HERE            ps.setString(1, roleclient.getUserName());
            System.out.println("*** the created userName is: " + roleclient.getUserName());
            ps.setString(2, roleclient.getRoleName());
            System.out.println("*** the created RoleName is: " + roleclient.getRoleName());
            ps.executeUpdate();
            ps.close();
        } catch (SQLException ex) {
            ex.printStackTrace();
            throw new DAOException();
        } finally {
            try {
                connection.close();
            } catch (SQLException e) {
                e.printStackTrace();
                throw new DAOException();
            }
        }
RoleManager.java

Code:
public class RoleManager {

    public static List<Role> getRole() {
        return search(new RoleSearchCriteria());
    }

    public static void create(Role role) {
        RoleDAO roleDAO = DAOFactory.getInstance().getRoleDAO();
        try {
 ***ERRROR HERE           roleDAO.createRole(role);
            
        } catch (DAOException e) {
            e.printStackTrace();
        }
    }
RoleAction.java:

Code:
package admin.main;

import admin.dao.DAOException;
import admin.dao.RoleDAOImpl;
import static com.opensymphony.xwork2.Action.SUCCESS;
import com.opensymphony.xwork2.ActionSupport;
import java.sql.SQLException;
import java.util.List;

public class RoleAction extends ActionSupport  {

    private Role role;
    private List<Role> roles;
   private String userName;
    // private Role createRole;
   
    public String list() throws SQLException {
        roles = RoleManager.getRole();
        return SUCCESS;
    }

    public String create() {
*** ERROR HERE         RoleManager.create(role);
        return SUCCESS;
    }

    public String edit() {
        return SUCCESS;
    }

    public String update() {
        RoleManager.update(role);
        roles = RoleManager.getRole();
        return SUCCESS;
    }

    public String delete() {
        RoleManager.delete(userName);
        roles = RoleManager.getRole();
        return SUCCESS;
    }

    
   
    public Role getRole() {
        return role;
    }

   
    public void setRole(Role role) {
        this.role = role;
    }

       
    public String getUserName() {
        return userName;
    }
    
       public void setUserName(String userName) {
        this.userName=userName;
    }

        
    public List<Role> getRoles() {
        return roles;
    }

        
    public void setRoles(List<Role> roles) {
        this.roles = roles;
    }
    }