协同办公系统考勤管理出异常,高分求救,能者多拿,帮顶的给辛苦分

时间:2022-08-21 21:29:44
以下是异常:
org.hibernate.NonUniqueResultException: query did not return a unique result: 2 

org.hibernate.impl.AbstractQueryImpl.uniqueElement(AbstractQueryImpl.java:762)
org.hibernate.impl.CriteriaImpl.uniqueResult(CriteriaImpl.java:305)
com.aljoin.oa.core.persistence.HibernateGenericDao.findUniqueBy(HibernateGenericDao.java:210)
com.aljoin.oa.core.persistence.HibernateEntityDao.findUniqueBy(HibernateEntityDao.java:210)
com.aljoin.oa.attendance.service.AttendanceService.getWorkTime(AttendanceService.java:51)
com.aljoin.oa.attendance.service.AttendanceService.createNewMarkRecord(AttendanceService.java:32)
com.aljoin.oa.attendance.service.AttendanceService.getTodayMarkRecord(AttendanceService.java:28)
com.aljoin.oa.attendance.action.MarkCardAction.prepare(MarkCardAction.java:54)
com.opensymphony.xwork.interceptor.PrepareInterceptor.before(PrepareInterceptor.java:28)
com.opensymphony.xwork.interceptor.AroundInterceptor.intercept(AroundInterceptor.java:34)
com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:164)
com.opensymphony.xwork.interceptor.AroundInterceptor.intercept(AroundInterceptor.java:35)
com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:164)
com.opensymphony.xwork.DefaultActionProxy.execute(DefaultActionProxy.java:116)
com.opensymphony.webwork.dispatcher.ServletDispatcher.serviceAction(ServletDispatcher.java:272)
com.opensymphony.webwork.dispatcher.ServletDispatcher.service(ServletDispatcher.java:237)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
com.opensymphony.webwork.lifecycle.RequestLifecycleFilter.doFilter(RequestLifecycleFilter.java:67)
com.aljoin.oa.core.misc.CharacterEncodingFilter.doFilter(CharacterEncodingFilter.java:24)
com.aljoin.oa.core.misc.SessionCheckFilter.doFilter(SessionCheckFilter.java:49)


note The full stack trace of the root cause is available in the Apache Tomcat/6.0.18 logs.


网上也查了些资料 但是还没修改对,忘大家多多提意见

26 个解决方案

#1


com.aljoin.oa.core.persistence.HibernateGenericDao.findUniqueBy(HibernateGenericDao.java:210) 
这行应该使用了uniqueResult这个方法,但是返回的结果却不是唯一的

#2


这个是HibernateGenicDao.java类 下面的findUniqueBy 方法:
 

public <T> T findUniqueBy(Class<T> entityClass, String propertyName, Object value)
  {
    return (T) createCriteria(entityClass, new Criterion[] {Restrictions.eq(propertyName, value) }).uniqueResult();
  }

这个是HibernateEntityDao.java类 下面的findUniqueBy方法
 

public T findUniqueBy(String propertyName, Object value)
  {
    return  (T)((Entity)findUniqueBy(getEntityClass(), propertyName, value));
  }
 
 

package com.aljoin.oa.core.misc;

import java.io.IOException;
import javax.servlet.*;

public class CharacterEncodingFilter
    implements Filter
{

    public CharacterEncodingFilter()
    {
        encoding = "GBK";
    }

     public final void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain)
        throws ServletException, IOException
    {
        request.setCharacterEncoding(encoding);
        filterChain.doFilter(request, response);
    }
    public final void init(FilterConfig filterconfig)
        throws ServletException
    {
    }

    public void destroy()
    {
    }

    private String encoding;
}


 

package com.aljoin.oa.core.misc;

import com.aljoin.oa.core.component.Config;
import com.aljoin.oa.core.misc.specilize.SessionLogoutIF;
import com.aljoin.oa.core.session.AljoinSession;
import com.aljoin.oa.core.session.LoginPoolManager;
import com.aljoin.oa.core.session.impl.LoginInfo;
import com.aljoin.oa.serve.misc.SignatureWriter;
import com.opensymphony.webwork.config.Configuration;
import java.io.IOException;
import java.io.PrintStream;
import javax.servlet.*;
import javax.servlet.http.*;

