public static UserDetail UserDetail.findUserDetail(Long id) {
        if (id == null) return null;
        return entityManager().find(UserDetail.class, id);
    }


我们正在使用spring Roo。上面是Roo生成的查找器方法。部分堆栈跟踪如下:

Caused by: org.hibernate.WrongClassException: Object with id: 1501237 was not of the specified subclass: com.***.***.user.UserDetail (Discriminator: FacebookUserDetail)


有没有人遇到这个例外?

编辑
该问题和以下问题与同一问题有关。

Java class file truncated

我有两个项目。我的一个项目(例如project2)依赖于另一个项目(project2)。这两个项目都是Maven项目,而project1在project2的依赖关系中列出。当我编译project2时,应该将project1中的所有类文件都复制到project2中(我想)。但是,我看到project1中一个类文件的文件大小与project2中相同类的类文件的文件大小不同。如果我反编译文件,则会得到以下结果。

从project1反编译FacebookUserDetail.class:

package com.***.domain.user.external;

import com.***.domain.user.UserDetailType;
import java.util.List;
import javax.persistence.Entity;
import javax.persistence.TypedQuery;
import org.aspectj.lang.JoinPoint;
import org.aspectj.runtime.internal.CFlowCounter;
import org.aspectj.runtime.reflect.Factory;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.beans.factory.aspectj.AbstractDependencyInjectionAspect;
import org.springframework.beans.factory.aspectj.AnnotationBeanConfigurerAspect;
import org.springframework.mock.staticmock.AnnotationDrivenStaticEntityMockingControl;

@Configurable
@Entity
public class FacebookUserDetail extends ExternalUserDetail
{
  public FacebookUserDetail()
  {
    JoinPoint localJoinPoint = Factory.makeJP(ajc$tjp_1, this, this); if ((!AnnotationBeanConfigurerAspect.ajc$if$bb0((Configurable)getClass().getAnnotation(Configurable.class))) && (AbstractDependencyInjectionAspect.ajc$if$6f1(localJoinPoint))) AnnotationBeanConfigurerAspect.aspectOf().ajc$afterReturning$org_springframework_beans_factory_aspectj_AbstractDependencyInjectionAspect$2$1ea6722c(this);
  }

  public static FacebookUserDetail findFacebookUserDetailByFacebookId(String facebookId)
  {
    String str = facebookId; JoinPoint localJoinPoint = Factory.makeJP(ajc$tjp_0, null, null, str); if ((AnnotationDrivenStaticEntityMockingControl.ajc$cflowCounter$1.isValid()) && (AnnotationDrivenStaticEntityMockingControl.hasAspect())) return (FacebookUserDetail)findFacebookUserDetailByFacebookId_aroundBody1$advice(str, localJoinPoint, AnnotationDrivenStaticEntityMockingControl.aspectOf(), null, ajc$tjp_0, localJoinPoint); return findFacebookUserDetailByFacebookId_aroundBody0(str, localJoinPoint);
  }

  public UserDetailType getExternalUserDetailType()
  {
    return UserDetailType.FACEBOOK;
  }

