获取异常Javassist Enhancement失败:由于JavassistLazyInitializer.getProxy

时间:2012-09-07 16:29:12

标签: hibernate

当我使用HibernateSession类的load方法时,我得到以下异常,如下所示:

getCurrentSession().load(entityClass, id);

如果我使用以下内容,我没有得到例外:

getCurrentSession().get(entityClass, id);

这是类代码

package com.company.x.y.field;

 @Entity
 @Table(name = "FIELD")
 @Inheritance(strategy = InheritanceType.SINGLE_TABLE)
 @DiscriminatorColumn(name = "FIELDTYPE")
 @Cache(usage = CacheConcurrencyStrategy.READ_WRITE,region="xEntity")
 public abstract class AbstractField extends AbstractEntity {
private static final long serialVersionUID = 1L;

private final ValueType valueType;
private final FieldType fieldType;
private DataPoint dataPoint;
private String name;
private String title;
private String guid;
private boolean deleted;
private Integer sequence;

protected AbstractField(FieldType fieldType, ValueType valueType) {
    this.fieldType = fieldType;
    this.valueType = valueType;
}

@Id
@SequenceGenerator(name = "SEQ_FIELD_ID", sequenceName = "SEQ_FIELD_ID", allocationSize = 1)
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SEQ_FIELD_ID")
@Override
@Column(name = "FIELD_ID")
public Long getId() {
    return id;
}

@Transient
public ValueType getValueType() {
    return valueType;
}

@Transient
public FieldType getFieldType() {
    return fieldType;
}

@ManyToOne
//@JoinColumn(name = "DP_ID", updatable = false)
@JoinColumn(name = "DP_ID")
public DPClass getDPClass() {
    return dpClass;
}

public void setDataPoint(DPClass dpClass) {
    this.dpClass = dpClass;
}

@Column(name = "NAME")
public String getName() {
    return name;
}

public void setName(String name) {
    this.name = name;
}

@Column(name = "TITLE")
public String getTitle() {
    return title;
}

public void setTitle(String title) {
    this.title = title;
}

@Column(name = "GUID")
public String getGuid() {
    if (StringUtils.isEmpty(guid)) {
        guid = UUID.randomUUID().toString().toUpperCase().replaceAll("-", "");
    }
    return guid;
}

public void setGuid(String guid) {
    this.guid = guid;
}

@Column(name = "DELETED_IND")
public boolean isDeleted() {
    return deleted;
}

public void setDeleted(boolean deleted) {
    this.deleted = deleted;
}

@Column(name = "SEQUENCE")
public Integer getSequence() {
    return sequence;
}

public void setSequence(Integer sequence) {
    this.sequence = sequence;
}

@Column(name = "CREAT_TS")
public Date getDateCreated() {
    return dateCreated;
}
@Column(name = "CREAT_USER")
public String getUserCreated() {
    return userCreated;
}
@Column(name = "LAST_UPDATE_TS")
public Date getDateUpdated() {
    return dateUpdated;
}
@Column(name = "LAST_UPDATE_USER")
public String getUserUpdated() {
    return userUpdated;
}
}

例外情况如下:

org.hibernate.HibernateException: Javassist Enhancement failed: com.company.x.y.field.AbstractField
    at org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer.getProxy(JavassistLazyInitializer.java:142)
    at org.hibernate.proxy.pojo.javassist.JavassistProxyFactory.getProxy(JavassistProxyFactory.java:71)
    at org.hibernate.tuple.entity.AbstractEntityTuplizer.createProxy(AbstractEntityTuplizer.java:631)
    at org.hibernate.persister.entity.AbstractEntityPersister.createProxy(AbstractEntityPersister.java:3737)
    at org.hibernate.event.def.DefaultLoadEventListener.createProxyIfNecessary(DefaultLoadEventListener.java:360)
    at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:281)
    at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:152)
    at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:1090)
    at org.hibernate.impl.SessionImpl.load(SessionImpl.java:985)
    at org.hibernate.impl.SessionImpl.load(SessionImpl.java:978)
    at com.company.x.y.field.app.FieldServiceImpl.getById(FieldServiceImpl.java:152)
    at com.company.x.y.field.app.FieldServiceImpl.getById(FieldServiceImpl.java:1)
    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 $Proxy67.getById(Unknown Source)
    at com.company.impl.web.AbstractEntityBean.getEntity(AbstractEntityBean.java:36)
    at sun.reflect.GeneratedMethodAccessor289.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at javax.el.BeanELResolver.getValue(BeanELResolver.java:302)
    at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176)
    at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203)
    at com.sun.el.parser.AstValue.getValue(AstValue.java:116)
    at com.sun.el.parser.AstValue.getValue(AstValue.java:163)
    at com.sun.el.parser.AstEqual.getValue(AstEqual.java:54)
    at com.sun.el.parser.AstOr.getValue(AstOr.java:54)
    at com.sun.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:219)
    at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:109)
    at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:193)
    at javax.faces.component.UIComponentBase.isRendered(UIComponentBase.java:422)
    at javax.faces.component.UIComponentBase.processDecodes(UIComponentBase.java:1038)
    at javax.faces.component.UIComponentBase.processDecodes(UIComponentBase.java:1048)
    at javax.faces.component.UIComponentBase.processDecodes(UIComponentBase.java:1048)
    at javax.faces.component.UIComponentBase.processDecodes(UIComponentBase.java:1048)
    at javax.faces.component.UIComponentBase.processDecodes(UIComponentBase.java:1048)
    at org.primefaces.component.tabview.TabView.processDecodes(TabView.java:243)
    at javax.faces.component.UIComponentBase.processDecodes(UIComponentBase.java:1048)
    at javax.faces.component.UIComponentBase.processDecodes(UIComponentBase.java:1048)
    at org.primefaces.component.tabview.TabView.processDecodes(TabView.java:243)
    at javax.faces.component.UIForm.processDecodes(UIForm.java:216)
    at javax.faces.component.UIComponentBase.processDecodes(UIComponentBase.java:1048)
    at javax.faces.component.UIComponentBase.processDecodes(UIComponentBase.java:1048)
    at javax.faces.component.UIViewRoot.processDecodes(UIViewRoot.java:926)
    at com.sun.faces.lifecycle.ApplyRequestValuesPhase.execute(ApplyRequestValuesPhase.java:78)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:508)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:311)
    at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:116)
    at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:83)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
    at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
    at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:64)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
    at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:101)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
    at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
    at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
    at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:45)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
    at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:182)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
    at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
    at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
    at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:173)
    at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
    at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:185)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:151)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:405)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:269)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:515)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:662)
Caused by: java.lang.InstantiationException: com.company.x.y.field.AbstractField_$$_javassist_28
    at java.lang.Class.newInstance0(Class.java:340)
    at java.lang.Class.newInstance(Class.java:308)
    at org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer.getProxy(JavassistLazyInitializer.java:139)
    ... 100 more

赞赏,如果有人知道是什么导致>谢谢。

2 个答案:

答案 0 :(得分:28)

com.company.x.y.field.AbstractField没有默认(无参数)构造函数。

堆栈跟踪的部分导致上述结论。

Caused by: java.lang.InstantiationException: com.company.x.y.field.AbstractField_$$_javassist_28
    at java.lang.Class.newInstance0(Class.java:340)
    at java.lang.Class.newInstance(Class.java:308)
    at org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer.getProxy(JavassistLazyInitializer.java:139)
    ... 100 more

答案 1 :(得分:0)

当hibernate没有正确版本的javassist类或一个以上版本时发生,在我的Websphere 8.5.5.12上,是因为该服务器具有该库的一个很旧的版本,而我的耳朵上有一个新的APP-INF / lib。我可以通过更改模块类加载器来解决此问题: enter image description here