public class SessionCheckFilter
    implements Filter
{

    public SessionCheckFilter()
    {
    }

     public void doFilter(ServletRequest request, ServletResponse response1, FilterChain filterChain)
        throws ServletException, IOException
    {
        HttpServletRequest res = (HttpServletRequest)request;
        HttpServletResponse response = (HttpServletResponse)response1;
        response.setHeader("P3P", "CP=CAO PSA OUR");
        String str = res.getServletPath();
        System.out.println((new StringBuilder("ASP:")).append(str).toString());
        if(str.indexOf("signature") >= 0)
        {
            filterSignature((HttpServletRequest)request, response);
            return;
        }
        if(isOmsRequest(str))
        {
            System.out.println((new StringBuilder("Remote Address: ")).append(request.getRemoteAddr()).toString());
            if(!validateIP(Configuration.getString("webwork.accept.serverip"), request.getRemoteAddr()))
                return;
        } else
        if(str.indexOf("downloadExchangeAttach") < 0 && !isSpecialRequest(str) && !doSessionCheck(request, res, response).booleanValue())
            return;
        filterChain.doFilter(request, response);
    }

    private Boolean doSessionCheck(ServletRequest request, HttpServletRequest res, HttpServletResponse response)
    {
        HttpSession session = res.getSession();
        String sessionLogoutClass = (new StringBuilder("com.aljoin.oa.core.misc.specilize.SessionLogoutImpl_")).append(Config.getVersion()).toString();
        try
        {
            sl = (SessionLogoutIF)Class.forName(sessionLogoutClass).newInstance();
        }
        catch(InstantiationException e)
        {
            e.printStackTrace();
        }
        catch(IllegalAccessException e)
        {
            e.printStackTrace();
        }
        catch(ClassNotFoundException e)
        {
            e.printStackTrace();
        }
        Long userid = (Long)session.getAttribute("_USERID_");
        if(userid == null)
        {
            sl.sessionLogout(request, response, session);
            return Boolean.valueOf(false);
        }
        String company = (String)session.getAttribute("_COMPANY_");
        AljoinSession aljoinSession = Config.getLoginManager().getAljoinSession(company, userid.longValue());
        if(aljoinSession != null && aljoinSession.getSession().getId() != session.getId())
        {
            if(aljoinSession.getLoginInfo().isMessenger() && aljoinSession.getLoginInfo().isIe())
            {
                return Boolean.valueOf(true);
            } else
            {
                System.out.println(" logout...........");
                sl.sessionLogout(request, response, session);
                return Boolean.valueOf(false);
            }
        } else
        {
            return Boolean.valueOf(true);
        }
    }

    private boolean isSpecialRequest(String request)
    {
        return aspSpecialRequest(request) || isMobileRequest(request) || isGasOuterRequest(request);
    }

    private boolean isGasOuterRequest(String request)
    {
        return request.indexOf("/outer/") >= 0;
    }

    private boolean aspSpecialRequest(String request)
    {
        return request.equals("/index.jsp") || request.equals("/login.jsp") || request.equals("/close.jsp") || request.equals("/login.action") || request.equals("/logout.action") || request.startsWith("/core") || request.indexOf("system_login.jsp") >= 0 || request.indexOf("SystemLogin.action") >= 0 || request.indexOf("/base/DeptTree_dx.action") >= 0 || request.indexOf("/organ/bindUser.action") >= 0 || request.indexOf("/organ/bindUserRun.action") >= 0 || request.indexOf("/organ/modifyUser.action") >= 0;
    }

    private boolean isMobileRequest(String request)
    {
        return request.indexOf("FileDownload.action") >= 0 || request.indexOf("mfileload.action") >= 0 || request.indexOf("mmfileload.action") >= 0 || request.indexOf("user_login.action") >= 0;
    }

    private boolean isOmsRequest(String request)
    {
        return request.startsWith("/serve") || request.startsWith("/checkCorpNum") || request.startsWith("/encryMids") || request.startsWith("/enable") || request.startsWith("/mailattachuploadservlet") || request.startsWith("/decryMids") || request.startsWith("/core/AddCompany") || request.startsWith("/getEnableUserNum") || request.startsWith("/getUsedSpace");
    }

    private void filterSignature(HttpServletRequest request, HttpServletResponse response)
    {
        SignatureWriter sw;
        try
        {
            sw = SignatureWriter.getNewInstance(request);
        }
        catch(Exception e)
        {
            e.printStackTrace();
            return;
        }
        try
        {
            sw.doExecute(response);
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
        return;
    }

    private boolean validateIP(String ips, String reqIp)
    {
        if(ips == "")
            return false;
        String iparray[] = ips.split(",");
        for(int i = 0; i < iparray.length; i++)
            if(iparray[i].equals(reqIp))
                return true;

        return false;
    }

    public final void init(FilterConfig filterconfig)
        throws ServletException
    {
    }

    public void destroy()
    {
    }

    public static void main(String args[])
    {
        System.out.println("http://220.162.241.60:80/core/AddCompany.action?compname=chainyyy136&cshortname=chainyyy136&usernumber=15&maxSpace=1024&stime=2006-08-10&enable=True&shortname=chainyyy136&adminname=admin&adminshortname=admin&__EventSource=addCompany".indexOf("/core/AddCompany"));
    }

    private static SessionLogoutIF sl;
}




这些类我都贴出来了 看看哪里有问题???

#3


我知道它不是唯一的 现在有2个结果,怎么才能让它唯一   

#4


引用 3 楼 lich720520 的回复:
我知道它不是唯一的 现在有2个结果,怎么才能让它唯一

除非你按主键查或者某一列是唯一的
使用uniqueResult方法必须要求能够查到数据且是唯一的一条,多条或没有都会报异常

#5


我刚才把数据库重新导入了一遍,问题解决了,不过在添加部门时现在出现这个异常,

java.lang.NullPointerException
com.aljoin.oa.core.component.HibernateSession.disposeSession(HibernateSession.java:83)
com.aljoin.oa.core.component.HibernateSession.dispose(HibernateSession.java:44)
com.opensymphony.xwork.interceptor.component.DefaultComponentManager.dispose(DefaultComponentManager.java:92)
com.opensymphony.webwork.lifecycle.RequestLifecycleFilter.doFilter(RequestLifecycleFilter.java:73)
com.aljoin.oa.core.misc.CharacterEncodingFilter.doFilter(CharacterEncodingFilter.java:24)
com.aljoin.oa.core.misc.SessionCheckFilter.doFilter(SessionCheckFilter.java:49)

#6


com.aljoin.oa.core.component.HibernateSession.disposeSession(HibernateSession.java:83) 
应该是这行有对象为null

#7



在贴代码块HibernateSession类
public class HibernateSession
  implements Serializable, HibernateControllerAware, Disposable
{
  private static final Log LOG = LogFactory.getLog(HibernateSession.class);
  private Session session;
  private Transaction transaction;
  private boolean rollBackOnly;

  public void commitAndBeginNewTranscation()
  {
    if (this.transaction != null) {
      this.transaction.commit();
      this.session.close();
      this.session = HibernateController.createHibernateSession();
      this.transaction = this.session.beginTransaction();
    }
  }

  public void setSession(Session session) {
    this.session = session;
  }

  public Session getSession() throws HibernateException {
    if (this.session == null) {
      this.session = HibernateController.createHibernateSession();
      this.transaction = this.session.beginTransaction();
    }
    return this.session;
  }

   public void dispose() {
    try {
      disposeSession();
    } catch (HibernateException he) {
      throw new RuntimeException(
        "could not cleanly dispose() HibernateSession", he);
    }
  }

  public void disposeSession() throws HibernateException {
    LOG.debug("disposing");

    if (this.session == null)
      return;
    if (!(this.session.isConnected())) {
      LOG.warn("数据库连接不应该关闭,但是已经关闭");
      return;
    }
    if (this.rollBackOnly)
      try {
        LOG.debug("rolling back");
        if (this.transaction != null)
          this.transaction.rollback();
      } catch (HibernateException e) {
        LOG.error("error during rollback", e);
        throw e;
      } finally {
        this.session.close();
        this.session = null;
        this.transaction = null;
      }
    try
    {
      LOG.debug("committing");
      if (this.transaction != null)
        this.transaction.commit();
    } catch (HibernateException e) {
      LOG.error("error during commit", e);
      this.transaction.rollback();
      throw e;
    } finally {
      this.session.close();
      this.session = null;
      this.transaction = null;
    }
  }

  public boolean isRollBackOnly()
  {
    return this.rollBackOnly;
  }

  public void setRollBackOnly(boolean rollBackOnly) {
    this.rollBackOnly = rollBackOnly;
  }

  public Session getSessionWithoutLogin() {
    if (this.session == null) {
      this.session = Config.getSessionFactory().openSession();
      this.transaction = this.session.beginTransaction();
    }
    return this.session;
  }

  public void setHibernateController(HibernateController factory)
  {
  }
}

#8


public void disposeSession() throws HibernateException {
    LOG.debug("disposing");

    if (this.session == null)
      return;
    if (!(this.session.isConnected())) {
      LOG.warn("数据库连接不应该关闭,但是已经关闭");
      return;
    }
    if (this.rollBackOnly){
      try {
        LOG.debug("rolling back");
        if (this.transaction != null)
          this.transaction.rollback();
      } catch (HibernateException e) {
        LOG.error("error during rollback", e);
        throw e;
      } finally {
        this.session.close();
        this.session = null;
        this.transaction = null;
      }
}else{
    try
    {
      LOG.debug("committing");
      if (this.transaction != null)
        this.transaction.commit();
    } catch (HibernateException e) {
      LOG.error("error during commit", e);
      this.transaction.rollback();
      throw e;
    } finally {
      this.session.close();
      this.session = null;
      this.transaction = null;
    }
}
  } 

这样试试
你原来不给这个this.rollBackOnly是不是为true
第二个try/catch块都会执行的

#9


试了下 在页面中弹出窗口不报异常了 但是窗口什么都没有,一片空白, 我在eclipse后台看了也出现了异常

ASP:/organ/createDept.action
java.lang.NullPointerException
at com.aljoin.oa.orgnize.action.CreateAction.createDept(CreateAction.java:57)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.opensymphony.xwork.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:300)
at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:166)
at com.aljoin.oa.core.interceptor.ValidationFlowInterceptor.intercept(ValidationFlowInterceptor.java:47)
at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:164)
at com.opensymphony.xwork.interceptor.AroundInterceptor.intercept(AroundInterceptor.java:35)
at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:164)
at com.aljoin.oa.core.interceptor.VarInterceptor.intercept(VarInterceptor.java:34)
at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:164)
at com.aljoin.oa.core.interceptor.ExceptionHandlerInterceptor.intercept(ExceptionHandlerInterceptor.java:54)
at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:164)
at com.opensymphony.xwork.interceptor.AroundInterceptor.intercept(AroundInterceptor.java:35)
at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:164)
at com.opensymphony.xwork.interceptor.AroundInterceptor.intercept(AroundInterceptor.java:35)
at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:164)
at com.opensymphony.xwork.interceptor.AroundInterceptor.intercept(AroundInterceptor.java:35)
at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:164)
at com.opensymphony.xwork.interceptor.AroundInterceptor.intercept(AroundInterceptor.java:35)
at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:164)
at com.opensymphony.xwork.interceptor.AroundInterceptor.intercept(AroundInterceptor.java:35)
at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:164)
at com.opensymphony.xwork.interceptor.AroundInterceptor.intercept(AroundInterceptor.java:35)
at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:164)
at com.aljoin.oa.base.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:56)
at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:164)
at com.opensymphony.xwork.DefaultActionProxy.execute(DefaultActionProxy.java:116)
at com.opensymphony.webwork.dispatcher.ServletDispatcher.serviceAction(ServletDispatcher.java:272)
at com.opensymphony.webwork.dispatcher.ServletDispatcher.service(ServletDispatcher.java:237)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.opensymphony.webwork.lifecycle.RequestLifecycleFilter.doFilter(RequestLifecycleFilter.java:67)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.aljoin.oa.core.misc.CharacterEncodingFilter.doFilter(CharacterEncodingFilter.java:24)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.aljoin.oa.core.misc.SessionCheckFilter.doFilter(SessionCheckFilter.java:49)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:619)
ASP:/message/checkMessage.action
ASP:/login.jsp
ASP:/message/checkMessage.action

#10


在贴相关代码
 


  public String createDept()
        throws Exception
    {
        Dept parentDept = (Dept)queryManager.loadById(Dept.class, dept.getParentDept().getId());
         IDGenerator ig = new IDGenerator(queryManager, parentDept.getId().toString());        dept.setId(ig.getDeptID());
        ig.setDeptcode(parentDept.getCode().toString());
        dept.setCode(ig.getDeptCode());
        dept.setDepth(new Short((new Integer(parentDept.getDepth().intValue() + 1)).toString()));
        dept.setIsdept(Boolean.TRUE);
        dept.setUsable(Boolean.TRUE);
        dept.setDescription(mdescription);
        dept.setParentDept(parentDept);
        persistenceManager.save(dept);
        persistenceManager.commitAndBeginNewTranscation(OrgnizeService.getCompanyName());
        exportOrganize();
        persistenceManager.getSession().flush();
        if(createnext != null && createnext.booleanValue())
        {
            createnext = Boolean.FALSE;
            Dept d = new Dept();
            d.setParentDept(parentDept);
            d.setParentText(dept.getParentText());
            dept = d;
            mdescription = null;
            return "next";
        } else
        {
            url = (new StringBuilder("javascript:navi('viewDept.action?dept.id=")).append(dept.getId()).append("');bodyBusy();").toString();
            return "success";
        }
    }