  static
  {
    ajc$preClinit(); }
  public static long countFacebookUserDetails() { return FacebookUserDetail_Roo_Entity.ajc$interMethod$com_nim_domain_user_external_FacebookUserDetail_Roo_Entity$com_nim_domain_user_external_FacebookUserDetail$countFacebookUserDetails(); }
  public static List<FacebookUserDetail> findAllFacebookUserDetails() { return FacebookUserDetail_Roo_Entity.ajc$interMethod$com_nim_domain_user_external_FacebookUserDetail_Roo_Entity$com_nim_domain_user_external_FacebookUserDetail$findAllFacebookUserDetails(); }
  public static FacebookUserDetail findFacebookUserDetail(Long paramLong) { return FacebookUserDetail_Roo_Entity.ajc$interMethod$com_nim_domain_user_external_FacebookUserDetail_Roo_Entity$com_nim_domain_user_external_FacebookUserDetail$findFacebookUserDetail(paramLong); }
  public static List<FacebookUserDetail> findFacebookUserDetailEntries(int paramInt1, int paramInt2) { return FacebookUserDetail_Roo_Entity.ajc$interMethod$com_nim_domain_user_external_FacebookUserDetail_Roo_Entity$com_nim_domain_user_external_FacebookUserDetail$findFacebookUserDetailEntries(paramInt1, paramInt2); }
  public static TypedQuery<FacebookUserDetail> findFacebookUserDetailsByUserIdEquals(String paramString) { return FacebookUserDetail_Roo_Finder.ajc$interMethod$com_nim_domain_user_external_FacebookUserDetail_Roo_Finder$com_nim_domain_user_external_FacebookUserDetail$findFacebookUserDetailsByUserIdEquals(paramString); }
  public String toString() { return FacebookUserDetail_Roo_ToString.ajc$interMethod$com_nim_domain_user_external_FacebookUserDetail_Roo_ToString$com_nim_domain_user_external_FacebookUserDetail$toString(this); }

}


从project2反编译FacebookUserDetail.class

package com.***.domain.user.external;

import com.***.domain.user.UserDetailType;
import org.aspectj.lang.JoinPoint;
import org.aspectj.runtime.internal.CFlowCounter;
import org.aspectj.runtime.reflect.Factory;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.beans.factory.aspectj.AbstractDependencyInjectionAspect;
import org.springframework.beans.factory.aspectj.AnnotationBeanConfigurerAspect;
import org.springframework.mock.staticmock.AnnotationDrivenStaticEntityMockingControl;

public class FacebookUserDetail extends ExternalUserDetail
{
  public FacebookUserDetail()
  {
    JoinPoint localJoinPoint = Factory.makeJP(ajc$tjp_1, this, this); if ((!AnnotationBeanConfigurerAspect.ajc$if$bb0((Configurable)getClass().getAnnotation(Configurable.class))) && (AbstractDependencyInjectionAspect.ajc$if$6f1(localJoinPoint))) AnnotationBeanConfigurerAspect.aspectOf().ajc$afterReturning$org_springframework_beans_factory_aspectj_AbstractDependencyInjectionAspect$2$1ea6722c(this);
  }

  public static FacebookUserDetail findFacebookUserDetailByFacebookId(String facebookId)
  {
    String str = facebookId; JoinPoint localJoinPoint = Factory.makeJP(ajc$tjp_0, null, null, str); if ((AnnotationDrivenStaticEntityMockingControl.ajc$cflowCounter$1.isValid()) && (AnnotationDrivenStaticEntityMockingControl.hasAspect())) return (FacebookUserDetail)findFacebookUserDetailByFacebookId_aroundBody1$advice(str, localJoinPoint, AnnotationDrivenStaticEntityMockingControl.aspectOf(), null, ajc$tjp_0, localJoinPoint); return findFacebookUserDetailByFacebookId_aroundBody0(str, localJoinPoint);
  }

  public UserDetailType getExternalUserDetailType()
  {
    return UserDetailType.FACEBOOK;
  }

  static
  {
    ajc$preClinit();
  }
}


我的问题是:project2中的类文件被截断的可能原因是什么?

最佳答案

据我从错误中了解到,您有以下情况:
您请求具有该ID的UserDetail类型的实体(该实体的DTYPE / discriminator列值应等于FacebookUserDetail或其他扩展UserDetail的实体),但是在您的数据库中,DTYPE是另一个。为此,您必须更正数据库。

或者也可能是FacebookUserDetail无法识别为相同层次结构的DTYPE。尝试调试一下,例如测试搜索相同ID的FacebookUserDetail实例时返回的内容。

关于java - 对原始JPA方法的调用将引发WrongClassException,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/21636649/

10-10 16:33