Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting exception Javassist Enhancement failed: due to JavassistLazyInitializer.getProxy

Tags:

hibernate

I am getting the following exception when i use load method from HibernateSession class as follows:

getCurrentSession().load(entityClass, id);.

I am not getting the exception, if i use the following:

getCurrentSession().get(entityClass, id);.

Here is the class code

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;
}
}

The exception is as follows:

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

Appreciated, if anyone gives an idea what is causing> Thank you.

like image 254
Sydaiah Avatar asked Sep 07 '12 16:09

Sydaiah


1 Answers

The class com.company.x.y.field.AbstractField doesn't have a default (no argument) constructor.

The part of stack trace that leads to the above conclusion.

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
like image 127
gkamal Avatar answered Nov 12 '22 00:11

gkamal