#11


at com.aljoin.oa.orgnize.action.CreateAction.createDept(CreateAction.java:57) 
和上面一样只要是NullPointerException就直接去找哪个对象为null就行了 

#12


引用 10 楼 lich720520 的回复:
在贴相关代码
  
  

    public   String   createDept() 
                throws   Exception 
        { 
                Dept   parentDept   =   (Dept)queryManager.loadById(Dept.class,   dept.getParentDept().getId()); 
               IDGenerator   ig   =   new   IDGenerator(queryManager,   parentDept.getId().toString());                 dept.setId(ig.get…

#13


public class  IDGenerator{

    public IDGenerator(QueryManager queryManager, String deptid)
    {
        this.queryManager = queryManager;
        this.deptid = deptid;
    }

    public synchronized Long getUserID()
        throws Exception
    {
        int b = OrgnizeUtil.COMPANYBIT.intValue();
        String str = deptid.substring(0, (19 + b) / 2);
        List list = queryManager.find((new StringBuilder("select max(user.id) from User user where user.id like '")).append(str).append("%'").toString());
        if(list.size() == 0 || list.get(0) == null)
            return new Long((new StringBuilder(String.valueOf(str))).append("000001").toString());
        User user = (User)queryManager.loadById(User.class, ((Long)list.get(0)).longValue());
        String n = user.getId().toString().substring((19 + b) / 2, 19);
        int i = (new Integer(n)).intValue();
        if(i == 0xf423f)
        {
            throw new SystemException("errors.insertuser");
        } else
        {
            i++;
            return new Long((new StringBuilder(String.valueOf(str))).append(getLeftString((new Integer(i)).toString(), (19 - b) / 2)).toString());
        }
    }

    public synchronized Long getDeptID()
        throws Exception
    {
        int b = OrgnizeUtil.COMPANYBIT.intValue();
        String str = deptid.substring(0, b);
        List list = queryManager.find((new StringBuilder("select max(dept.id) from Dept dept where dept.id like '")).append(str).append("%'").toString());
        Long maxid = (Long)list.get(0);
        int i = (new Integer(maxid.toString().substring(b, (19 + b) / 2))).intValue();
        if(i == 0xf423f)
        {
            throw new SystemException("errors.insertdept");
        } else
        {
            i++;
            return new Long((new StringBuilder(String.valueOf(str))).append(getLeftString((new Integer(i)).toString(), (19 - b) / 2)).append(getZeroString((19 - b) / 2)).toString());
        }
    }

    public synchronized Long getDeptCode()
        throws Exception
    {
        int b = OrgnizeUtil.COMPANYBIT.intValue();
        int c = OrgnizeUtil.CODEBIT.intValue();
        String deptCodeSign = deptcode.substring(3, 5);
        if(!deptCodeSign.equals("00"))
            c = 5;
        int i = deptcode.indexOf("00", c);
        if(i == -1 || i > 14)
            throw new SystemException("errors.insertdept_codelevel");
        String left = deptcode.substring(0, i);
        String right = deptcode.substring(i + 2);
        int j = 17 - i;
        List list = queryManager.find((new StringBuilder("select max(dept.code) from Dept dept where dept.id like ? and dept.usable=true and dept.code like '")).append(left).append("%").append(getZeroString(j)).append("'").toString(), (new StringBuilder(String.valueOf(deptid.substring(0, b)))).append("%").toString(), Hibernate.STRING);
        Long maxid = (Long)list.get(0);
        j = (new Integer(maxid.toString().substring(i, i + 2))).intValue();
        if(j == 99)
        {
            throw new SystemException("errors.insertdept_levelcount");
        } else
        {
            j++;
            return new Long((new StringBuilder(String.valueOf(left))).append(getLeftString((new Integer(j)).toString(), 2)).append(right).toString());
        }
    }

    public Long getDeptCode(int n)
        throws Exception
    {
        int i = deptcode.indexOf("00", 3);
        if(i == -1 || i > 14)
        {
            throw new SystemException("errors.insertdept_codelevel");
        } else
        {
            String left = deptcode.substring(0, i);
            String right = deptcode.substring(i + 2);
            return new Long((new StringBuilder(String.valueOf(left))).append(getLeftString((new Integer(n)).toString(), 2)).append(right).toString());
        }
    }

    public synchronized Long getPositionCode()
        throws Exception
    {
        int b = OrgnizeUtil.COMPANYBIT.intValue();
        int c = OrgnizeUtil.CODEBIT.intValue();
        String str = deptcode.substring(0, 15);
        List list = queryManager.find((new StringBuilder("select max(dept.code) from Dept dept where dept.id like ? and dept.usable=true and dept.code like '")).append(str).append("%'").toString(), (new StringBuilder(String.valueOf(deptid.substring(0, b)))).append("%").toString(), Hibernate.STRING);
        Long maxid = (Long)list.get(0);
        int i = (new Integer(maxid.toString().substring(15, 19))).intValue();
        if(i == 9999)
        {
            throw new SystemException("errors.insertposition");
        } else
        {
            i++;
            return new Long((new StringBuilder(String.valueOf(str))).append(getLeftString((new Integer(i)).toString(), 4)).toString());
        }
    }

    public Long getPositionCode(int n)
        throws Exception
    {
        String str = deptcode.substring(0, 15);
        return new Long((new StringBuilder(String.valueOf(str))).append(getLeftString((new Integer(n)).toString(), 4)).toString());
    }

    private String getZeroString(int bit)
    {
        StringBuffer s = new StringBuffer();
        for(int i = 0; i < bit; i++)
            s.append("0");

        return s.toString();
    }

    private String getLeftString(String num, int bit)
    {
        int r = bit - num.length();
        StringBuffer s = new StringBuffer();
        for(int i = 0; i < r; i++)
            s.append("0");

        return s.append(num).toString();
    }

    public static String getRightString(String num, int bit)
    {
        int r = bit - num.length();
        StringBuffer s = new StringBuffer();
        for(int i = 0; i < r; i++)
            s.append("0");

        return s.insert(0, num).toString();
    }

    public void setDeptcode(String deptcode)
    {
        this.deptcode = deptcode;
    }

    public static final void main(String args[])
    {
        String id = "111010100000000";
        id.indexOf("00");
        System.out.println(id.substring(3, 5));
    }

    public static boolean isDeptId(Long id)
    {
        String strId = id.toString();
        if(strId.length() != 19)
            return false;
        else
            return strId.endsWith("000000");
    }

    private static final String DEPTID_END = "000000";
    private QueryManager queryManager;
    private String deptid;
    private String deptcode;
}

#14


学习!

#15


照你给出的我估计最有可能是这部分有问题
 parentDept.getId().toString()

#16


  public  String createDept()
        throws Exception
    { System.out.println("????????????????????????");
        Dept parentDept = (Dept)queryManager.loadById(Dept.class, dept.getParentDept().getId());
        IDGenerator ig = new IDGenerator(queryManager, parentDept.getId().toString());
        

        System.out.println("ig============="+ig);
        
        dept.setId(ig.getDeptID());


这个当中上面的???都出来 下面就没进去,一点反应也没 
ASP:/organ/createDept.action
????????????????????????
java.lang.NullPointerException
at com.aljoin.oa.orgnize.action.CreateAction.createDept(CreateAction.java:57)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.opensymphony.xwork.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:300)
at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:166)
at com.aljoin.oa.core.interceptor.ValidationFlowInterceptor.intercept(ValidationFlowInterceptor.java:47)
at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:164)
at com.opensymphony.xwork.interceptor.AroundInterceptor.intercept(AroundInterceptor.java:35)
at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:164)
at com.aljoin.oa.core.interceptor.VarInterceptor.intercept(VarInterceptor.java:34)
at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:164)
at com.aljoin.oa.core.interceptor.ExceptionHandlerInterceptor.intercept(ExceptionHandlerInterceptor.java:54)
at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:164)
at com.opensymphony.xwork.interceptor.AroundInterceptor.intercept(AroundInterceptor.java:35)
at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:164)
at com.opensymphony.xwork.interceptor.AroundInterceptor.intercept(AroundInterceptor.java:35)
at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:164)
at com.opensymphony.xwork.interceptor.AroundInterceptor.intercept(AroundInterceptor.java:35)
at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:164)
at com.opensymphony.xwork.interceptor.AroundInterceptor.intercept(AroundInterceptor.java:35)
at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:164)
at com.opensymphony.xwork.interceptor.AroundInterceptor.intercept(AroundInterceptor.java:35)
at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:164)
at com.opensymphony.xwork.interceptor.AroundInterceptor.intercept(AroundInterceptor.java:35)
at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:164)
at com.aljoin.oa.base.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:56)
at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:164)
at com.opensymphony.xwork.DefaultActionProxy.execute(DefaultActionProxy.java:116)
at com.opensymphony.webwork.dispatcher.ServletDispatcher.serviceAction(ServletDispatcher.java:272)
at com.opensymphony.webwork.dispatcher.ServletDispatcher.service(ServletDispatcher.java:237)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.opensymphony.webwork.lifecycle.RequestLifecycleFilter.doFilter(RequestLifecycleFilter.java:67)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.aljoin.oa.core.misc.CharacterEncodingFilter.doFilter(CharacterEncodingFilter.java:24)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.aljoin.oa.core.misc.SessionCheckFilter.doFilter(SessionCheckFilter.java:49)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:619)

