CGLIB增强失败:参数类型不匹配

时间:2012-09-07 16:40:18

标签: hibernate cglib type-mismatch

我收到了以下错误:

Caused by: org.hibernate.HibernateException: CGLIB Enhancement failed: sk.statistics.isis.conceptsvocab.jpa.entities.VocabDomain
at org.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer.getProxy(CGLIBLazyInitializer.java:119)
at org.hibernate.proxy.pojo.cglib.CGLIBProxyFactory.getProxy(CGLIBProxyFactory.java:72)
at org.hibernate.tuple.entity.AbstractEntityTuplizer.createProxy(AbstractEntityTuplizer.java:402)
at org.hibernate.persister.entity.AbstractEntityPersister.createProxy(AbstractEntityPersister.java:3483)
at org.hibernate.event.def.DefaultLoadEventListener.createProxyIfNecessary(DefaultLoadEventListener.java:298)
at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:219)
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:126)
at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:905)
at org.hibernate.impl.SessionImpl.internalLoad(SessionImpl.java:873)
at org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:590)
at org.hibernate.type.EntityType.resolve(EntityType.java:412)
at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:139)
at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:877)
at org.hibernate.loader.Loader.doQuery(Loader.java:752)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:259)
at org.hibernate.loader.Loader.doList(Loader.java:2228)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2125)
at org.hibernate.loader.Loader.list(Loader.java:2120)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:401)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:361)
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:196)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1148)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:102)
at sk.statistics.isis.conceptsvocab.adminmodule.services.impl.SubdomainsServiceImpl.getAllSubdomainLocalizationNamesForSpecificLocalization(SubdomainsServiceImpl.java:70)
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 org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:318)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
at $Proxy31.getAllSubdomainLocalizationNamesForSpecificLocalization(Unknown Source)
at sk.statistics.isis.conceptsvocab.adminmodule.ui.SubdomainsList.initContent(SubdomainsList.java:210)
at sk.statistics.isis.conceptsvocab.adminmodule.mainWindow.MainPanel.selectWindowToDisplay(MainPanel.java:63)
at sk.statistics.isis.conceptsvocab.adminmodule.mainWindow.MainPanel.access$0(MainPanel.java:50)
at sk.statistics.isis.conceptsvocab.adminmodule.mainWindow.MainPanel$MainPanelListener.valueChange(MainPanel.java:98)
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.vaadin.event.ListenerMethod.receiveEvent(ListenerMethod.java:510)
... 26 more
Caused by: java.lang.IllegalArgumentException: argument type mismatch
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 org.hibernate.repackage.cglib.proxy.Enhancer.setCallbacksHelper(Enhancer.java:616)
at org.hibernate.repackage.cglib.proxy.Enhancer.setThreadCallbacks(Enhancer.java:609)
at org.hibernate.repackage.cglib.proxy.Enhancer.registerCallbacks(Enhancer.java:578)
at org.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer.getProxyInstance(CGLIBLazyInitializer.java:129)
at org.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer.getProxy(CGLIBLazyInitializer.java:116)
... 69 more

VocabDomain列表:

/**
* The persistent class for the VOCAB_DOMAINS database table.
* 
*/
@Entity
@Table(name="VOCAB_DOMAINS")
public class VocabDomain implements Serializable {

/**
 * 
 */
private static final long serialVersionUID = 202977208021067034L;
private Long domainid;
private Long optlockversion;
private Set<VocabDomainsLoc> vocabDomainsLocs;
private Set<VocabSubdomain> vocabSubdomains;

public VocabDomain() {
}


@Id
@SequenceGenerator(name="VOCAB_DOMAINS_DOMAINID_GENERATOR", sequenceName="SEQ_DOMAIN_ID")
@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="VOCAB_DOMAINS_DOMAINID_GENERATOR")    
public Long getDomainid() {
    return this.domainid;
}

public void setDomainid(Long domainid) {
    this.domainid = domainid;
}

@Version
public Long getOptlockversion() {
    return this.optlockversion;
}

public void setOptlockversion(Long optlockversion) {
    this.optlockversion = optlockversion;
}


//bi-directional many-to-one association to VocabDomainsLoc
@OneToMany(mappedBy="vocabDomain",fetch=FetchType.LAZY) 
public Set<VocabDomainsLoc> getVocabDomainsLocs() {
    return this.vocabDomainsLocs;
}

public void setVocabDomainsLocs(Set<VocabDomainsLoc> vocabDomainsLocs) {
    this.vocabDomainsLocs = vocabDomainsLocs;
}


//bi-directional many-to-one association to VocabSubdomain
@OneToMany(mappedBy="vocabDomain",fetch=FetchType.LAZY)
public Set<VocabSubdomain> getVocabSubdomains() {
    return this.vocabSubdomains;
}

public void setVocabSubdomains(Set<VocabSubdomain> vocabSubdomains) {
    this.vocabSubdomains = vocabSubdomains;
}

@Override
public boolean equals(Object other) {
    if (this == other) {
        return true;
    }
    if (!(other instanceof VocabDomain)) {
        return false;
    }
    if (this.getDomainid() == null) {
        return false;
    }       
    VocabDomain castOther = (VocabDomain) other;
    if (castOther.getDomainid() == null) {
        return false;
    }
    return this.getDomainid().equals(castOther.getDomainid());

}

@Override
public int hashCode() {
    final int prime = 211;
    int hash = 223;
    hash = hash * prime + (this.getDomainid() != null ?     this.getDomainid().hashCode() : 1);
    return hash;
}       
}

