FetchMode仅适用于主键Column

时间:2011-05-30 04:49:07

标签: hibernate fetch

我已更改代码但问题仍然存在

    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,
      serializationPolicy, flags);
}

1 个答案:

答案 0 :(得分:1)

crit.createAlias("Class2", "c2").add(Restrictions.eq("c2.zip", 123)

应该这样做......

如果你只是使用'zip',hibernate会在类Class1中寻找属性zip;它与PK属性无关。