#17


System.out.println("????????????????????????");
        Dept parentDept = (Dept)queryManager.loadById(Dept.class, dept.getParentDept().getId());
        System.out.println("parentDept=========="+parentDept);
        IDGenerator ig = new IDGenerator(queryManager, parentDept.getId().toString());
        System.out.println("ig============="+ig);

打印出
????????????????????????
parentDept==========null
java.lang.NullPointerException

#18


在贴::QueryManager类


public class QueryManager
  implements Serializable, GenericDaoAware
{
  private GenericDao genericDao;

   public <T> T loadById(Class<T> entity, long id)
  {
    return (T) this.genericDao.getById(entity, Long.valueOf(id));
  }

  public <T> T loadById(Class<T> entity, Serializable id) {
    return (T) this.genericDao.getById(entity, id);
  }

  public <T> T getById(Class<T> entity, Serializable id) {
    return (T) this.genericDao.getById(entity, id);
  }

  public Object load(String query, Object value) throws Exception {
    Query queryObject = this.genericDao.createQuery(query, new Object[0]);
    queryObject.setParameter(0, value);
    return queryObject.uniqueResult();
  }

  public <T> List<T> findAll(Class<T> entity) {
    return this.genericDao.getAll(entity);
  }

  public List findAllByCId(Class entity, String field) throws Exception {
    return this.genericDao.find("from " + entity.getName() + " where " + field + " like '" + OrgnizeService.getCorpId() + "%'", new Object[0]);
  }

  public List find(String query) throws Exception {
    return this.genericDao.createQuery(combineQuery(query), new Object[0]).list();
  }

  public List find(String queryString, Object value) throws Exception {
    return this.genericDao.find(queryString, new Object[] { value });
  }

  public List findByCId(String query, String field) throws Exception {
    query = analyseSql(query, field);
    return this.genericDao.find(query, new Object[0]);
  }

  public List findByCId(String queryString, Object value, String field) throws Exception {
    queryString = analyseSql(queryString, field);
    return this.genericDao.find(queryString, new Object[] { value });
  }

  public List find(String queryString, Object value, Type type) throws Exception {
    Query queryObject = this.genericDao.createQuery(combineQuery(queryString), new Object[0]);
    queryObject.setParameter(0, value, type);
    return queryObject.list();
  }

//  public List find(String queryString, String value, Type type) throws Exception
//  {
//    return find(queryString, value, type);
//  }

  public List find(String queryString, Object[] values) throws Exception {
    String combineQuery = combineQuery(queryString);
    return this.genericDao.find(combineQuery, values);
  }

  public List find(String queryString, Object[] values, Type[] types) throws Exception {
    Query queryObject = this.genericDao.createQuery(queryString, new Object[0]);
    for (int i = 0; i < values.length; ++i)
      queryObject.setParameter(i, values[i], types[i]);

    return queryObject.list();
  }

  public List paginationFind(String query, int startIndex, int pageSize) throws Exception {
    Query queryObject = this.genericDao.createQuery(combineQuery(query), new Object[0]);
    queryObject.setFirstResult(startIndex);
    queryObject.setMaxResults(pageSize);
    return queryObject.list();
  }

  public List paginationFindByCId(String query, int startIndex, int pageSize, String field) throws Exception {
    query = analyseSql(query, field);
    return paginationFind(query, startIndex, pageSize);
  }

  public List paginationFind(String query, Object value, int startIndex, int pageSize) throws Exception {
    Query queryObject = this.genericDao.createQuery(combineQuery(query), new Object[0]);
    queryObject.setParameter(0, value);
    queryObject.setFirstResult(startIndex);
    queryObject.setMaxResults(pageSize);
    return queryObject.list();
  }

  public List paginationFindByCId(String query, Object value, int startIndex, int pageSize, String field) throws Exception {
    query = analyseSql(query, field);
    return paginationFind(query, value, startIndex, pageSize);
  }

  public List paginationFind(String query, Object value, Type type, int startIndex, int pageSize) throws Exception {
    Query queryObject = this.genericDao.createQuery(combineQuery(query), new Object[0]);
    queryObject.setParameter(0, value, type);
    queryObject.setFirstResult(startIndex);
    queryObject.setMaxResults(pageSize);
    return queryObject.list();
  }

  private String combineQuery(String query) {
    if (query.indexOf(":corpId") > 0)
      query = StringUtils.replace(query, ":corpId", "'" + OrgnizeService.getCorpId() + "%" + "'");

    return query;
  }

  public List paginationFind(String query, Object[] values, int startIndex, int pageSize) throws Exception {
    Query queryObject = this.genericDao.createQuery(combineQuery(query), new Object[0]);
    for (int i = 0; i < values.length; ++i)
      queryObject.setParameter(i, values[i]);

    queryObject.setFirstResult(startIndex);
    queryObject.setMaxResults(pageSize);
    return queryObject.list();
  }

  public List paginationFind(String query, Object[] values, Type[] types, int startIndex, int pageSize) throws Exception {
    Query queryObject = this.genericDao.createQuery(combineQuery(query), new Object[0]);
    for (int i = 0; i < values.length; ++i)
      queryObject.setParameter(i, values[i], types[i]);

    queryObject.setFirstResult(startIndex);
    queryObject.setMaxResults(pageSize);

    return queryObject.list();
  }

  private String analyseSql(String queryString, String field) {
    int indexofWhere = queryString.toLowerCase().indexOf("where");
    if (indexofWhere != -1) {
      String firstSql = queryString.substring(0, indexofWhere + 5);
      String secondsql = queryString.substring(indexofWhere + 6, queryString.length());
      queryString = firstSql + " " + field + " like '" + OrgnizeService.getCorpId() + "%' and " + secondsql;
    } else {
      int indexofFrom = queryString.toLowerCase().indexOf("order by");
      if (indexofFrom != -1) {
        String sql1 = queryString.substring(0, indexofFrom - 1);
        String sql2 = queryString.substring(indexofFrom, queryString.length());
        queryString = sql1 + " where " + field + " like '" + OrgnizeService.getCorpId() + "%' " + sql2;
      } else {
        queryString = queryString + " where " + field + " like '" + OrgnizeService.getCorpId() + "%'";
      }
    }

    return queryString;
  }

  public Session getSession()
  {
    return this.genericDao.getSession();
  }

  public void disposeSession() {
    this.genericDao.disposeSession();
  }

  public void setGenericDao(GenericDao genericDao) {
    this.genericDao = genericDao;
  }
}

#19


这就要看数据库中是否有主键为dept.getParentDept().getId()这个的记录了

#20


 return (T) this.genericDao.getById(entity, Long.valueOf(id)); 
   的getById方法都是调用HibernateGenicDao中的 


public class HibernateGenericDao
{
  private static final Logger LOGGER = Logger.getLogger(HibernateGenericDao.class);
  private Session session;
  protected HibernateSession hibernateSession;

  public Session getSession()
  {
    if ((this.session != null) && (this.session.isOpen())) {
      return this.session;
    }

    this.session = this.hibernateSession.getSession();
    return this.session;
  }

  @SuppressWarnings("unchecked")
public <T> T loadById(Class<T> entityClass, Serializable id)
  {
    try
    {
      return (T) getSession().load(entityClass, id);
    } catch (Exception e) {
      e.printStackTrace();
      LOGGER.warn(e.getMessage());
      return null;
    }
  }

  @SuppressWarnings("unchecked")
public <T> T getById(Class<T> entityClass, Serializable id)
  {
    return (T) getSession().get(entityClass, id);
  }
  
@SuppressWarnings("unchecked")
public <T> List<T> getAll(Class<T> entityClass)
  {
    return getSession().createQuery("from " + entityClass.getName()).list();
  }