执行此命令时代码失败:     查询q = sessionFactory.getCurrentSession()。createQuery(“SELECT vsd FROM VocabSubdomain vsd LEFT JOIN vsd.vocabSubdomainsLocs”);     列出vsdl = q.list();


我在pom.xml中的依赖项

<spring.version>3.1.1.RELEASE</spring.version>
<hibernate.version>3.4.0.GA</hibernate.version>


<dependencies>

<dependency>
    <!-- na poradi zalezi -->
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-jcl</artifactId>
    <version>1.6.1</version>
</dependency>


<dependency>        
      <groupId>sk.statistics.isis.conceptsvocab.jpa</groupId>
      <artifactId>ConceptsVocabJpa</artifactId>
      <version>0.0.1-SNAPSHOT</version>
</dependency>

    <!-- Spring dependencies -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-aop</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-expression</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-aspects</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-jdbc</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-core</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-web</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-acl</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-config</artifactId>
        <version>${spring.version}</version>
    </dependency>   

    <!--  Vaadin dependencies -->
    <dependency>
        <groupId>com.vaadin</groupId>
        <artifactId>vaadin</artifactId>
        <version>${vaadin.version}</version>
    </dependency>
    <!--  J2EE dependencies -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
    <!-- Portlet dependencies -->       
    <dependency>
        <groupId>javax.portlet</groupId>
        <artifactId>portlet-api</artifactId>
        <version>2.0</version>
        <scope>${portal.scope}</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.portals.bridges</groupId>
        <artifactId>portals-bridges-common</artifactId>
        <version>2.0</version>
    </dependency>   
    <!-- Ldap configuration start -->
    <dependency>
        <groupId>com.sun</groupId>
        <artifactId>ldapbp</artifactId>
        <version>1.0</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.ldap</groupId>
        <artifactId>spring-ldap-core</artifactId>
        <version>1.3.1.RELEASE</version>
    </dependency>
    <!-- Ldap configuration end -->         
    <!-- Hibernate configuration -->
    <dependency>
      <artifactId>jta</artifactId>
      <groupId>javax.transaction</groupId>
      <version>1.1</version>
      <scope>${websphere.scope}</scope>
      <!--  TODO: pre profil na websphere tu treba dat provided -->
    </dependency>
    <dependency>
      <groupId>org.hibernate</groupId>
      <artifactId>hibernate-annotations</artifactId>
      <version>${hibernate.version}</version>
      <!--  vynechaj jta transakcny management, websphere ma vlastny -->
      <exclusions>
          <exclusion>
              <artifactId>jta</artifactId>
              <groupId>javax.transaction</groupId>
          </exclusion>
          <exclusion>
              <groupId>xml-apis</groupId>
              <artifactId>xml-apis</artifactId>
          </exclusion>
      </exclusions>
    </dependency>
   <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-tx</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-orm</artifactId>
    <version>${spring.version}</version>
   </dependency>        
   <dependency>
      <groupId>org.hibernate</groupId>
      <artifactId>hibernate-cglib-repack</artifactId>
      <version>2.1_3</version>
    </dependency>
    <dependency>
      <groupId>cglib</groupId>
      <artifactId>cglib</artifactId>
      <version>2.2.2</version>
    </dependency>   
    <!-- Slf4j over commons logging -->
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.6.6</version>
        <type>jar</type>
    </dependency>           
    <!-- 
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>jcl-over-slf4j</artifactId>
        <version>1.6.6</version>
        <type>jar</type>
    </dependency>           
<dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-jdk14</artifactId>
        <version>1.6.6</version>
    </dependency>
    --> 
<dependency>
    <groupId>log4j</groupId>
    <artifactId>log4j</artifactId>
    <version>1.2.16</version>
</dependency>

</dependencies>  

1 个答案:

答案 0 :(得分:2)

问题是由于hibernate-cglib-repack。如果删除该依赖项,它应该可以工作。

背景: 在一个版本的hibernate中,他们决定将cglib类重新打包到org.hibernate包下。忽略更改以处理对编码为字符串的类名的引用。因此,一旦hibernate代码升级为使用2.2版本的cglib,就不再需要进行更改。

Hibernate与此问题相关的错误。

https://hibernate.onjira.com/browse/HHH-3504

https://hibernate.onjira.com/browse/HHH-2875

相关摘录

  

计划不再使用cglib的重新打包和迁移   现在它已经被释放了2.2。事实上,这已经完成了   斯科特在SVN:HHH-3832

     

不幸的是,当我们做到这一点时,我们没有太多的选择   更改。我们一直在等待cglib 2.2发布超过一年   在那一点上,我们的多次尝试没有得到任何回应   联系他们。我说的是一年多没有发布   所有,不是贝塔斯,crs,nada。我没有意识到里面的琴弦   增强。我认为阴影插件应该处理FQN   类作为字符串。猜不是在这一点上,考虑到cglib 2.2是   最好将其用于Hibernate 3.5   重新包装。对于3.3,我们需要继续使用重新包装   除非cglib 2.1和2.2是字节码兼容的(它们不是   根据我的理解)。我会调查这是否是地址   在树荫下插入,或其他选项可能是什么。还有   我们用来制作阴影重新包装的项目:   http://anonsvn.jboss.org/repos/hibernate/cglib/所以,谁的   志愿了解如何让cglib 2.2与之合作   冬眠?