Error with WildFly, RestEasy and Hibernate
fheldt Feb 19, 2014 10:21 AMWe've got an error with a simple REST Webservice after switching from JBoss 7.1.1 to WildFly 8.0.0.Final.
It's a simple Entity Object with @ManyToOne connections.
@GET
@Produces({ MediaType.APPLICATION_JSON })
@org.jboss.resteasy.annotations.providers.jaxb.Wrapped(element="einkauf")
@Path("/einkauf/{aun1:[0-9][0-9]*}/{jahr:[0-9][0-9]*}/{abnr:[0-9][0-9]*}")
@GZIP
public Einkauf getEinkauf(@PathParam("aun1") short aun1, @PathParam("jahr") short jahr, @PathParam("abnr") String abnr) {
Einkauf eink = weEJB.getEinkaufItem(aun1, jahr, abnr);
return eink;
}
@Entity
@Table(name = "EINK")
public class Einkauf implements Serializable {
...
@ManyToOne
@JoinColumn(name="EKABNR", insertable=false, updatable=false)
@NotFound(action = NotFoundAction.IGNORE)
private Baustein baustein;
public Baustein getBaustein() {
return baustein;
}
...
}
WARN [org.jboss.resteasy.core.ExceptionHandler] (default task-2) Unknown exception while executing GET /eingang/einkauf/9507/2013/3361: org.codehaus.jackson.map.JsonMappingException: Session is closed! (through reference chain: com.mathai.entity.Einkauf["baustein"]->com.mathai.entity.Baustein["fieldHandler"]->org.hibernate.bytecode.instrumentation.internal.javassist.FieldInterceptorImpl["session"]->org.hibernate.internal.SessionImpl["statistics"]->org.hibernate.stat.internal.SessionStatisticsImpl["entityCount"])
...
Caused by: org.hibernate.SessionException: Session is closed!
at org.hibernate.internal.AbstractSessionImpl.errorIfClosed(AbstractSessionImpl.java:133) [hibernate-core-4.3.1.Final.jar:4.3.1.Final]
at org.hibernate.internal.SessionImpl.getPersistenceContext(SessionImpl.java:1990) [hibernate-core-4.3.1.Final.jar:4.3.1.Final]
at org.hibernate.stat.internal.SessionStatisticsImpl.getEntityCount(SessionStatisticsImpl.java:44) [hibernate-core-4.3.1.Final.jar:4.3.1.Final]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.7.0_51]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) [rt.jar:1.7.0_51]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.7.0_51]
at java.lang.reflect.Method.invoke(Method.java:606) [rt.jar:1.7.0_51]
at org.codehaus.jackson.map.ser.BeanPropertyWriter.get(BeanPropertyWriter.java:483) [jackson-mapper-asl-1.9.13.jar:1.9.13]
at org.codehaus.jackson.map.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:418) [jackson-mapper-asl-1.9.13.jar:1.9.13]
at org.codehaus.jackson.map.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:150) [jackson-mapper-asl-1.9.13.jar:1.9.13]
So looking at the Exception it looks like RestEasy is trying to serialize all the getters (via reflection) until it comes to getBaustein() and then it stumbles upon some Hibernate code attached to the object.
The same REST WebService is doing fine in JBoss 7.1.1! This problem is with nearly every REST WebService using Entities (and not DAOs)
Anyone any idea, what's going on here?