微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

FetchMode仅对主键Column起作用

如何解决FetchMode仅对主键Column起作用

| 我更改了代码,但问题仍然存在
    CandidateResumeInfo candidateResumeInfo = new CandidateResumeInfo();
    ArrayList<CandidateResumeInfo> allCandidateResumeInfo= new ArrayList<CandidateResumeInfo>();

    Session session = sessionFactory.openSession();
    String city1 =\"Anniston\";

    Criteria  crit = session.createCriteria(CandidateResumeInfo.class);
    crit.createalias(\"candidate\",\"candidateinfo\");

    //crit.setFetchMode(\"candidateinfo\",FetchMode.JOIN);
    crit.add( Restrictions.eq(\"candidateinfo.city\",city1));
    List list = crit.list();
这是实体类.. 公共类CandidateResumeInfo实现了Serializable { ...
      @OnetoMany     
      CandidateInfo candidate;

      ....
      }
      public class CandidateInfo implements Serializable{
      .......

     @Column(name=\"city\")
     private String city;
      .......
      }
这是堆栈跟踪的前几行 这是一些RPC.class(在此行显示Throwable cause = e.getCause();在右侧变量侧(在调试模式下)编写了java.lang.reflect.InvocationTargetException,但是有堆栈跟踪中没有任何java.lang.reflect.InvocationTargetException
   public final class RPC {
    .......
   public static String invokeAndEncodeResponse(Object target,Method serviceMethod,Object[] args,SerializationPolicy serializationPolicy,int flags)
  throws SerializationException {
if (serviceMethod == null) {
  throw new NullPointerException(\"serviceMethod\");
}

if (serializationPolicy == null) {
  throw new NullPointerException(\"serializationPolicy\");
}

String responsePayload;
try {
  Object result = serviceMethod.invoke(target,args);

  responsePayload = encodeResponseForSuccess(serviceMethod,result,serializationPolicy,flags);
} catch (illegalaccessexception e) {
  SecurityException securityException = new SecurityException(
      formatIllegalAccessErrorMessage(target,serviceMethod));
  securityException.initCause(e);
  throw securityException;
} catch (IllegalArgumentException e) {
  SecurityException securityException = new SecurityException(
      formatIllegalArgumentErrorMessage(target,serviceMethod,args));
  securityException.initCause(e);
  throw securityException;
} catch (InvocationTargetException e) {
  // Try to encode the caught exception
  //
  **Throwable cause = e.getCause();**   // THIS IS THE LINE WHERE IT BRINGS ME ..

  responsePayload = encodeResponseForFailure(serviceMethod,cause,flags);
}
    

解决方法

        
crit.createAlias(\"Class2\",\"c2\").add(Restrictions.eq(\"c2.zip\",123)
应该做... 如果仅使用\'zip \',hibernate将在类Class1中查找属性zip;它与属性是否为PK无关。     

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。