  public void save(Entity entity)
  {
    try
    {
      Class<? extends Entity> clazz = entity.getClass();
      Method method = clazz.getMethod("setCompanyId", new Class[] { Long.class });
      if (method != null)
        method.invoke(entity, new Object[] { OrgnizeService.getCompanyid() });
    }
    catch (Exception clazz) {
    }
    getSession().saveOrUpdate(entity);
  }




我一直都对这个里面报有问题,还有个是HibernateEentityDao  

#21


数据库是没有问题的 ,这个是一个合强的办公系统, 代码都是我反编译过来的,安装版本是可以跑的,反编译后出现的错误,我修改的可能不合理

#22


oooo

#23


顶一个.

#24


引用 23 楼 mike_24 的回复:
顶一个.

顶一个.

#25


要怎么看数据库中是否有主键为dept.getParentDept().getId()这个的记录  
协同办公系统考勤管理出异常,高分求救,能者多拿,帮顶的给辛苦分

#26


回答的都有分啊 呵呵  

#1


com.aljoin.oa.core.persistence.HibernateGenericDao.findUniqueBy(HibernateGenericDao.java:210) 
这行应该使用了uniqueResult这个方法,但是返回的结果却不是唯一的

#2


这个是HibernateGenicDao.java类 下面的findUniqueBy 方法:
 

public <T> T findUniqueBy(Class<T> entityClass, String propertyName, Object value)
  {
    return (T) createCriteria(entityClass, new Criterion[] {Restrictions.eq(propertyName, value) }).uniqueResult();
  }

这个是HibernateEntityDao.java类 下面的findUniqueBy方法
 

public T findUniqueBy(String propertyName, Object value)
  {
    return  (T)((Entity)findUniqueBy(getEntityClass(), propertyName, value));
  }
 
 

package com.aljoin.oa.core.misc;

import java.io.IOException;
import javax.servlet.*;

public class CharacterEncodingFilter
    implements Filter
{

    public CharacterEncodingFilter()
    {
        encoding = "GBK";
    }

     public final void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain)
        throws ServletException, IOException
    {
        request.setCharacterEncoding(encoding);
        filterChain.doFilter(request, response);
    }
    public final void init(FilterConfig filterconfig)
        throws ServletException
    {
    }

    public void destroy()
    {
    }

    private String encoding;
}


 

package com.aljoin.oa.core.misc;

import com.aljoin.oa.core.component.Config;
import com.aljoin.oa.core.misc.specilize.SessionLogoutIF;
import com.aljoin.oa.core.session.AljoinSession;
import com.aljoin.oa.core.session.LoginPoolManager;
import com.aljoin.oa.core.session.impl.LoginInfo;
import com.aljoin.oa.serve.misc.SignatureWriter;
import com.opensymphony.webwork.config.Configuration;
import java.io.IOException;
import java.io.PrintStream;
import javax.servlet.*;
import javax.servlet.http.*;

