具有codehaus jackson休息服务的glassfish jersey中的Hibernate懒惰初始化器问题

时间:2015-02-26 06:17:20

标签: hibernate glassfish jersey-2.0

我正在使用codehus-Jackson为json数据研究glashfish泽西休息服务。 但我得到了Hibernate延迟初始化异常,因为我为所有子类添加了lazy = false。但它给出了无限递归错误。所以我在反向映射属性上添加了JsonIgnore。但它没有检测到。我的配置如下。

<servlet>
    <servlet-name>Jersey REST Service</servlet-name>
    <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>

    <init-param>
        <param-name>jersey.config.server.provider.packages</param-name>
        <param-value>com.koderzlab.lawman;org.codehaus.jackson.jaxrs</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>

我的堆栈跟踪如下

at org.codehaus.jackson.map.ser.BeanSerializer.serializeFields(BeanSerializer.java:189)
    at org.codehaus.jackson.map.ser.BeanSerializer.serialize(BeanSerializer.java:142)
    at org.codehaus.jackson.map.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:430)
    at org.codehaus.jackson.map.ser.BeanSerializer.serializeFields(BeanSerializer.java:175)
    at org.codehaus.jackson.map.ser.BeanSerializer.serialize(BeanSerializer.java:142)
    at org.codehaus.jackson.map.ser.ContainerSerializers$CollectionSerializer.serializeContents(ContainerSerializers.java:442)
    at org.codehaus.jackson.map.ser.ContainerSerializers$CollectionSerializer.serializeContents(ContainerSerializers.java:383)
    at org.codehaus.jackson.map.ser.ContainerSerializers$AsArraySerializer.serialize(ContainerSerializers.java:142)
    at org.codehaus.jackson.map.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:430)
    at org.codehaus.jackson.map.ser.BeanSerializer.serializeFields(BeanSerializer.java:175)
    at org.codehaus.jackson.map.ser.BeanSerializer.serialize(BeanSerializer.java:142)
    at org.codehaus.jackson.map.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:430)
    at org.codehaus.jackson.map.ser.BeanSerializer.serializeFields(BeanSerializer.java:175)
    at org.codehaus.jackson.map.ser.BeanSerializer.serialize(BeanSerializer.java:142)
    at org.codehaus.jackson.map.ser.ContainerSerializers$CollectionSerializer.serializeContents(ContainerSerializers.java:442)
    at org.codehaus.jackson.map.ser.ContainerSerializers$CollectionSerializer.serializeContents(ContainerSerializers.java:383)

2 个答案:

答案 0 :(得分:0)

虽然你的Hibernate问题可能无法解决,但看起来你正在为Jackson课程扫描错误的包名。

对于 Jackson 2.x ,通常与 Jersey 2.x 一起使用,您需要扫描包com.fasterxml.jackson.jaxrs而不是{{1 }}

org.codehaus.jackson.jaxrs中的部分更改为以下内容:

web.xml

另见:

答案 1 :(得分:0)

我刚添加了codehusjackson 1.9.2罐子,现在它正在识别@JsonBack参考。但是在每个pojo课上我们需要添加
@JsonIgnoreProperties({“hibernateLazyInitializer”,“handler”})