我收到以下错误:

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

词汇域列表:
/**
* 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>

最佳答案

问题是由于 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

相关摘录

关于hibernate - CGLIB 增强失败 :argument type mismatch,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/12322174/

10-16 17:21