public class SessionCheckFilter
    implements Filter
{

    public SessionCheckFilter()
    {
    }

     public void doFilter(ServletRequest request, ServletResponse response1, FilterChain filterChain)
        throws ServletException, IOException
    {
        HttpServletRequest res = (HttpServletRequest)request;
        HttpServletResponse response = (HttpServletResponse)response1;
        response.setHeader("P3P", "CP=CAO PSA OUR");
        String str = res.getServletPath();
        System.out.println((new StringBuilder("ASP:")).append(str).toString());
        if(str.indexOf("signature") >= 0)
        {
            filterSignature((HttpServletRequest)request, response);
            return;
        }
        if(isOmsRequest(str))
        {
            System.out.println((new StringBuilder("Remote Address: ")).append(request.getRemoteAddr()).toString());
            if(!validateIP(Configuration.getString("webwork.accept.serverip"), request.getRemoteAddr()))
                return;
        } else
        if(str.indexOf("downloadExchangeAttach") < 0 && !isSpecialRequest(str) && !doSessionCheck(request, res, response).booleanValue())
            return;
        filterChain.doFilter(request, response);
    }

    private Boolean doSessionCheck(ServletRequest request, HttpServletRequest res, HttpServletResponse response)
    {
        HttpSession session = res.getSession();
        String sessionLogoutClass = (new StringBuilder("com.aljoin.oa.core.misc.specilize.SessionLogoutImpl_")).append(Config.getVersion()).toString();
        try
        {
            sl = (SessionLogoutIF)Class.forName(sessionLogoutClass).newInstance();
        }
        catch(InstantiationException e)
        {
            e.printStackTrace();
        }
        catch(IllegalAccessException e)
        {
            e.printStackTrace();
        }
        catch(ClassNotFoundException e)
        {
            e.printStackTrace();
        }
        Long userid = (Long)session.getAttribute("_USERID_");
        if(userid == null)
        {
            sl.sessionLogout(request, response, session);
            return Boolean.valueOf(false);
        }
        String company = (String)session.getAttribute("_COMPANY_");
        AljoinSession aljoinSession = Config.getLoginManager().getAljoinSession(company, userid.longValue());
        if(aljoinSession != null && aljoinSession.getSession().getId() != session.getId())
        {
            if(aljoinSession.getLoginInfo().isMessenger() && aljoinSession.getLoginInfo().isIe())
            {
                return Boolean.valueOf(true);
            } else
            {
                System.out.println(" logout...........");
                sl.sessionLogout(request, response, session);
                return Boolean.valueOf(false);
            }
        } else
        {
            return Boolean.valueOf(true);
        }
    }

    private boolean isSpecialRequest(String request)
    {
        return aspSpecialRequest(request) || isMobileRequest(request) || isGasOuterRequest(request);
    }

    private boolean isGasOuterRequest(String request)
    {
        return request.indexOf("/outer/") >= 0;
    }

    private boolean aspSpecialRequest(String request)
    {
        return request.equals("/index.jsp") || request.equals("/login.jsp") || request.equals("/close.jsp") || request.equals("/login.action") || request.equals("/logout.action") || request.startsWith("/core") || request.indexOf("system_login.jsp") >= 0 || request.indexOf("SystemLogin.action") >= 0 || request.indexOf("/base/DeptTree_dx.action") >= 0 || request.indexOf("/organ/bindUser.action") >= 0 || request.indexOf("/organ/bindUserRun.action") >= 0 || request.indexOf("/organ/modifyUser.action") >= 0;
    }

    private boolean isMobileRequest(String request)
    {
        return request.indexOf("FileDownload.action") >= 0 || request.indexOf("mfileload.action") >= 0 || request.indexOf("mmfileload.action") >= 0 || request.indexOf("user_login.action") >= 0;
    }

    private boolean isOmsRequest(String request)
    {
        return request.startsWith("/serve") || request.startsWith("/checkCorpNum") || request.startsWith("/encryMids") || request.startsWith("/enable") || request.startsWith("/mailattachuploadservlet") || request.startsWith("/decryMids") || request.startsWith("/core/AddCompany") || request.startsWith("/getEnableUserNum") || request.startsWith("/getUsedSpace");
    }

    private void filterSignature(HttpServletRequest request, HttpServletResponse response)
    {
        SignatureWriter sw;
        try
        {
            sw = SignatureWriter.getNewInstance(request);
        }
        catch(Exception e)
        {
            e.printStackTrace();
            return;
        }
        try
        {
            sw.doExecute(response);
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
        return;
    }

    private boolean validateIP(String ips, String reqIp)
    {
        if(ips == "")
            return false;
        String iparray[] = ips.split(",");
        for(int i = 0; i < iparray.length; i++)
            if(iparray[i].equals(reqIp))
                return true;

        return false;
    }

    public final void init(FilterConfig filterconfig)
        throws ServletException
    {
    }

    public void destroy()
    {
    }

    public static void main(String args[])
    {
        System.out.println("http://220.162.241.60:80/core/AddCompany.action?compname=chainyyy136&cshortname=chainyyy136&usernumber=15&maxSpace=1024&stime=2006-08-10&enable=True&shortname=chainyyy136&adminname=admin&adminshortname=admin&__EventSource=addCompany".indexOf("/core/AddCompany"));
    }

    private static SessionLogoutIF sl;
}




这些类我都贴出来了 看看哪里有问题???

#3


我知道它不是唯一的 现在有2个结果,怎么才能让它唯一   

#4


引用 3 楼 lich720520 的回复:
我知道它不是唯一的 现在有2个结果,怎么才能让它唯一

除非你按主键查或者某一列是唯一的
使用uniqueResult方法必须要求能够查到数据且是唯一的一条,多条或没有都会报异常

#5


我刚才把数据库重新导入了一遍,问题解决了,不过在添加部门时现在出现这个异常,

java.lang.NullPointerException
com.aljoin.oa.core.component.HibernateSession.disposeSession(HibernateSession.java:83)
com.aljoin.oa.core.component.HibernateSession.dispose(HibernateSession.java:44)
com.opensymphony.xwork.interceptor.component.DefaultComponentManager.dispose(DefaultComponentManager.java:92)
com.opensymphony.webwork.lifecycle.RequestLifecycleFilter.doFilter(RequestLifecycleFilter.java:73)
com.aljoin.oa.core.misc.CharacterEncodingFilter.doFilter(CharacterEncodingFilter.java:24)
com.aljoin.oa.core.misc.SessionCheckFilter.doFilter(SessionCheckFilter.java:49)

#6


com.aljoin.oa.core.component.HibernateSession.disposeSession(HibernateSession.java:83) 
应该是这行有对象为null

#7



在贴代码块HibernateSession类
public class HibernateSession
  implements Serializable, HibernateControllerAware, Disposable
{
  private static final Log LOG = LogFactory.getLog(HibernateSession.class);
  private Session session;
  private Transaction transaction;
  private boolean rollBackOnly;

  public void commitAndBeginNewTranscation()
  {
    if (this.transaction != null) {
      this.transaction.commit();
      this.session.close();
      this.session = HibernateController.createHibernateSession();
      this.transaction = this.session.beginTransaction();
    }
  }

  public void setSession(Session session) {
    this.session = session;
  }

  public Session getSession() throws HibernateException {
    if (this.session == null) {
      this.session = HibernateController.createHibernateSession();
      this.transaction = this.session.beginTransaction();
    }
    return this.session;
  }

   public void dispose() {
    try {
      disposeSession();
    } catch (HibernateException he) {
      throw new RuntimeException(
        "could not cleanly dispose() HibernateSession", he);
    }
  }

  public void disposeSession() throws HibernateException {
    LOG.debug("disposing");

    if (this.session == null)
      return;
    if (!(this.session.isConnected())) {
      LOG.warn("数据库连接不应该关闭,但是已经关闭");
      return;
    }
    if (this.rollBackOnly)
      try {
        LOG.debug("rolling back");
        if (this.transaction != null)
          this.transaction.rollback();
      } catch (HibernateException e) {
        LOG.error("error during rollback", e);
        throw e;
      } finally {
        this.session.close();
        this.session = null;
        this.transaction = null;
      }
    try
    {
      LOG.debug("committing");
      if (this.transaction != null)
        this.transaction.commit();
    } catch (HibernateException e) {
      LOG.error("error during commit", e);
      this.transaction.rollback();
      throw e;
    } finally {
      this.session.close();
      this.session = null;
      this.transaction = null;
    }
  }

  public boolean isRollBackOnly()
  {
    return this.rollBackOnly;
  }

  public void setRollBackOnly(boolean rollBackOnly) {
    this.rollBackOnly = rollBackOnly;
  }

  public Session getSessionWithoutLogin() {
    if (this.session == null) {
      this.session = Config.getSessionFactory().openSession();
      this.transaction = this.session.beginTransaction();
    }
    return this.session;
  }

  public void setHibernateController(HibernateController factory)
  {
  }
}

#8


public void disposeSession() throws HibernateException {
    LOG.debug("disposing");

    if (this.session == null)
      return;
    if (!(this.session.isConnected())) {
      LOG.warn("数据库连接不应该关闭,但是已经关闭");
      return;
    }
    if (this.rollBackOnly){
      try {
        LOG.debug("rolling back");
        if (this.transaction != null)
          this.transaction.rollback();
      } catch (HibernateException e) {
        LOG.error("error during rollback", e);
        throw e;
      } finally {
        this.session.close();
        this.session = null;
        this.transaction = null;
      }
}else{
    try
    {
      LOG.debug("committing");
      if (this.transaction != null)
        this.transaction.commit();
    } catch (HibernateException e) {
      LOG.error("error during commit", e);
      this.transaction.rollback();
      throw e;
    } finally {
      this.session.close();
      this.session = null;
      this.transaction = null;
    }
}
  } 

这样试试
你原来不给这个this.rollBackOnly是不是为true
第二个try/catch块都会执行的

#9


试了下 在页面中弹出窗口不报异常了 但是窗口什么都没有,一片空白, 我在eclipse后台看了也出现了异常

ASP:/organ/createDept.action
java.lang.NullPointerException
at com.aljoin.oa.orgnize.action.CreateAction.createDept(CreateAction.java:57)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.opensymphony.xwork.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:300)
at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:166)
at com.aljoin.oa.core.interceptor.ValidationFlowInterceptor.intercept(ValidationFlowInterceptor.java:47)
at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:164)
at com.opensymphony.xwork.interceptor.AroundInterceptor.intercept(AroundInterceptor.java:35)
at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:164)
at com.aljoin.oa.core.interceptor.VarInterceptor.intercept(VarInterceptor.java:34)
at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:164)
at com.aljoin.oa.core.interceptor.ExceptionHandlerInterceptor.intercept(ExceptionHandlerInterceptor.java:54)
at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:164)
at com.opensymphony.xwork.interceptor.AroundInterceptor.intercept(AroundInterceptor.java:35)
at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:164)
at com.opensymphony.xwork.interceptor.AroundInterceptor.intercept(AroundInterceptor.java:35)
at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:164)
at com.opensymphony.xwork.interceptor.AroundInterceptor.intercept(AroundInterceptor.java:35)
at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:164)
at com.opensymphony.xwork.interceptor.AroundInterceptor.intercept(AroundInterceptor.java:35)
at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:164)
at com.opensymphony.xwork.interceptor.AroundInterceptor.intercept(AroundInterceptor.java:35)
at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:164)
at com.opensymphony.xwork.interceptor.AroundInterceptor.intercept(AroundInterceptor.java:35)
at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:164)
at com.aljoin.oa.base.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:56)
at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:164)
at com.opensymphony.xwork.DefaultActionProxy.execute(DefaultActionProxy.java:116)
at com.opensymphony.webwork.dispatcher.ServletDispatcher.serviceAction(ServletDispatcher.java:272)
at com.opensymphony.webwork.dispatcher.ServletDispatcher.service(ServletDispatcher.java:237)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.opensymphony.webwork.lifecycle.RequestLifecycleFilter.doFilter(RequestLifecycleFilter.java:67)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.aljoin.oa.core.misc.CharacterEncodingFilter.doFilter(CharacterEncodingFilter.java:24)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.aljoin.oa.core.misc.SessionCheckFilter.doFilter(SessionCheckFilter.java:49)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:619)
ASP:/message/checkMessage.action
ASP:/login.jsp
ASP:/message/checkMessage.action

#10


在贴相关代码
 


  public String createDept()
        throws Exception
    {
        Dept parentDept = (Dept)queryManager.loadById(Dept.class, dept.getParentDept().getId());
         IDGenerator ig = new IDGenerator(queryManager, parentDept.getId().toString());        dept.setId(ig.getDeptID());
        ig.setDeptcode(parentDept.getCode().toString());
        dept.setCode(ig.getDeptCode());
        dept.setDepth(new Short((new Integer(parentDept.getDepth().intValue() + 1)).toString()));
        dept.setIsdept(Boolean.TRUE);
        dept.setUsable(Boolean.TRUE);
        dept.setDescription(mdescription);
        dept.setParentDept(parentDept);
        persistenceManager.save(dept);
        persistenceManager.commitAndBeginNewTranscation(OrgnizeService.getCompanyName());
        exportOrganize();
        persistenceManager.getSession().flush();
        if(createnext != null && createnext.booleanValue())
        {
            createnext = Boolean.FALSE;
            Dept d = new Dept();
            d.setParentDept(parentDept);
            d.setParentText(dept.getParentText());
            dept = d;
            mdescription = null;
            return "next";
        } else
        {
            url = (new StringBuilder("javascript:navi('viewDept.action?dept.id=")).append(dept.getId()).append("');bodyBusy();").toString();
            return "success";
        }
    }

#11


at com.aljoin.oa.orgnize.action.CreateAction.createDept(CreateAction.java:57) 
和上面一样只要是NullPointerException就直接去找哪个对象为null就行了 

#12


引用 10 楼 lich720520 的回复:
在贴相关代码
  
  

    public   String   createDept() 
                throws   Exception 
        { 
                Dept   parentDept   =   (Dept)queryManager.loadById(Dept.class,   dept.getParentDept().getId()); 
               IDGenerator   ig   =   new   IDGenerator(queryManager,   parentDept.getId().toString());                 dept.setId(ig.get…

#13


public class  IDGenerator{

    public IDGenerator(QueryManager queryManager, String deptid)
    {
        this.queryManager = queryManager;
        this.deptid = deptid;
    }

    public synchronized Long getUserID()
        throws Exception
    {
        int b = OrgnizeUtil.COMPANYBIT.intValue();
        String str = deptid.substring(0, (19 + b) / 2);
        List list = queryManager.find((new StringBuilder("select max(user.id) from User user where user.id like '")).append(str).append("%'").toString());
        if(list.size() == 0 || list.get(0) == null)
            return new Long((new StringBuilder(String.valueOf(str))).append("000001").toString());
        User user = (User)queryManager.loadById(User.class, ((Long)list.get(0)).longValue());
        String n = user.getId().toString().substring((19 + b) / 2, 19);
        int i = (new Integer(n)).intValue();
        if(i == 0xf423f)
        {
            throw new SystemException("errors.insertuser");
        } else
        {
            i++;
            return new Long((new StringBuilder(String.valueOf(str))).append(getLeftString((new Integer(i)).toString(), (19 - b) / 2)).toString());
        }
    }

    public synchronized Long getDeptID()
        throws Exception
    {
        int b = OrgnizeUtil.COMPANYBIT.intValue();
        String str = deptid.substring(0, b);
        List list = queryManager.find((new StringBuilder("select max(dept.id) from Dept dept where dept.id like '")).append(str).append("%'").toString());
        Long maxid = (Long)list.get(0);
        int i = (new Integer(maxid.toString().substring(b, (19 + b) / 2))).intValue();
        if(i == 0xf423f)
        {
            throw new SystemException("errors.insertdept");
        } else
        {
            i++;
            return new Long((new StringBuilder(String.valueOf(str))).append(getLeftString((new Integer(i)).toString(), (19 - b) / 2)).append(getZeroString((19 - b) / 2)).toString());
        }
    }

    public synchronized Long getDeptCode()
        throws Exception
    {
        int b = OrgnizeUtil.COMPANYBIT.intValue();
        int c = OrgnizeUtil.CODEBIT.intValue();
        String deptCodeSign = deptcode.substring(3, 5);
        if(!deptCodeSign.equals("00"))
            c = 5;
        int i = deptcode.indexOf("00", c);
        if(i == -1 || i > 14)
            throw new SystemException("errors.insertdept_codelevel");
        String left = deptcode.substring(0, i);
        String right = deptcode.substring(i + 2);
        int j = 17 - i;
        List list = queryManager.find((new StringBuilder("select max(dept.code) from Dept dept where dept.id like ? and dept.usable=true and dept.code like '")).append(left).append("%").append(getZeroString(j)).append("'").toString(), (new StringBuilder(String.valueOf(deptid.substring(0, b)))).append("%").toString(), Hibernate.STRING);
        Long maxid = (Long)list.get(0);
        j = (new Integer(maxid.toString().substring(i, i + 2))).intValue();
        if(j == 99)
        {
            throw new SystemException("errors.insertdept_levelcount");
        } else
        {
            j++;
            return new Long((new StringBuilder(String.valueOf(left))).append(getLeftString((new Integer(j)).toString(), 2)).append(right).toString());
        }
    }

    public Long getDeptCode(int n)
        throws Exception
    {
        int i = deptcode.indexOf("00", 3);
        if(i == -1 || i > 14)
        {
            throw new SystemException("errors.insertdept_codelevel");
        } else
        {
            String left = deptcode.substring(0, i);
            String right = deptcode.substring(i + 2);
            return new Long((new StringBuilder(String.valueOf(left))).append(getLeftString((new Integer(n)).toString(), 2)).append(right).toString());
        }
    }

    public synchronized Long getPositionCode()
        throws Exception
    {
        int b = OrgnizeUtil.COMPANYBIT.intValue();
        int c = OrgnizeUtil.CODEBIT.intValue();
        String str = deptcode.substring(0, 15);
        List list = queryManager.find((new StringBuilder("select max(dept.code) from Dept dept where dept.id like ? and dept.usable=true and dept.code like '")).append(str).append("%'").toString(), (new StringBuilder(String.valueOf(deptid.substring(0, b)))).append("%").toString(), Hibernate.STRING);
        Long maxid = (Long)list.get(0);
        int i = (new Integer(maxid.toString().substring(15, 19))).intValue();
        if(i == 9999)
        {
            throw new SystemException("errors.insertposition");
        } else
        {
            i++;
            return new Long((new StringBuilder(String.valueOf(str))).append(getLeftString((new Integer(i)).toString(), 4)).toString());
        }
    }

    public Long getPositionCode(int n)
        throws Exception
    {
        String str = deptcode.substring(0, 15);
        return new Long((new StringBuilder(String.valueOf(str))).append(getLeftString((new Integer(n)).toString(), 4)).toString());
    }

    private String getZeroString(int bit)
    {
        StringBuffer s = new StringBuffer();
        for(int i = 0; i < bit; i++)
            s.append("0");

        return s.toString();
    }

    private String getLeftString(String num, int bit)
    {
        int r = bit - num.length();
        StringBuffer s = new StringBuffer();
        for(int i = 0; i < r; i++)
            s.append("0");

        return s.append(num).toString();
    }

    public static String getRightString(String num, int bit)
    {
        int r = bit - num.length();
        StringBuffer s = new StringBuffer();
        for(int i = 0; i < r; i++)
            s.append("0");

        return s.insert(0, num).toString();
    }

    public void setDeptcode(String deptcode)
    {
        this.deptcode = deptcode;
    }

    public static final void main(String args[])
    {
        String id = "111010100000000";
        id.indexOf("00");
        System.out.println(id.substring(3, 5));
    }

    public static boolean isDeptId(Long id)
    {
        String strId = id.toString();
        if(strId.length() != 19)
            return false;
        else
            return strId.endsWith("000000");
    }

    private static final String DEPTID_END = "000000";
    private QueryManager queryManager;
    private String deptid;
    private String deptcode;
}

#14


学习!

#15


照你给出的我估计最有可能是这部分有问题
 parentDept.getId().toString()

#16


  public  String createDept()
        throws Exception
    { System.out.println("????????????????????????");
        Dept parentDept = (Dept)queryManager.loadById(Dept.class, dept.getParentDept().getId());
        IDGenerator ig = new IDGenerator(queryManager, parentDept.getId().toString());
        

        System.out.println("ig============="+ig);
        
        dept.setId(ig.getDeptID());


这个当中上面的???都出来 下面就没进去,一点反应也没 
ASP:/organ/createDept.action
????????????????????????
java.lang.NullPointerException
at com.aljoin.oa.orgnize.action.CreateAction.createDept(CreateAction.java:57)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.opensymphony.xwork.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:300)
at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:166)
at com.aljoin.oa.core.interceptor.ValidationFlowInterceptor.intercept(ValidationFlowInterceptor.java:47)
at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:164)
at com.opensymphony.xwork.interceptor.AroundInterceptor.intercept(AroundInterceptor.java:35)
at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:164)
at com.aljoin.oa.core.interceptor.VarInterceptor.intercept(VarInterceptor.java:34)
at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:164)
at com.aljoin.oa.core.interceptor.ExceptionHandlerInterceptor.intercept(ExceptionHandlerInterceptor.java:54)
at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:164)
at com.opensymphony.xwork.interceptor.AroundInterceptor.intercept(AroundInterceptor.java:35)
at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:164)
at com.opensymphony.xwork.interceptor.AroundInterceptor.intercept(AroundInterceptor.java:35)
at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:164)
at com.opensymphony.xwork.interceptor.AroundInterceptor.intercept(AroundInterceptor.java:35)
at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:164)
at com.opensymphony.xwork.interceptor.AroundInterceptor.intercept(AroundInterceptor.java:35)
at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:164)
at com.opensymphony.xwork.interceptor.AroundInterceptor.intercept(AroundInterceptor.java:35)
at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:164)
at com.opensymphony.xwork.interceptor.AroundInterceptor.intercept(AroundInterceptor.java:35)
at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:164)
at com.aljoin.oa.base.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:56)
at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:164)
at com.opensymphony.xwork.DefaultActionProxy.execute(DefaultActionProxy.java:116)
at com.opensymphony.webwork.dispatcher.ServletDispatcher.serviceAction(ServletDispatcher.java:272)
at com.opensymphony.webwork.dispatcher.ServletDispatcher.service(ServletDispatcher.java:237)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.opensymphony.webwork.lifecycle.RequestLifecycleFilter.doFilter(RequestLifecycleFilter.java:67)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.aljoin.oa.core.misc.CharacterEncodingFilter.doFilter(CharacterEncodingFilter.java:24)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.aljoin.oa.core.misc.SessionCheckFilter.doFilter(SessionCheckFilter.java:49)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:619)

#17


System.out.println("????????????????????????");
        Dept parentDept = (Dept)queryManager.loadById(Dept.class, dept.getParentDept().getId());
        System.out.println("parentDept=========="+parentDept);
        IDGenerator ig = new IDGenerator(queryManager, parentDept.getId().toString());
        System.out.println("ig============="+ig);

打印出
????????????????????????
parentDept==========null
java.lang.NullPointerException

#18


在贴::QueryManager类


public class QueryManager
  implements Serializable, GenericDaoAware
{
  private GenericDao genericDao;

   public <T> T loadById(Class<T> entity, long id)
  {
    return (T) this.genericDao.getById(entity, Long.valueOf(id));
  }

  public <T> T loadById(Class<T> entity, Serializable id) {
    return (T) this.genericDao.getById(entity, id);
  }

  public <T> T getById(Class<T> entity, Serializable id) {
    return (T) this.genericDao.getById(entity, id);
  }

  public Object load(String query, Object value) throws Exception {
    Query queryObject = this.genericDao.createQuery(query, new Object[0]);
    queryObject.setParameter(0, value);
    return queryObject.uniqueResult();
  }

  public <T> List<T> findAll(Class<T> entity) {
    return this.genericDao.getAll(entity);
  }

  public List findAllByCId(Class entity, String field) throws Exception {
    return this.genericDao.find("from " + entity.getName() + " where " + field + " like '" + OrgnizeService.getCorpId() + "%'", new Object[0]);
  }

  public List find(String query) throws Exception {
    return this.genericDao.createQuery(combineQuery(query), new Object[0]).list();
  }

  public List find(String queryString, Object value) throws Exception {
    return this.genericDao.find(queryString, new Object[] { value });
  }

  public List findByCId(String query, String field) throws Exception {
    query = analyseSql(query, field);
    return this.genericDao.find(query, new Object[0]);
  }

  public List findByCId(String queryString, Object value, String field) throws Exception {
    queryString = analyseSql(queryString, field);
    return this.genericDao.find(queryString, new Object[] { value });
  }

  public List find(String queryString, Object value, Type type) throws Exception {
    Query queryObject = this.genericDao.createQuery(combineQuery(queryString), new Object[0]);
    queryObject.setParameter(0, value, type);
    return queryObject.list();
  }

//  public List find(String queryString, String value, Type type) throws Exception
//  {
//    return find(queryString, value, type);
//  }

  public List find(String queryString, Object[] values) throws Exception {
    String combineQuery = combineQuery(queryString);
    return this.genericDao.find(combineQuery, values);
  }

  public List find(String queryString, Object[] values, Type[] types) throws Exception {
    Query queryObject = this.genericDao.createQuery(queryString, new Object[0]);
    for (int i = 0; i < values.length; ++i)
      queryObject.setParameter(i, values[i], types[i]);

    return queryObject.list();
  }

  public List paginationFind(String query, int startIndex, int pageSize) throws Exception {
    Query queryObject = this.genericDao.createQuery(combineQuery(query), new Object[0]);
    queryObject.setFirstResult(startIndex);
    queryObject.setMaxResults(pageSize);
    return queryObject.list();
  }

  public List paginationFindByCId(String query, int startIndex, int pageSize, String field) throws Exception {
    query = analyseSql(query, field);
    return paginationFind(query, startIndex, pageSize);
  }

  public List paginationFind(String query, Object value, int startIndex, int pageSize) throws Exception {
    Query queryObject = this.genericDao.createQuery(combineQuery(query), new Object[0]);
    queryObject.setParameter(0, value);
    queryObject.setFirstResult(startIndex);
    queryObject.setMaxResults(pageSize);
    return queryObject.list();
  }

  public List paginationFindByCId(String query, Object value, int startIndex, int pageSize, String field) throws Exception {
    query = analyseSql(query, field);
    return paginationFind(query, value, startIndex, pageSize);
  }

  public List paginationFind(String query, Object value, Type type, int startIndex, int pageSize) throws Exception {
    Query queryObject = this.genericDao.createQuery(combineQuery(query), new Object[0]);
    queryObject.setParameter(0, value, type);
    queryObject.setFirstResult(startIndex);
    queryObject.setMaxResults(pageSize);
    return queryObject.list();
  }

  private String combineQuery(String query) {
    if (query.indexOf(":corpId") > 0)
      query = StringUtils.replace(query, ":corpId", "'" + OrgnizeService.getCorpId() + "%" + "'");

    return query;
  }

  public List paginationFind(String query, Object[] values, int startIndex, int pageSize) throws Exception {
    Query queryObject = this.genericDao.createQuery(combineQuery(query), new Object[0]);
    for (int i = 0; i < values.length; ++i)
      queryObject.setParameter(i, values[i]);

    queryObject.setFirstResult(startIndex);
    queryObject.setMaxResults(pageSize);
    return queryObject.list();
  }

  public List paginationFind(String query, Object[] values, Type[] types, int startIndex, int pageSize) throws Exception {
    Query queryObject = this.genericDao.createQuery(combineQuery(query), new Object[0]);
    for (int i = 0; i < values.length; ++i)
      queryObject.setParameter(i, values[i], types[i]);

    queryObject.setFirstResult(startIndex);
    queryObject.setMaxResults(pageSize);

    return queryObject.list();
  }

  private String analyseSql(String queryString, String field) {
    int indexofWhere = queryString.toLowerCase().indexOf("where");
    if (indexofWhere != -1) {
      String firstSql = queryString.substring(0, indexofWhere + 5);
      String secondsql = queryString.substring(indexofWhere + 6, queryString.length());
      queryString = firstSql + " " + field + " like '" + OrgnizeService.getCorpId() + "%' and " + secondsql;
    } else {
      int indexofFrom = queryString.toLowerCase().indexOf("order by");
      if (indexofFrom != -1) {
        String sql1 = queryString.substring(0, indexofFrom - 1);
        String sql2 = queryString.substring(indexofFrom, queryString.length());
        queryString = sql1 + " where " + field + " like '" + OrgnizeService.getCorpId() + "%' " + sql2;
      } else {
        queryString = queryString + " where " + field + " like '" + OrgnizeService.getCorpId() + "%'";
      }
    }

    return queryString;
  }

  public Session getSession()
  {
    return this.genericDao.getSession();
  }

  public void disposeSession() {
    this.genericDao.disposeSession();
  }

  public void setGenericDao(GenericDao genericDao) {
    this.genericDao = genericDao;
  }
}

#19


这就要看数据库中是否有主键为dept.getParentDept().getId()这个的记录了

#20


 return (T) this.genericDao.getById(entity, Long.valueOf(id)); 
   的getById方法都是调用HibernateGenicDao中的 


public class HibernateGenericDao
{
  private static final Logger LOGGER = Logger.getLogger(HibernateGenericDao.class);
  private Session session;
  protected HibernateSession hibernateSession;

  public Session getSession()
  {
    if ((this.session != null) && (this.session.isOpen())) {
      return this.session;
    }

    this.session = this.hibernateSession.getSession();
    return this.session;
  }

  @SuppressWarnings("unchecked")
public <T> T loadById(Class<T> entityClass, Serializable id)
  {
    try
    {
      return (T) getSession().load(entityClass, id);
    } catch (Exception e) {
      e.printStackTrace();
      LOGGER.warn(e.getMessage());
      return null;
    }
  }

  @SuppressWarnings("unchecked")
public <T> T getById(Class<T> entityClass, Serializable id)
  {
    return (T) getSession().get(entityClass, id);
  }
  
@SuppressWarnings("unchecked")
public <T> List<T> getAll(Class<T> entityClass)
  {
    return getSession().createQuery("from " + entityClass.getName()).list();
  }

  public void save(Entity entity)
  {
    try
    {
      Class<? extends Entity> clazz = entity.getClass();
      Method method = clazz.getMethod("setCompanyId", new Class[] { Long.class });
      if (method != null)
        method.invoke(entity, new Object[] { OrgnizeService.getCompanyid() });
    }
    catch (Exception clazz) {
    }
    getSession().saveOrUpdate(entity);
  }




我一直都对这个里面报有问题,还有个是HibernateEentityDao  

#21


数据库是没有问题的 ,这个是一个合强的办公系统, 代码都是我反编译过来的,安装版本是可以跑的,反编译后出现的错误,我修改的可能不合理

#22


oooo

#23


顶一个.

#24


引用 23 楼 mike_24 的回复:
顶一个.

顶一个.

#25


要怎么看数据库中是否有主键为dept.getParentDept().getId()这个的记录  
协同办公系统考勤管理出异常,高分求救,能者多拿,帮顶的给辛苦分

#26


回答的都有分啊 呵呵